Skip to content

fix: preserve file mtime after atomic rewrite#98

Closed
leno23 wants to merge 1 commit into
dolph:mainfrom
leno23:fix/preserve-mtime-issue-23-v2
Closed

fix: preserve file mtime after atomic rewrite#98
leno23 wants to merge 1 commit into
dolph:mainfrom
leno23:fix/preserve-mtime-issue-23-v2

Conversation

@leno23
Copy link
Copy Markdown

@leno23 leno23 commented May 31, 2026

Summary

  • Call os.Chtimes on the temp file before rename to preserve the original modification time

Test plan

  • go test -run ModTime ./...

Fixes #23

Made with Cursor

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
Copy link
Copy Markdown

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

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: 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".

Comment thread file_handling.go
Comment on lines +107 to +108
if err := os.Chtimes(tempName, modTime, modTime); err != nil {
return fmt.Errorf("preserve mtime on temp file %v: %w", tempName, err)
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 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 👍 / 👎.

@dolph dolph closed this Jun 2, 2026
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.

mtime is not preserved after rewrite

2 participants