atomic_write_file

Function atomic_write_file 

Source
pub async fn atomic_write_file(
    parent: &DirectoryProxy,
    path: &str,
    contents: &[u8],
) -> Result<(), WriteError>
Expand description

Atomically creates path with contents.

This is done by opening an unnamed temporary file, writing the contents into it, and linking to $(path).__tmp, and then renaming the temporary file to path.

Note that power failure after the temporary file was created, but before it was renamed, will result in the temporary file existing in the filesystem. This function will always try to remove that file first, but if this function is never called, the temp file will never be removed.

TODO(https://fxbug.dev/444270977): It would be preferable if we could avoid creating the named temporary file, but a limitation in Node/LinkInto prevents this. Once that limitation is resolved, directly LinkInto over the target file, avoiding the need to clean up on poewr failure.

Note that not all filesystems support this feature.

Available at HEAD since FLAG_CREATE_AS_UNNAMED_TEMPORARY is available at HEAD