Skip to content

fix(fs): AtomicWrite uses a unique synced temp file, watcher fingerprints real mtime - #3775

Merged
BaseMax merged 2 commits into
mainfrom
fix/fs-atomicwrite
Nov 21, 2026
Merged

BaseMax merged 2 commits into
mainfrom
fix/fs-atomicwrite

Conversation

@BaseMax

@BaseMax BaseMax commented Nov 21, 2026

Copy link
Copy Markdown
Member

AtomicWrite wrote to path.tmp, so concurrent writers clobbered each other and an existing x.tmp was destroyed. It also never fsynced and left the temp file behind when the rename failed.

It now writes to path..tmp in the same directory, flushes and fsyncs (_commit on Windows) before the rename, and removes the temp file on any failure. Windows rename also asks for write-through.

fs.watcher computed its fingerprint from os.FileSize twice, so same-size rewrites were missed. It now uses fs.ModTime.

Tests: tests/en/stdlib/fs_atomicwrite_safe (decoy x.tmp survives, failed rename leaves no temp) and fs_watcher_same_size; existing fs tests unchanged; check passes for x86_64-w64-windows-gnu and aarch64-apple-darwin.

…ints real mtime

AtomicWrite wrote to path.tmp, so concurrent writers clobbered each other and an existing x.tmp was destroyed; it never fsynced and left the temp file when rename failed. The watcher fingerprint used the file size twice instead of the modification time.
@BaseMax
BaseMax requested a review from a team as a code owner November 21, 2026 17:24
@coderabbitai

coderabbitai Bot commented Nov 21, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 46 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used all 2 included reviews currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 03311739-9532-4a1b-a175-aa30aecaa586
Commits

Reviewing files that changed from the base of the PR and between e07cb26 and dc354bf.

Files ignored due to path filters: 2

  • tests/en/stdlib/fs_atomicwrite_safe.out is excluded by !**/*.out
  • tests/en/stdlib/fs_watcher_same_size.out is excluded by !**/*.out
Files selected for processing: 4

  • std/fs/files.salam
  • std/fs/watcher/watcher.salam
  • tests/en/stdlib/fs_atomicwrite_safe.salam
  • tests/en/stdlib/fs_watcher_same_size.salam
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@BaseMax
BaseMax merged commit a24a4fb into main Nov 21, 2026
7 of 8 checks passed
@BaseMax
BaseMax deleted the fix/fs-atomicwrite branch November 21, 2026 17:26
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.

1 participant