Browse code

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 <derek@mcgstyle.net>
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>

Derek McGowan authored on 2018/04/03 02:48:34
Showing 2 changed files
... ...
@@ -17,6 +17,7 @@ import (
17 17
 	"strconv"
18 18
 	"strings"
19 19
 	"syscall"
20
+	"time"
20 21
 
21 22
 	"github.com/docker/docker/pkg/fileutils"
22 23
 	"github.com/docker/docker/pkg/idtools"
... ...
@@ -360,6 +361,10 @@ func FileInfoHeader(name string, fi os.FileInfo, link string) (*tar.Header, erro
360 360
 	if err != nil {
361 361
 		return nil, err
362 362
 	}
363
+	hdr.Format = tar.FormatPAX
364
+	hdr.ModTime = hdr.ModTime.Truncate(time.Second)
365
+	hdr.AccessTime = time.Time{}
366
+	hdr.ChangeTime = time.Time{}
363 367
 	hdr.Mode = fillGo18FileTypeBits(int64(chmodTarEntry(os.FileMode(hdr.Mode))), fi)
364 368
 	name, err = canonicalTarName(name, fi.IsDir())
365 369
 	if err != nil {
... ...
@@ -1158,6 +1163,10 @@ func (archiver *Archiver) CopyFileWithTar(src, dst string) (err error) {
1158 1158
 			if err != nil {
1159 1159
 				return err
1160 1160
 			}
1161
+			hdr.Format = tar.FormatPAX
1162
+			hdr.ModTime = hdr.ModTime.Truncate(time.Second)
1163
+			hdr.AccessTime = time.Time{}
1164
+			hdr.ChangeTime = time.Time{}
1161 1165
 			hdr.Name = filepath.Base(dst)
1162 1166
 			hdr.Mode = int64(chmodTarEntry(os.FileMode(hdr.Mode)))
1163 1167
 
... ...
@@ -6,6 +6,7 @@ import (
6 6
 	"io"
7 7
 	"os"
8 8
 	"path/filepath"
9
+	"time"
9 10
 
10 11
 	"github.com/docker/docker/pkg/archive"
11 12
 	"github.com/docker/docker/pkg/idtools"
... ...
@@ -138,6 +139,10 @@ func (archiver *Archiver) CopyFileWithTar(src, dst string) (err error) {
138 138
 			if err != nil {
139 139
 				return err
140 140
 			}
141
+			hdr.Format = tar.FormatPAX
142
+			hdr.ModTime = hdr.ModTime.Truncate(time.Second)
143
+			hdr.AccessTime = time.Time{}
144
+			hdr.ChangeTime = time.Time{}
141 145
 			hdr.Name = dstDriver.Base(dst)
142 146
 			if dstDriver.OS() == "windows" {
143 147
 				hdr.Mode = int64(chmodTarEntry(os.FileMode(hdr.Mode)))