Skip to content

v0.2.0: Replace for exact-path atomic publication

Latest

Choose a tag to compare

@spf13 spf13 released this 23 Oct 03:57

v0.2.0 — Replace for exact-path atomic publication

Additive only. Move/Copy/Rename unchanged.

New API

func Replace(src, dst string) (string, error)
func (f *Flow) Replace(src, dst string) (string, error)
  • Moves a regular file to exactly dst, intentionally overwriting different content without conflict suffixing. Returns dst on success.
  • Same-filesystem: native replace (Unix os.Rename, Windows MoveFileEx with MOVEFILE_REPLACE_EXISTING|WRITE_THROUGH).
  • Cross-filesystem: copy+sync to a temporary file in the destination directory, publish, then remove source.
  • Respects Flow.DirMode and NoCreateDirs; FindAvailableName ignored.
  • Source must be a regular file: symlinks/non-regular rejected with fs.ErrInvalid wrapped in ErrFailedMovingFile.
  • Destination symlink is replaced, not followed.
  • Same-file paths (including hard links) return ErrSameFile.
  • If cross-filesystem publication succeeds but source removal fails, returns dst plus *ErrFailedRemovingOriginal — destination already committed.
  • No crash-durability or CAS promise; sync and close staged source before calling Replace when durability matters.
  • On Windows, open-file sharing rules can reject replacement; error returned rather than deleting destination.

Compatibility

  • Go 1.19 floor preserved, golang.org/x/sys v0.30.0 only.
  • Fully additive; no breaking changes.
  • gorelease suggests v0.1.1 (patch) — released as v0.2.0 minor per additive intent.

Verification

  • go vet ./... clean, go test -race ./... pass, Windows amd64 go test -c ok, cross-filesystem smoke on /tmp vs /dev/shm.
  • RoboRev job 1645 PASS (commit 4be9157); prior job 1643 flagged and fixed a symlink ordering issue in Replace.
  • Windows runtime not exercised beyond cross-compile; open-file sharing caveat documented.