From fb170206ba12752214630b269a40ac7be6115ed4 Mon Sep 17 00:00:00 2001 From: Derek McGowan Date: Mon, 2 Apr 2018 10:48:34 -0700 Subject: [PATCH] Set format in archiver Prevent changing the tar output by setting the format to PAX and keeping the times truncated. Without this change the archiver will produce different tar archives with different hashes with go 1.10. The addition of the access and changetime timestamps would also cause diff comparisons to fail. Signed-off-by: Derek McGowan Signed-off-by: Sebastiaan van Stijn --- pkg/archive/archive.go | 9 +++++++++ pkg/containerfs/archiver.go | 5 +++++ 2 files changed, 14 insertions(+) diff --git a/pkg/archive/archive.go b/pkg/archive/archive.go index e8f50869d9..5fb3995e9b 100644 --- a/pkg/archive/archive.go +++ b/pkg/archive/archive.go @@ -17,6 +17,7 @@ import ( "strconv" "strings" "syscall" + "time" "github.com/docker/docker/pkg/fileutils" "github.com/docker/docker/pkg/idtools" @@ -360,6 +361,10 @@ func FileInfoHeader(name string, fi os.FileInfo, link string) (*tar.Header, erro if err != nil { return nil, err } + hdr.Format = tar.FormatPAX + 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) name, err = canonicalTarName(name, fi.IsDir()) if err != nil { @@ -1158,6 +1163,10 @@ func (archiver *Archiver) CopyFileWithTar(src, dst string) (err error) { if err != nil { return err } + hdr.Format = tar.FormatPAX + hdr.ModTime = hdr.ModTime.Truncate(time.Second) + hdr.AccessTime = time.Time{} + hdr.ChangeTime = time.Time{} hdr.Name = filepath.Base(dst) hdr.Mode = int64(chmodTarEntry(os.FileMode(hdr.Mode))) diff --git a/pkg/containerfs/archiver.go b/pkg/containerfs/archiver.go index 405f14f780..1fb7ff7bdc 100644 --- a/pkg/containerfs/archiver.go +++ b/pkg/containerfs/archiver.go @@ -6,6 +6,7 @@ import ( "io" "os" "path/filepath" + "time" "github.com/docker/docker/pkg/archive" "github.com/docker/docker/pkg/idtools" @@ -138,6 +139,10 @@ func (archiver *Archiver) CopyFileWithTar(src, dst string) (err error) { if err != nil { return err } + hdr.Format = tar.FormatPAX + hdr.ModTime = hdr.ModTime.Truncate(time.Second) + hdr.AccessTime = time.Time{} + hdr.ChangeTime = time.Time{} hdr.Name = dstDriver.Base(dst) if dstDriver.OS() == "windows" { hdr.Mode = int64(chmodTarEntry(os.FileMode(hdr.Mode)))