From 0991bbfef8d1cd6d2ef9b41582e8b91e1e7e2cc3 Mon Sep 17 00:00:00 2001 From: Cthulhu Date: Fri, 26 Aug 2022 05:58:32 +0300 Subject: [PATCH] Restore file modification times --- CHANGELOG.md | 1 + archive/tar/tar.go | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 78d76a95..5fe6d322 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added +- [#212](https://github.com/meltwater/drone-cache/pull/212) `filesystem` backend now restores files modification time (with sub-second prevision if possible) - [#209](https://github.com/meltwater/drone-cache/pull/209) Added double star directory searching in mounts (e.g. `path/**/subdir`) - [#198](https://github.com/meltwater/drone-cache/pull/198) Add `hashFiles` template function to generate the SHA256 hash of multiple files diff --git a/archive/tar/tar.go b/archive/tar/tar.go index ab5130f5..59b72210 100644 --- a/archive/tar/tar.go +++ b/archive/tar/tar.go @@ -72,6 +72,7 @@ func writeToArchive(tw *tar.Writer, root string, skipSymlinks bool, written *int if err != nil { return fmt.Errorf("create header for <%s>, %w", path, err) } + h.Format = tar.FormatPAX if fi.Mode()&os.ModeSymlink != 0 { // isSymbolic if skipSymlinks { @@ -254,6 +255,12 @@ func extractRegular(h *tar.Header, tr io.Reader, target string) (int64, error) { return written, fmt.Errorf("copy extracted file for writing <%s>, %w", target, err) } + if !h.ModTime.IsZero() { + if err = os.Chtimes(target, h.AccessTime, h.ModTime); err != nil { + return written, fmt.Errorf("set atime/mtime <%s>, %w", target, err) + } + } + return written, nil }