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.

renameTmpIntoCache

Fetch.renameTmpIntoCache
pub fn renameTmpIntoCache(io: Io, tmp_path: Path, dest_path: Path) !void

File

lib/compiler/Maker/Fetch.zig:1668

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 => {
                // Package has been already downloaded and may already be in use on the system.
                tmp_path.root_dir.handle.deleteTree(io, tmp_path.sub_path) catch |er| switch (er) {
                    error.Canceled => |e| return e,
                    // Garbage files leftover in zig-cache/tmp/ is, as they say
                    // 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;
    }
}