From: Joe Tsai Date: Thu, 21 Sep 2017 06:20:28 +0000 (-0700) Subject: archive/tar: make check for hole detection support more liberal X-Git-Tag: go1.10beta1~1031 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=fdecab6ef00be4a2e6247ebd962a281276b3f37d;p=gostls13.git archive/tar: make check for hole detection support more liberal On most Unix OSes, lseek reports EINVAL when lacking SEEK_HOLE support. However, there are reports that ENOTTY is reported instead. Rather than tracking down every possible errno that may be used to represent "not supported", just treat any non-nil error as meaning that there is no support. This is the same strategy taken by the GNU and BSD tar tools. Fixes #21958 Change-Id: Iae68afdc934042f52fa914fca45f0ca89220c383 Reviewed-on: https://go-review.googlesource.com/65191 Run-TryBot: Joe Tsai TryBot-Result: Gobot Gobot Reviewed-by: Ian Lance Taylor --- diff --git a/src/archive/tar/sparse_unix.go b/src/archive/tar/sparse_unix.go index 76b4c6cc2b..4bc3482858 100644 --- a/src/archive/tar/sparse_unix.go +++ b/src/archive/tar/sparse_unix.go @@ -23,8 +23,12 @@ func sparseDetectUnix(f *os.File) (sph sparseHoles, err error) { const seekHole = 4 // SEEK_HOLE from unistd.h // Check for seekData/seekHole support. - if _, err := f.Seek(0, seekHole); errno(err) == syscall.EINVAL { - return nil, nil // Either old kernel or FS does not support this + // Different OS and FS may differ in the exact errno that is returned when + // there is no support. Rather than special-casing every possible errno + // representing "not supported", just assume that a non-nil error means + // that seekData/seekHole is not supported. + if _, err := f.Seek(0, seekHole); err != nil { + return nil, nil } // Populate the SparseHoles.