Zig 0.17.0-dev (Split by item)

This is an example of documentation generated by ZigDoc, an alternative to Zig's built-in Auto Doc feature. See also examples in other modes/formats. The project being documented here (as the example) is the Zig library itself.

replace

Atomically materializes the file into place, replacing any file that already exists there.

Calling this function requires setting CreateFileAtomicOptions.replace to true.

On Windows, this function introduces a period of time where some file system operations on the destination file will result in error.AccessDenied, including rename operations (such as the one used in this function).

Atomic.replace
pub fn replace(af: *Atomic, io: Io) ReplaceError!void

File

lib/std/Io/File/Atomic.zig:77

Code

pub fn replace(af: *Atomic, io: Io) ReplaceError!void {
    assert(af.file_exists); // Wrong value for `CreateFileAtomicOptions.replace`.
    if (af.file_open) {
        af.file.close(io);
        af.file_open = false;
    }
    const tmp_sub_path = std.fmt.hex(af.file_basename_hex);
    try af.dir.rename(&tmp_sub_path, af.dir, af.dest_sub_path, io);
    af.file_exists = false;
}