From 9e0fb3e0c758ff3ac9261536985a91cc53c5b1eb Mon Sep 17 00:00:00 2001 From: "Stefan J. Wernli" Date: Thu, 5 Nov 2015 11:47:18 -0800 Subject: [PATCH] Fixing last access time on Windows to unblock python. Signed-off-by: Stefan J. Wernli --- archive/archive.go | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/archive/archive.go b/archive/archive.go index e7c82e1..1c8e115 100644 --- a/archive/archive.go +++ b/archive/archive.go @@ -407,19 +407,25 @@ func createTarFile(path, extractDir string, hdr *tar.Header, reader io.Reader, L return err } + aTime := hdr.AccessTime + if aTime.Before(hdr.ModTime) { + // Last access time should never be before last modified time. + aTime = hdr.ModTime + } + // system.Chtimes doesn't support a NOFOLLOW flag atm if hdr.Typeflag == tar.TypeLink { if fi, err := os.Lstat(hdr.Linkname); err == nil && (fi.Mode()&os.ModeSymlink == 0) { - if err := system.Chtimes(path, hdr.AccessTime, hdr.ModTime); err != nil { + if err := system.Chtimes(path, aTime, hdr.ModTime); err != nil { return err } } } else if hdr.Typeflag != tar.TypeSymlink { - if err := system.Chtimes(path, hdr.AccessTime, hdr.ModTime); err != nil { + if err := system.Chtimes(path, aTime, hdr.ModTime); err != nil { return err } } else { - ts := []syscall.Timespec{timeToTimespec(hdr.AccessTime), timeToTimespec(hdr.ModTime)} + ts := []syscall.Timespec{timeToTimespec(aTime), timeToTimespec(hdr.ModTime)} if err := system.LUtimesNano(path, ts); err != nil && err != system.ErrNotSupportedPlatform { return err }