Skip to content

Use unique temporary files for atomic edits - #7

Closed
sylvesterkaczmarek wants to merge 1 commit into
google-deepmind:mainfrom
sylvesterkaczmarek:fix/edit-file-unique-temp
Closed

sylvesterkaczmarek wants to merge 1 commit into
google-deepmind:mainfrom
sylvesterkaczmarek:fix/edit-file-unique-temp

Conversation

@sylvesterkaczmarek

Copy link
Copy Markdown
Contributor

atomicWrite uses a fixed <path>.amplio.tmp name. Concurrent writes can overwrite or rename each other's temporary file, and an unrelated file with that name is overwritten and removed. A failed rename also leaves the temporary file behind.

Create a unique temporary file in the destination directory, preserve the target's permissions, close before renaming, and clean up on every return path. This preserves last-writer-wins behavior; it does not add edit conflict detection.

Validation

go test -race ./internal/tool/editfile ./internal/tool/anchor ./internal/tool/viewfile: 79 tests passed. The three new atomic-write regressions fail on unpatched main and pass after the fix, including 30 repeated race-enabled runs. go vet for those packages and gofmt pass. Tested on macOS; no Windows execution was performed.

pluskid pushed a commit that referenced this pull request Sep 16, 2026
@pluskid

pluskid commented Sep 16, 2026

Copy link
Copy Markdown
Collaborator

Thank you! Manually merged in 7684e38 with authorship preserved.

@pluskid pluskid closed this Sep 16, 2026
@sylvesterkaczmarek

Copy link
Copy Markdown
Contributor Author

Thanks for merging this and preserving the authorship. Much appreciated.

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.

2 participants