Skip to main content

try_atomic_write_if

Function try_atomic_write_if 

Source
pub fn try_atomic_write_if(
    path: &Path,
    bytes: &[u8],
    permissions: Option<&Permissions>,
    may_commit: impl FnOnce() -> bool,
) -> Result<(), Error>
Expand description

try_atomic_write with a last word for the caller: may_commit is asked once the new content is fully staged and synced, immediately before the replace. On false the staged file is removed, path is untouched and the error kind is TimedOut. Everything slow (cleanup, create, write, sync) lies before that question; after it only the replace itself follows — which on Windows may retry a held target for about a second.