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.

link

Atomically materializes the file into place, failing with error.PathAlreadyExists if something already exists there.

If this operation could not be done with an unnamed temporary file, the named temporary file will be deleted in a following operation, which may independently fail. The result of that operation is stored in delete_err.

Atomic.link
pub fn link(af: *Atomic, io: Io) LinkError!void

File

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

Code

pub fn link(af: *Atomic, io: Io) LinkError!void {
    if (af.file_exists) {
        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.renamePreserve(&tmp_sub_path, af.dir, af.dest_sub_path, io);
        af.file_exists = false;
    } else {
        assert(af.file_open);
        try af.file.hardLink(io, af.dir, af.dest_sub_path, .{});
        af.file.close(io);
        af.file_open = false;
    }
}