Merge pull request #44083 from thaJeztah/archive_cachebust
pkg/archive: remove backward compat hack for go < 1.9
This commit is contained in:
commit
f3e6b7065a
4 changed files with 8 additions and 50 deletions
|
@ -60,7 +60,7 @@ func TestHashFile(t *testing.T) {
|
|||
t.Fatalf("Hash returned empty sum")
|
||||
}
|
||||
|
||||
expected := "1149ab94af7be6cc1da1335e398f24ee1cf4926b720044d229969dfc248ae7ec"
|
||||
expected := "55dfeb344351ab27f59aa60ebb0ed12025a2f2f4677bf77d26ea7a671274a9ca"
|
||||
|
||||
if actual := sum; expected != actual {
|
||||
t.Fatalf("invalid checksum. expected %s, got %s", expected, actual)
|
||||
|
@ -97,7 +97,7 @@ func TestHashSubdir(t *testing.T) {
|
|||
t.Fatalf("Hash returned empty sum")
|
||||
}
|
||||
|
||||
expected := "d7f8d6353dee4816f9134f4156bf6a9d470fdadfb5d89213721f7e86744a4e69"
|
||||
expected := "74a3326b8e766ce63a8e5232f22e9dd895be647fb3ca7d337e5e0a9b3da8ef28"
|
||||
|
||||
if actual := sum; expected != actual {
|
||||
t.Fatalf("invalid checksum. expected %s, got %s", expected, actual)
|
||||
|
|
|
@ -99,16 +99,6 @@ const (
|
|||
OverlayWhiteoutFormat
|
||||
)
|
||||
|
||||
const (
|
||||
modeISDIR = 040000 // Directory
|
||||
modeISFIFO = 010000 // FIFO
|
||||
modeISREG = 0100000 // Regular file
|
||||
modeISLNK = 0120000 // Symbolic link
|
||||
modeISBLK = 060000 // Block special file
|
||||
modeISCHR = 020000 // Character special file
|
||||
modeISSOCK = 0140000 // Socket
|
||||
)
|
||||
|
||||
// IsArchivePath checks if the (possibly compressed) file at the given path
|
||||
// starts with a tar file header.
|
||||
func IsArchivePath(path string) bool {
|
||||
|
@ -458,9 +448,7 @@ func FileInfoHeaderNoLookups(fi os.FileInfo, link string) (*tar.Header, error) {
|
|||
// but is safe to call from a chrooted process. The AccessTime and ChangeTime
|
||||
// fields are not set in the returned header, ModTime is truncated to one-second
|
||||
// precision, and the Uname and Gname fields are only set when fi is a FileInfo
|
||||
// value returned from tar.Header.FileInfo(). Also, regardless of Go version,
|
||||
// this function fills file type bits (e.g. hdr.Mode |= modeISDIR), which have
|
||||
// been deleted since Go 1.9 archive/tar.
|
||||
// value returned from tar.Header.FileInfo().
|
||||
func FileInfoHeader(name string, fi os.FileInfo, link string) (*tar.Header, error) {
|
||||
hdr, err := FileInfoHeaderNoLookups(fi, link)
|
||||
if err != nil {
|
||||
|
@ -470,36 +458,11 @@ func FileInfoHeader(name string, fi os.FileInfo, link string) (*tar.Header, erro
|
|||
hdr.ModTime = hdr.ModTime.Truncate(time.Second)
|
||||
hdr.AccessTime = time.Time{}
|
||||
hdr.ChangeTime = time.Time{}
|
||||
hdr.Mode = fillGo18FileTypeBits(int64(chmodTarEntry(os.FileMode(hdr.Mode))), fi)
|
||||
hdr.Mode = int64(chmodTarEntry(os.FileMode(hdr.Mode)))
|
||||
hdr.Name = canonicalTarName(name, fi.IsDir())
|
||||
return hdr, nil
|
||||
}
|
||||
|
||||
// fillGo18FileTypeBits fills type bits which have been removed on Go 1.9 archive/tar
|
||||
// https://github.com/golang/go/commit/66b5a2f
|
||||
func fillGo18FileTypeBits(mode int64, fi os.FileInfo) int64 {
|
||||
fm := fi.Mode()
|
||||
switch {
|
||||
case fm.IsRegular():
|
||||
mode |= modeISREG
|
||||
case fi.IsDir():
|
||||
mode |= modeISDIR
|
||||
case fm&os.ModeSymlink != 0:
|
||||
mode |= modeISLNK
|
||||
case fm&os.ModeDevice != 0:
|
||||
if fm&os.ModeCharDevice != 0 {
|
||||
mode |= modeISCHR
|
||||
} else {
|
||||
mode |= modeISBLK
|
||||
}
|
||||
case fm&os.ModeNamedPipe != 0:
|
||||
mode |= modeISFIFO
|
||||
case fm&os.ModeSocket != 0:
|
||||
mode |= modeISSOCK
|
||||
}
|
||||
return mode
|
||||
}
|
||||
|
||||
// ReadSecurityXattrToTarHeader reads security.capability xattr from filesystem
|
||||
// to a tar header
|
||||
func ReadSecurityXattrToTarHeader(path string, hdr *tar.Header) error {
|
||||
|
|
|
@ -31,14 +31,11 @@ func CanonicalTarNameForPath(p string) string {
|
|||
// chmodTarEntry is used to adjust the file permissions used in tar header based
|
||||
// on the platform the archival is done.
|
||||
func chmodTarEntry(perm os.FileMode) os.FileMode {
|
||||
// perm &= 0755 // this 0-ed out tar flags (like link, regular file, directory marker etc.)
|
||||
permPart := perm & os.ModePerm
|
||||
noPermPart := perm &^ os.ModePerm
|
||||
// Add the x bit: make everything +x from windows
|
||||
permPart |= 0111
|
||||
permPart &= 0755
|
||||
// Remove group- and world-writable bits.
|
||||
perm &= 0o755
|
||||
|
||||
return noPermPart | permPart
|
||||
// Add the x bit: make everything +x on Windows
|
||||
return perm | 0o111
|
||||
}
|
||||
|
||||
func setHeaderForSpecialDevice(hdr *tar.Header, name string, stat interface{}) (err error) {
|
||||
|
|
|
@ -75,8 +75,6 @@ func TestChmodTarEntry(t *testing.T) {
|
|||
{0644, 0755},
|
||||
{0755, 0755},
|
||||
{0444, 0555},
|
||||
{0755 | os.ModeDir, 0755 | os.ModeDir},
|
||||
{0755 | os.ModeSymlink, 0755 | os.ModeSymlink},
|
||||
}
|
||||
for _, v := range cases {
|
||||
if out := chmodTarEntry(v.in); out != v.expected {
|
||||
|
|
Loading…
Reference in a new issue