Skip to content

Commit

Permalink
Restore file modification times
Browse files Browse the repository at this point in the history
  • Loading branch information
CthulhuDen committed Aug 26, 2022
1 parent 3574624 commit 0991bbf
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -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

Expand Down
7 changes: 7 additions & 0 deletions archive/tar/tar.go
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}

Expand Down

0 comments on commit 0991bbf

Please sign in to comment.