v0.9.3 — Release Candidate - Prep #3
jamesgober
announced in
Announcements
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
mod-tempdir v0.9.3 — Release Notes
Date: 2026-05-13
Compare:
v0.9.2...v0.9.3Headline
Crash-safe file finalization via
NamedTempFile::persist_atomic,with a structured error type that preserves the source temp file
on failure so a retry path never loses data.
What's new
Public API additions
NamedTempFile::persist_atomic(target) -> Result<PathBuf, PersistAtomicError>Atomically move the temp file to
targetand disable cleanup ondrop. Performs the canonical "atomic durable write" sequence:
fsyncthe temp file(
std::fs::File::sync_all)std::fs::rename(POSIXrename(2)on Unix,MoveFileExWwithMOVEFILE_REPLACE_EXISTINGon Windows)fsyncof the target's parent directory so therename itself survives a crash.
Atomic within a single filesystem. Cross-filesystem
targetreturns
EXDEV(Unix) or the equivalent (Windows) inside theerror.
PersistAtomicError { error: io::Error, file: NamedTempFile }Structured error type. On any failure of
persist_atomic, thetemp file is preserved on disk and the original
NamedTempFileis returned to the caller inside the error so a retry or
fallback path does not lose the source. Implements
Debug,Display,std::error::Error, andFrom<PersistAtomicError> for io::Errorfor callers that only need the underlying IOerror.
Test additions
tests/persist_atomic.rs— four integration tests:→ source survives, recovered
NamedTempFilepoints at theoriginal temp path.
path after a successful persist.
Documentation
pattern.
persist_atomicandPersistAtomicErrorinthe public API surface.
persist_atomicincludes both the happy-path exampleand the retry pattern on recoverable error.
Why no fsys
The roadmap reserved a possible v0.9.3+
fsysintegration forthis milestone. After auditing the
fsyspublic API, theintegration was not taken:
fsys::platform::atomic_renameispub(crate)— not callablefrom outside the crate.
fsys::Handle::renamerequires both paths to live under asingle handle root, which does not fit a generic
temp_dir → arbitrary_targetmove.std::fs::renameinvokes the same OS primitivesfsysusesinternally (POSIX
rename(2)on Unix,MoveFileExWonWindows), so the
std-only path is functionally equivalent forthis use case and keeps the default zero-dep build intact.
Same architectural call as the retired
v0.9.1fsys-for-directory-opsmilestone: when
fsys's value lives in its internals rather thanits public surface, adding the dep does not pay off.
Migration
Purely additive. No code edits needed for existing callers. To
use the new method:
Verification
cargo build/--features mod-rand/--all-featurescargo +1.75 build --all-features(MSRV check)cargo fmt --all -- --checkcargo clippy --all-targets --all-features -- -D warningscargo test --all-features: 63 tests pass (Windows)cargo test(default): 59 tests passcargo doc --no-depsand--all-features: 0 warningsCI matrix: ubuntu-latest, macos-latest, windows-latest.
Limitations
persist_atomicis atomic only within a single filesystem.Cross-mount
targetreturnsEXDEV/ equivalent. Callersneeding cross-filesystem finalization should copy through the
target filesystem first using
TempDir::with_prefixrooted atthe target's parent.
fsyncis best-effort; on Windows it requiresFILE_FLAG_BACKUP_SEMANTICSto acquire the directory handle.Failures here are silent and do not affect the return value
(the rename itself has already succeeded by that point).
a successful
persist_atomicconsumesself; an unsuccessfulone returns it inside
PersistAtomicError.file. Callers thatuse
io::Result<PathBuf>via theFromconversion lose therecovered file. Use the structured
Result<PathBuf, PersistAtomicError>return type directly when retry-on-failure matters.
This discussion was created from the release v0.9.3 — Release Candidate - Prep.
All reactions