Skip to main content

Module atomic

Module atomic 

Source
Expand description

Atomic file I/O utilities for concurrency-safe cache operations.

This module provides:

  • Atomic writes via temp-file + rename to prevent partial/corrupt files.
  • Advisory file locking for coordinating concurrent access to cache directories.

§Concurrency Guarantees

  • A reader will never see a partially written file.
  • Concurrent writers to the same path will not interleave bytes; the last rename wins, producing one complete file.
  • Advisory locks coordinate cache-directory operations across processes.

§Cross-Platform Notes

  • On POSIX systems, rename(2) is atomic within the same filesystem.
  • On Windows, std::fs::rename uses MoveFileEx with MOVEFILE_REPLACE_EXISTING, which is atomic for same-volume renames.

Structs§

DirLock
An advisory file lock scoped to a directory.

Functions§

atomic_write
Write data to path atomically by writing to a temporary sibling file and then renaming it into place.
atomic_write_sync
Synchronous version of atomic_write for use in contexts that cannot use async (e.g., the FileSystem trait).