fix: preserve file mtime after atomic rewrite#98
Conversation
Call os.Chtimes on the temp file before rename so Make-style dependency tracking and file watchers see a stable modification time. Fixes dolph#23
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 4ea06ee70b
ℹ️ About Codex in GitHub
Your team has set up Codex to 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 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if err := os.Chtimes(tempName, modTime, modTime); err != nil { | ||
| return fmt.Errorf("preserve mtime on temp file %v: %w", tempName, err) |
There was a problem hiding this comment.
Register temp cleanup before preserving times
When os.Chtimes fails after the temp file has already been created (for example on a filesystem that rejects the timestamp or denies utime updates), this new early return happens before the defer os.Remove(tempName) is installed, so Write leaves the random temp file behind in the target directory. That regresses the cleanup guarantee for failures after temp-file creation; move the defer immediately after os.WriteFile succeeds so the new Chtimes failure path is also cleaned up.
Useful? React with 👍 / 👎.
Summary
os.Chtimeson the temp file before rename to preserve the original modification timeTest plan
go test -run ModTime ./...Fixes #23
Made with Cursor