diff options
author | Caio Marcelo de Oliveira Filho <caio.oliveira@intel.com> | 2018-01-01 16:16:43 -0800 |
---|---|---|
committer | Joe Tsai <thebrokentoaster@gmail.com> | 2018-02-13 18:36:49 +0000 |
commit | e4bde0510465eecd4c8a8293418b1cbed1e0e623 (patch) | |
tree | 37a77a82777c266a7f4dd105c2671b1a75ff52de /src/archive/tar/writer.go | |
parent | 5158aab7d662e274aed870ae6bf9cf8ae0786f5b (diff) | |
download | go-git-e4bde0510465eecd4c8a8293418b1cbed1e0e623.tar.gz |
archive/tar: automatically promote TypeRegA
Change Reader to promote TypeRegA to TypeReg in headers, unless their
name have a trailing slash which is already promoted to TypeDir. This
will allow client code to handle just TypeReg instead both TypeReg and
TypeRegA.
Change Writer to promote TypeRegA to TypeReg or TypeDir in the headers
depending on whether the name has a trailing slash. This normalization
is motivated by the specification (in pax(1)):
0 represents a regular file. For backwards-compatibility, a
typeflag value of binary zero ( '\0' ) should be recognized as
meaning a regular file when extracting files from the
archive. Archives written with this version of the archive file
format create regular files with a typeflag value of the
ISO/IEC 646:1991 standard IRV '0'.
Fixes #22768.
Change-Id: I149ec55824580d446cdde5a0d7a0457ad7b03466
Reviewed-on: https://go-review.googlesource.com/85656
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/archive/tar/writer.go')
-rw-r--r-- | src/archive/tar/writer.go | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/src/archive/tar/writer.go b/src/archive/tar/writer.go index 97d23f8038..d6f69314e0 100644 --- a/src/archive/tar/writer.go +++ b/src/archive/tar/writer.go @@ -71,6 +71,16 @@ func (tw *Writer) WriteHeader(hdr *Header) error { } tw.hdr = *hdr // Shallow copy of Header + // Avoid usage of the legacy TypeRegA flag, and automatically promote + // it to use TypeReg or TypeDir. + if tw.hdr.Typeflag == TypeRegA { + if strings.HasSuffix(tw.hdr.Name, "/") { + tw.hdr.Typeflag = TypeDir + } else { + tw.hdr.Typeflag = TypeReg + } + } + // Round ModTime and ignore AccessTime and ChangeTime unless // the format is explicitly chosen. // This ensures nominal usage of WriteHeader (without specifying the format) |