feature. See also
. The project being documented here (as the example) is the Zig library itself.
Fetch.renameTmpIntoCache
pub fn renameTmpIntoCache(io: Io, tmp_path: Path, dest_path: Path) !void
File
Code
pub fn renameTmpIntoCache(io: Io, tmp_path: Path, dest_path: Path) !void {
var handled_missing_dir = false;
while (true) {
Io.Dir.rename(
tmp_path.root_dir.handle,
tmp_path.sub_path,
dest_path.root_dir.handle,
dest_path.sub_path,
io,
) catch |err| switch (err) {
error.FileNotFound => {
if (handled_missing_dir) return err;
const parent_sub_path = Io.Dir.path.dirname(dest_path.sub_path).?;
dest_path.root_dir.handle.createDir(io, parent_sub_path, .default_dir) catch |er| switch (er) {
error.PathAlreadyExists => handled_missing_dir = true,
else => |e| return e,
};
continue;
},
error.DirNotEmpty, error.AccessDenied => {
tmp_path.root_dir.handle.deleteTree(io, tmp_path.sub_path) catch |er| switch (er) {
error.Canceled => |e| return e,
// on Star Trek, "operating within normal parameters".
else => |e| log.warn("failed to delete temporary directory {f}: {t}", .{ tmp_path, e }),
};
},
else => |e| return e,
};
break;
}
}