11// Package archive provides helper functions for dealing with archive files.
2- package archive // import "github.com/docker/docker/pkg/archive"
2+ package archive
33
44import (
55 "archive/tar"
@@ -26,7 +26,6 @@ import (
2626 "github.com/containerd/log"
2727 "github.com/docker/docker/pkg/idtools"
2828 "github.com/docker/docker/pkg/pools"
29- "github.com/docker/docker/pkg/system"
3029 "github.com/klauspost/compress/zstd"
3130 "github.com/moby/patternmatcher"
3231 "github.com/moby/sys/sequential"
@@ -507,7 +506,7 @@ func ReadSecurityXattrToTarHeader(path string, hdr *tar.Header) error {
507506 vfsCapRevision2 = 2
508507 vfsCapRevision3 = 3
509508 )
510- capability , _ := system . Lgetxattr (path , "security.capability" )
509+ capability , _ := lgetxattr (path , "security.capability" )
511510 if capability != nil {
512511 if capability [versionOffset ] == vfsCapRevision3 {
513512 // Convert VFS_CAP_REVISION_3 to VFS_CAP_REVISION_2 as root UID makes no
@@ -799,7 +798,7 @@ func createTarFile(path, extractDir string, hdr *tar.Header, reader io.Reader, o
799798 if ! ok {
800799 continue
801800 }
802- if err := system . Lsetxattr (path , xattr , []byte (value ), 0 ); err != nil {
801+ if err := lsetxattr (path , xattr , []byte (value ), 0 ); err != nil {
803802 if bestEffortXattrs && errors .Is (err , syscall .ENOTSUP ) || errors .Is (err , syscall .EPERM ) {
804803 // EPERM occurs if modifying xattrs is not allowed. This can
805804 // happen when running in userns with restrictions (ChromeOS).
@@ -822,26 +821,22 @@ func createTarFile(path, extractDir string, hdr *tar.Header, reader io.Reader, o
822821 return err
823822 }
824823
825- aTime := hdr .AccessTime
826- if aTime .Before (hdr .ModTime ) {
827- // Last access time should never be before last modified time.
828- aTime = hdr .ModTime
829- }
824+ aTime := boundTime (latestTime (hdr .AccessTime , hdr .ModTime ))
825+ mTime := boundTime (hdr .ModTime )
830826
831- // system.Chtimes doesn't support a NOFOLLOW flag atm
827+ // chtimes doesn't support a NOFOLLOW flag atm
832828 if hdr .Typeflag == tar .TypeLink {
833829 if fi , err := os .Lstat (hdr .Linkname ); err == nil && (fi .Mode ()& os .ModeSymlink == 0 ) {
834- if err := system . Chtimes (path , aTime , hdr . ModTime ); err != nil {
830+ if err := chtimes (path , aTime , mTime ); err != nil {
835831 return err
836832 }
837833 }
838834 } else if hdr .Typeflag != tar .TypeSymlink {
839- if err := system . Chtimes (path , aTime , hdr . ModTime ); err != nil {
835+ if err := chtimes (path , aTime , mTime ); err != nil {
840836 return err
841837 }
842838 } else {
843- ts := []syscall.Timespec {timeToTimespec (aTime ), timeToTimespec (hdr .ModTime )}
844- if err := system .LUtimesNano (path , ts ); err != nil && err != system .ErrNotSupportedPlatform {
839+ if err := lchtimes (path , aTime , mTime ); err != nil {
845840 return err
846841 }
847842 }
@@ -1201,7 +1196,7 @@ loop:
12011196 // #nosec G305 -- The header was checked for path traversal before it was appended to the dirs slice.
12021197 path := filepath .Join (dest , hdr .Name )
12031198
1204- if err := system . Chtimes (path , hdr .AccessTime , hdr .ModTime ); err != nil {
1199+ if err := chtimes (path , boundTime ( latestTime ( hdr .AccessTime , hdr .ModTime )), boundTime ( hdr . ModTime ) ); err != nil {
12051200 return err
12061201 }
12071202 }
@@ -1350,7 +1345,7 @@ func (archiver *Archiver) CopyFileWithTar(src, dst string) (err error) {
13501345 dst = filepath .Join (dst , filepath .Base (src ))
13511346 }
13521347 // Create the holding directory if necessary
1353- if err := system .MkdirAll (filepath .Dir (dst ), 0o700 ); err != nil {
1348+ if err := os .MkdirAll (filepath .Dir (dst ), 0o700 ); err != nil {
13541349 return err
13551350 }
13561351
0 commit comments