Skip to content

Commit 578f62f

Browse files
authored
Merge pull request meltwater#212 from CthulhuDen/master
Restore file modification times
2 parents ab88f2d + 4917ade commit 578f62f

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2626

2727
### Added
2828

29+
- [#212](https://github.com/meltwater/drone-cache/pull/212) `filesystem` backend now restores files modification time (with sub-second prevision if possible)
2930
- [#209](https://github.com/meltwater/drone-cache/pull/209) Added double star directory searching in mounts (e.g. `path/**/subdir`)
3031
- [#198](https://github.com/meltwater/drone-cache/pull/198) Add `hashFiles` template function to generate the SHA256 hash of multiple files
3132

archive/tar/tar.go

+7
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ func writeToArchive(tw *tar.Writer, root string, skipSymlinks bool, written *int
9797
}
9898

9999
h.Name = name
100+
h.Format = tar.FormatPAX
100101

101102
if err := tw.WriteHeader(h); err != nil {
102103
return fmt.Errorf("write header for <%s>, %w", path, err)
@@ -261,6 +262,12 @@ func extractRegular(h *tar.Header, tr io.Reader, target string) (int64, error) {
261262
return written, fmt.Errorf("copy extracted file for writing <%s>, %w", target, err)
262263
}
263264

265+
if !h.ModTime.IsZero() {
266+
if err = os.Chtimes(target, h.AccessTime, h.ModTime); err != nil {
267+
return written, fmt.Errorf("set atime/mtime <%s>, %w", target, err)
268+
}
269+
}
270+
264271
return written, nil
265272
}
266273

0 commit comments

Comments
 (0)