Skip to content

Commit

Permalink
Merge pull request #180 from nalind/subsecond
Browse files Browse the repository at this point in the history
pkg/archive: use subsecond timestamps in Copy...WithTar
  • Loading branch information
rhatdan authored May 30, 2018
2 parents 620f6bd + dc5a7f2 commit 8a34ffd
Show file tree
Hide file tree
Showing 4 changed files with 154 additions and 1 deletion.
16 changes: 16 additions & 0 deletions pkg/archive/archive.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ type (
// replaced with the matching name from this map.
RebaseNames map[string]string
InUserNS bool
// CopyPass indicates that the contents of any archive we're creating
// will instantly be extracted and written to disk, so we can deviate
// from the traditional behavior/format to get features like subsecond
// precision in timestamps.
CopyPass bool
}
)

Expand Down Expand Up @@ -396,6 +401,11 @@ type tarAppender struct {
// by the AUFS standard are used as the tar whiteout
// standard.
WhiteoutConverter tarWhiteoutConverter
// CopyPass indicates that the contents of any archive we're creating
// will instantly be extracted and written to disk, so we can deviate
// from the traditional behavior/format to get features like subsecond
// precision in timestamps.
CopyPass bool
}

func newTarAppender(idMapping *idtools.IDMappings, writer io.Writer, chownOpts *idtools.IDPair) *tarAppender {
Expand Down Expand Up @@ -446,6 +456,9 @@ func (ta *tarAppender) addTarFile(path, name string) error {
if err := ReadSecurityXattrToTarHeader(path, hdr); err != nil {
return err
}
if ta.CopyPass {
copyPassHeader(hdr)
}

// if it's not a directory and has more than 1 link,
// it's hard linked, so set the type flag accordingly
Expand Down Expand Up @@ -710,6 +723,7 @@ func TarWithOptions(srcPath string, options *TarOptions) (io.ReadCloser, error)
options.ChownOpts,
)
ta.WhiteoutConverter = getWhiteoutConverter(options.WhiteoutFormat, options.WhiteoutData)
ta.CopyPass = options.CopyPass

defer func() {
// Make sure to check the error on Close.
Expand Down Expand Up @@ -1039,6 +1053,7 @@ func (archiver *Archiver) TarUntar(src, dst string) error {
UIDMaps: tarMappings.UIDs(),
GIDMaps: tarMappings.GIDs(),
Compression: Uncompressed,
CopyPass: true,
}
archive, err := TarWithOptions(src, options)
if err != nil {
Expand Down Expand Up @@ -1145,6 +1160,7 @@ func (archiver *Archiver) CopyFileWithTar(src, dst string) (err error) {
}
hdr.Name = filepath.Base(dst)
hdr.Mode = int64(chmodTarEntry(os.FileMode(hdr.Mode)))
copyPassHeader(hdr)

if err := remapIDs(archiver.TarIDMappings, nil, archiver.ChownOpts, hdr); err != nil {
return err
Expand Down
11 changes: 11 additions & 0 deletions pkg/archive/archive_110.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// +build go1.10

package archive

import (
"archive/tar"
)

func copyPassHeader(hdr *tar.Header) {
hdr.Format = tar.FormatPAX
}
10 changes: 10 additions & 0 deletions pkg/archive/archive_19.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// +build !go1.10

package archive

import (
"archive/tar"
)

func copyPassHeader(hdr *tar.Header) {
}
118 changes: 117 additions & 1 deletion pkg/archive/archive_ffjson.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 8a34ffd

Please sign in to comment.