Skip to content

WriteFileAtomic - #333

Merged
kke merged 1 commit into
mainfrom
write-file-atomic
May 5, 2026
Merged

kke merged 1 commit into
mainfrom
write-file-atomic

Conversation

@kke

@kke kke commented May 5, 2026

Copy link
Copy Markdown
Contributor

Add WriteFileAtomic and fix WinFS.Rename

Add remotefs.WriteFileAtomic, a package-level function that writes data
to a path atomically via a temp-then-rename sequence: creates a temp
file in the same directory, writes with restricted permissions (0o600),
chmod's to the final perm, then renames into place. Parent directories
are created as needed. Deferred Remove cleans up the temp file on any
failure before the rename.

Also fix WinFS.Rename: add -Force to Move-Item so it overwrites an
existing destination (matching POSIX mv -f semantics), and fix the
error format string to include newpath.

Part of the rig v2 last mile effort, breaking API is not a problem as rig v2 has not been released yet.

@kke kke added the enhancement New feature or request label May 5, 2026
@kke
kke requested a review from Copilot May 5, 2026 06:14

Copilot AI 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.

Pull request overview

This PR introduces an atomic file-write helper for the remotefs package and aligns Windows rename behavior with POSIX overwrite semantics, supporting the rig v2 “last mile” effort.

Changes:

  • Add remotefs.WriteFileAtomic, implementing temp-file + rename atomic writes with directory creation and permission staging.
  • Add unit tests for WriteFileAtomic, including an end-to-end flow via PosixFS.
  • Fix WinFS.Rename to overwrite existing destinations and improve its error formatting.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
remotefs/writefileatomic.go Adds WriteFileAtomic implementation using temp-then-rename semantics.
remotefs/writefileatomic_test.go Adds stub-based unit tests plus an integration-style test via PosixFS.
remotefs/winfs.go Updates WinFS.Rename to overwrite existing targets (-Force) and improves error context.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread remotefs/writefileatomic.go Resolved
Comment thread remotefs/writefileatomic_test.go Resolved
Comment thread remotefs/winfs.go Resolved
@kke
kke force-pushed the write-file-atomic branch from 6f34180 to 21643d7 Compare May 5, 2026 06:44
@kke
kke requested a review from Copilot May 5, 2026 06:45

Copilot AI 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.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread remotefs/writefileatomic.go Resolved
Comment thread remotefs/winfs.go Resolved
Add remotefs.WriteFileAtomic, a package-level function that writes data
to a path atomically via a temp-then-rename sequence: creates a temp
file in the same directory, writes with restricted permissions (0o600),
chmod's to the final perm, then renames into place. Parent directories
are created as needed. Deferred Remove cleans up the temp file on any
failure before the rename.

Also fix WinFS.Rename: add -Force to Move-Item so it overwrites an
existing destination (matching POSIX mv -f semantics), and fix the
error format string to include newpath.

Signed-off-by: Kimmo Lehto <klehto@mirantis.com>
@kke
kke force-pushed the write-file-atomic branch from 21643d7 to 8da886f Compare May 5, 2026 07:24
@kke
kke requested a review from Copilot May 5, 2026 07:25

Copilot AI 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.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated no new comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@kke
kke marked this pull request as ready for review May 5, 2026 07:32
@kke
kke merged commit eb568d3 into main May 5, 2026
15 checks passed
@kke
kke deleted the write-file-atomic branch May 5, 2026 07:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants