pub fn openUnresolved(
arena: Allocator,
io: Io,
cwd: []const u8,
unresolved_path: []const u8,
thing: enum { @"zig lib", @"global cache", @"local cache", @"build root" },
) Cache.Directory {
const path = resolvePath(arena, cwd, &.{unresolved_path}) catch |err| {
fatal("unable to resolve {t} directory: {t}", .{ thing, err });
};
const nonempty_path = if (path.len == 0) "." else path;
const handle_or_err = switch (thing) {
.@"zig lib", .@"build root" => Dir.cwd().openDir(io, nonempty_path, .{}),
.@"global cache", .@"local cache" => Dir.cwd().createDirPathOpen(io, nonempty_path, .{}),
};
return .{
.path = if (path.len == 0) null else path,
.handle = handle_or_err catch |err| {
const extra_str: []const u8 = e: {
if (thing == .@"global cache") switch (err) {
error.AccessDenied, error.ReadOnlyFileSystem => break :e "\n" ++
"If this location is not writable then consider specifying an alternative with " ++
"the ZIG_GLOBAL_CACHE_DIR environment variable or the --global-cache-dir option.",
else => {},
};
break :e "";
};
fatal("unable to open {t} directory {q}: {t}{s}", .{ thing, nonempty_path, err, extra_str });
},
};
}