pub fn link(af: *Atomic, io: Io) LinkError!void 48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63pub 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;
}
}
Atomically materializes the file into place, failing with
error.PathAlreadyExistsif 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.