Skip to content

Commit

Permalink
Merge pull request #212 from CthulhuDen/master
Browse files Browse the repository at this point in the history
Restore file modification times
  • Loading branch information
foymikek authored Sep 21, 2022
2 parents ab88f2d + 4917ade commit 578f62f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,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

Expand Down
7 changes: 7 additions & 0 deletions archive/tar/tar.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ func writeToArchive(tw *tar.Writer, root string, skipSymlinks bool, written *int
}

h.Name = name
h.Format = tar.FormatPAX

if err := tw.WriteHeader(h); err != nil {
return fmt.Errorf("write header for <%s>, %w", path, err)
Expand Down Expand Up @@ -261,6 +262,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
}

Expand Down

0 comments on commit 578f62f

Please sign in to comment.