build: Fix timestamp of files created by 'docker export'

Currently 'docker export' is used to convert a linuxkit entry
in the YAML file to a tar file of the root filesystem. This
process creates a number of files and directories which have
the timestamp of when the 'docker export' is run. Fix 'em up.

Signed-off-by: Rolf Neugebauer <rn@rneugeba.io>
This commit is contained in:
Rolf Neugebauer 2018-12-28 16:54:04 +00:00
parent 5cbc156faf
commit 93596225da

View File

@ -53,6 +53,18 @@ ff02::2 ip6-allrouters
`, `,
} }
// Files which may be created as part of 'docker export'. These need their timestamp fixed.
var touch = map[string]bool{
"dev/": true,
"dev/pts/": true,
"dev/shm/": true,
"etc/": true,
"etc/mtab": true,
"etc/resolv.conf": true,
"proc/": true,
"sys/": true,
}
// tarPrefix creates the leading directories for a path // tarPrefix creates the leading directories for a path
func tarPrefix(path string, tw tarWriter) error { func tarPrefix(path string, tw tarWriter) error {
if path == "" { if path == "" {
@ -182,7 +194,12 @@ func ImageTar(ref *reference.Spec, prefix string, tw tarWriter, trust bool, pull
return err return err
} }
} else { } else {
log.Debugf("image tar: %s %s add %s (original)", ref, prefix, hdr.Name) if touch[hdr.Name] {
log.Debugf("image tar: %s %s add %s (touch)", ref, prefix, hdr.Name)
hdr.ModTime = defaultModTime
} else {
log.Debugf("image tar: %s %s add %s (original)", ref, prefix, hdr.Name)
}
hdr.Name = prefix + hdr.Name hdr.Name = prefix + hdr.Name
if hdr.Typeflag == tar.TypeLink { if hdr.Typeflag == tar.TypeLink {
// hard links are referenced by full path so need to be adjusted // hard links are referenced by full path so need to be adjusted