1
0
mirror of https://github.com/golang/go synced 2024-11-20 02:54:39 -07:00

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>
This commit is contained in:
Giovanni Bajo 2017-09-23 00:57:51 +02:00 committed by Joe Tsai
parent 6171d055dc
commit 2f8b555de2

View File

@ -9,6 +9,7 @@ package tar
import ( import (
"io" "io"
"os" "os"
"runtime"
"syscall" "syscall"
) )
@ -19,8 +20,12 @@ func init() {
func sparseDetectUnix(f *os.File) (sph sparseHoles, err error) { func sparseDetectUnix(f *os.File) (sph sparseHoles, err error) {
// SEEK_DATA and SEEK_HOLE originated from Solaris and support for it // SEEK_DATA and SEEK_HOLE originated from Solaris and support for it
// has been added to most of the other major Unix systems. // has been added to most of the other major Unix systems.
const seekData = 3 // SEEK_DATA from unistd.h var seekData, seekHole = 3, 4 // SEEK_DATA/SEEK_HOLE from unistd.h
const seekHole = 4 // 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. // Check for seekData/seekHole support.
// Different OS and FS may differ in the exact errno that is returned when // Different OS and FS may differ in the exact errno that is returned when