diff options
author | Joe Tsai <joetsai@digital-static.net> | 2017-11-16 10:15:34 -0800 |
---|---|---|
committer | Joe Tsai <thebrokentoaster@gmail.com> | 2017-11-29 19:04:57 +0000 |
commit | 9ec0c7abe14102b6a374a4d2920afac10d99e27e (patch) | |
tree | 31728f854f9342c5940332e9121ef6dc4dfb6e46 /src/archive/tar/writer.go | |
parent | ba1943cd230c4193e8f84695de5651276efe3607 (diff) | |
download | go-git-9ec0c7abe14102b6a374a4d2920afac10d99e27e.tar.gz |
archive/tar: use placeholder name for global PAX records
Several usages of tar (reasonably) just use the Header.FileInfo
to determine the type of the header. However, the os.FileMode type
is not expressive enough to represent "files" that are not files
at all, but some form of metadata.
Thus, Header{Typeflag: TypeXGlobalHeader}.FileInfo().Mode().IsRegular()
reports true, even though the expected result may have been false.
To reduce (not eliminate) the possibility of failure for such usages,
use the placeholder filename from the global PAX headers.
Thus, in the event the user did not handle special "meta" headers
specifically, they will just be written to disk as a regular file.
As an example use case, the "git archive --format=tgz" command produces
an archive where the first "file" is a global PAX header with the
name "global_pax_header". For users that do not explicitly check
the Header.Typeflag field to ignore such headers, they may end up
extracting a file named "global_pax_header". While it is a bogus file,
it at least does not stop the extraction process.
Updates #22748
Change-Id: I28448b528dcfacb4e92311824c33c71b482f49c9
Reviewed-on: https://go-review.googlesource.com/78355
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Diffstat (limited to 'src/archive/tar/writer.go')
-rw-r--r-- | src/archive/tar/writer.go | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/src/archive/tar/writer.go b/src/archive/tar/writer.go index 79b06b334f..97d23f8038 100644 --- a/src/archive/tar/writer.go +++ b/src/archive/tar/writer.go @@ -179,7 +179,10 @@ func (tw *Writer) writePAXHeader(hdr *Header, paxHdrs map[string]string) error { var name string var flag byte if isGlobal { - name = "GlobalHead.0.0" + name = realName + if name == "" { + name = "GlobalHead.0.0" + } flag = TypeXGlobalHeader } else { dir, file := path.Split(realName) |