aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGiovanni Bajo <rasky@develer.com>2017-09-23 00:57:51 +0200
committerJoe Tsai <thebrokentoaster@gmail.com>2017-09-23 16:53:28 +0000
commit2f8b555de27198775f9606e001ef19b76efdb415 (patch)
treea5c2288bb560e98dd33fcebac1278bf0e062e000 /src
parent6171d055dc39b316fbc051a43ce7473798bb5561 (diff)
downloadgo-2f8b555de27198775f9606e001ef19b76efdb415.tar.xz
archive/tar: fix sparse files support on Darwin
Apple defined the SEEK_HOLE/SEEK_DATA constants in unistd.h with swapped values, compared to all other UNIX systems. Fixes #21970 Change-Id: I84a33e0741f0f33a2e04898e96b788b87aa9890f Reviewed-on: https://go-review.googlesource.com/65570 Reviewed-by: Joe Tsai <thebrokentoaster@gmail.com> Run-TryBot: Joe Tsai <thebrokentoaster@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org>
Diffstat (limited to 'src')
-rw-r--r--src/archive/tar/sparse_unix.go9
1 files changed, 7 insertions, 2 deletions
diff --git a/src/archive/tar/sparse_unix.go b/src/archive/tar/sparse_unix.go
index 4bc3482858..c623c1ee4f 100644
--- a/src/archive/tar/sparse_unix.go
+++ b/src/archive/tar/sparse_unix.go
@@ -9,6 +9,7 @@ package tar
import (
"io"
"os"
+ "runtime"
"syscall"
)
@@ -19,8 +20,12 @@ func init() {
func sparseDetectUnix(f *os.File) (sph sparseHoles, err error) {
// SEEK_DATA and SEEK_HOLE originated from Solaris and support for it
// has been added to most of the other major Unix systems.
- const seekData = 3 // SEEK_DATA from unistd.h
- const seekHole = 4 // SEEK_HOLE from unistd.h
+ var seekData, seekHole = 3, 4 // SEEK_DATA/SEEK_HOLE from unistd.h
+
+ if runtime.GOOS == "darwin" {
+ // Darwin has the constants swapped, compared to all other UNIX.
+ seekData, seekHole = 4, 3
+ }
// Check for seekData/seekHole support.
// Different OS and FS may differ in the exact errno that is returned when