Returns the sub_path that worked, or null if none did.
The path of the returned Directory is relative to base.
The handle of the returned Directory is open.
fn testZigInstallPrefix(io: Io, base_dir: Dir) ?Cache.Directory
fn testZigInstallPrefix(io: Io, base_dir: Dir) ?Cache.Directory {
const test_index_file = "std" ++ Dir.path.sep_str ++ "std.zig";
zig_dir: {
// Try lib/zig/std/std.zig
const lib_zig = "lib" ++ Dir.path.sep_str ++ "zig";
var test_zig_dir = base_dir.openDir(io, lib_zig, .{}) catch break :zig_dir;
const file = test_zig_dir.openFile(io, test_index_file, .{}) catch {
test_zig_dir.close(io);
break :zig_dir;
};
file.close(io);
return .{ .handle = test_zig_dir, .path = lib_zig };
}
// Try lib/std/std.zig
var test_zig_dir = base_dir.openDir(io, "lib", .{}) catch return null;
const file = test_zig_dir.openFile(io, test_index_file, .{}) catch {
test_zig_dir.close(io);
return null;
};
file.close(io);
return .{ .handle = test_zig_dir, .path = "lib" };
}