diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2024-07-09 23:13:03 -0700 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2024-07-12 00:14:08 -0700 |
| commit | dcbb3aa1f329ba0f12f8a039df62cd347b8f2559 (patch) | |
| tree | 6a1c67705f15a5759f40cec9948d99a50b89fc76 /lib/std/Build/Cache | |
| parent | d1c14f2f52ddec476eca6d605b985a27f4d4fe28 (diff) | |
| download | zig-dcbb3aa1f329ba0f12f8a039df62cd347b8f2559.tar.gz zig-dcbb3aa1f329ba0f12f8a039df62cd347b8f2559.zip | |
std.Build.Cache.Path: fix format function for absolute paths
Diffstat (limited to 'lib/std/Build/Cache')
| -rw-r--r-- | lib/std/Build/Cache/Path.zig | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/lib/std/Build/Cache/Path.zig b/lib/std/Build/Cache/Path.zig index 89dba6b577..f6e469c254 100644 --- a/lib/std/Build/Cache/Path.zig +++ b/lib/std/Build/Cache/Path.zig @@ -58,6 +58,20 @@ pub fn openFile( return p.root_dir.handle.openFile(joined_path, flags); } +pub fn openDir( + p: Path, + sub_path: []const u8, + args: fs.Dir.OpenOptions, +) fs.Dir.OpenError!fs.Dir { + var buf: [fs.max_path_bytes]u8 = undefined; + const joined_path = if (p.sub_path.len == 0) sub_path else p: { + break :p std.fmt.bufPrint(&buf, "{s}" ++ fs.path.sep_str ++ "{s}", .{ + p.sub_path, sub_path, + }) catch return error.NameTooLong; + }; + return p.root_dir.handle.openDir(joined_path, args); +} + pub fn makeOpenPath(p: Path, sub_path: []const u8, opts: fs.Dir.OpenOptions) !fs.Dir { var buf: [fs.max_path_bytes]u8 = undefined; const joined_path = if (p.sub_path.len == 0) sub_path else p: { @@ -137,6 +151,10 @@ pub fn format( } if (fmt_string.len > 0) std.fmt.invalidFmtError(fmt_string, self); + if (std.fs.path.isAbsolute(self.sub_path)) { + try writer.writeAll(self.sub_path); + return; + } if (self.root_dir.path) |p| { try writer.writeAll(p); try writer.writeAll(fs.path.sep_str); |
