]> Cypherpunks repositories - gostls13.git/commit
archive/tar: add Header.DetectSparseHoles and Header.PunchSparseHoles
authorJoe Tsai <joetsai@digital-static.net>
Fri, 1 Sep 2017 09:57:46 +0000 (02:57 -0700)
committerJoe Tsai <thebrokentoaster@gmail.com>
Wed, 20 Sep 2017 22:12:38 +0000 (22:12 +0000)
commit1eacf78858fd18b100d25f7a04c4c62d96a23020
tree88d73ddae40820cc66aa7849191ade5914f6ae34
parentd2f317218bf563121e80b36bb06a8ba46d040a20
archive/tar: add Header.DetectSparseHoles and Header.PunchSparseHoles

To support the detection and creation of sparse files,
add two new methods:
func Header.DetectSparseHoles(*os.File) error
func Header.PunchSparseHoles(*os.File) error

DetectSparseHoles is intended to be used after FileInfoHeader
prior to serializing the Header with WriteHeader.
For each OS, it uses specialized logic to detect
the location of sparse holes. On most Unix systems, it uses
SEEK_HOLE and SEEK_DATA to query for the holes.
On Windows, it uses a specialized the FSCTL_QUERY_ALLOCATED_RANGES
syscall to query for all the holes.

PunchSparseHoles is intended to be used after Reader.Next
prior to populating the file with Reader.WriteTo.
On Windows, this uses the FSCTL_SET_ZERO_DATA syscall.
On other operating systems it simply truncates the file
to the end-offset of SparseHoles.

DetectSparseHoles and PunchSparseHoles are added as methods on
Header because they are heavily tied to the operating system,
for which there is already an existing precedence for
(since FileInfoHeader makes uses of OS-specific details).

Fixes #13548

Change-Id: I98a321dd1ce0165f3d143d4edadfda5e7db67746
Reviewed-on: https://go-review.googlesource.com/60871
Run-TryBot: Joe Tsai <thebrokentoaster@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
src/archive/tar/common.go
src/archive/tar/example_test.go
src/archive/tar/sparse_unix.go [new file with mode: 0644]
src/archive/tar/sparse_windows.go [new file with mode: 0644]
src/archive/tar/stat_actime1.go [moved from src/archive/tar/stat_atim.go with 100% similarity]
src/archive/tar/stat_actime2.go [moved from src/archive/tar/stat_atimespec.go with 100% similarity]
src/archive/tar/tar_test.go