Skip to content

Fix access time updates changing modification time - #1292

Open
fallintoplace wants to merge 1 commit into
openai:mainfrom
fallintoplace:fix/preserve-modification-date
Open

Fix access time updates changing modification time#1292
fallintoplace wants to merge 1 commit into
openai:mainfrom
fallintoplace:fix/preserve-modification-date

Conversation

@fallintoplace

@fallintoplace fallintoplace commented Jul 24, 2026

Copy link
Copy Markdown

URL.updateAccessDate() currently reads contentAccessDate and passes it to utimes() 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 contentModificationDate instead, 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 tart
  • SwiftFormat lint
  • verified with the built executable that a modification time of 1577836800.125000 remains unchanged

@fallintoplace
fallintoplace force-pushed the fix/preserve-modification-date branch from 1d0d829 to 9ebea30 Compare July 24, 2026 17:33
@fallintoplace fallintoplace changed the title Preserve modification date when updating access time Fix access time updates changing modification time Jul 24, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

Comment thread Sources/tart/URL+AccessDate.swift Outdated
let attrs = try resourceValues(forKeys: [.contentAccessDateKey])
let modificationDate = attrs.contentAccessDate!
let attrs = try resourceValues(forKeys: [.contentModificationDateKey])
let modificationDate = attrs.contentModificationDate!

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preserve subsecond mtimes

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 👍 / 👎.

@fallintoplace
fallintoplace force-pushed the fix/preserve-modification-date branch 2 times, most recently from 84cd4c4 to f0e9526 Compare July 24, 2026 17:38
@fallintoplace
fallintoplace force-pushed the fix/preserve-modification-date branch from f0e9526 to 7e77e5c Compare July 26, 2026 00:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant