Fix access time updates changing modification time - #1292
Conversation
1d0d829 to
9ebea30
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 1d0d82911d
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| // Ensure it's access date is different than our desired access date | ||
| let arbitraryDate = Date.init(year: 2008, month: 09, day: 28, hour: 23, minute: 15) | ||
| let modificationDate = Date(timeIntervalSince1970: 1_577_836_800) | ||
| try FileManager.default.setAttributes([.modificationDate: modificationDate], atPath: tmpFile.path) |
There was a problem hiding this comment.
Use the Foundation setAttributes label
When the test target is compiled, this call doesn't match Foundation's FileManager.setAttributes API, which takes ofItemAtPath:; the repo's other call in SoftnetControlFDTests.swift uses that label. Because swift build --product tart does not compile tests, this newly added regression test can still be checked in but swift test will fail before running it; use ofItemAtPath: here.
Useful? React with 👍 / 👎.
| let attrs = try resourceValues(forKeys: [.contentAccessDateKey]) | ||
| let modificationDate = attrs.contentAccessDate! | ||
| let attrs = try resourceValues(forKeys: [.contentModificationDateKey]) | ||
| let modificationDate = attrs.contentModificationDate! |
There was a problem hiding this comment.
When the existing modification time contains fractional seconds, saving it here still won't preserve it because the later modificationDate.asTimeval() goes through Date.asTimeval(), which always sets tv_usec to 0. Every updateAccessDate() call therefore rounds the mtime down to a whole second even though only atime should change; pass through the fractional component, or use a nanosecond timestamp API, for the saved mtime.
Useful? React with 👍 / 👎.
84cd4c4 to
f0e9526
Compare
f0e9526 to
7e77e5c
Compare
URL.updateAccessDate()currently readscontentAccessDateand passes it toutimes()as the modification timestamp. As a result, opening a local or cached VM can replace its modification time with its previous access time.This reads
contentModificationDateinstead, so only the requested access time changes.Date.asTimeval()now carries the microsecond component as well, avoiding modification-time rounding when the timestamp contains fractional seconds.The regression test sets a modification timestamp with fractional seconds and verifies that it remains unchanged after the access-time update.
Testing
swift build --product tart1577836800.125000remains unchanged