authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2026-09-17 21:03:29-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2026-09-17 21:03:29-07:00
logb27aacf8207bab54f62bfe78b25d05a0a758d99d
tree564f0604b122c9ab548d17eeaea0a0e1ce95c48d
parent9d0fb12a8f377fea9e5496e48b5741fe7d2d1a97

std.Build.Cache: fix handling of empty sub paths

when a sub path relative to a given prefix is length zero, it needs to be treated as "." when doing actual file system operations.

1 files changed, 8 insertions(+), 3 deletions(-)

lib/std/Build/Cache.zig+8-3
......@@ -514,6 +514,11 @@ pub const Manifest = struct {
514514 pub fn path(off: File.Offset, contents: []const u8) [:0]const u8 {
515515 return pathFallible(off, contents) catch unreachable;
516516 }
517
518 pub fn pathOrDot(off: File.Offset, contents: []const u8) [:0]const u8 {
519 const p = pathFallible(off, contents) catch unreachable;
520 return if (p.len == 0) "." else p;
521 }
517522 };
518523
519524 /// Intentionally matches if the files are different only by flags other than prefix.
......@@ -1176,7 +1181,7 @@ pub const Manifest = struct {
11761181 const io = cache.io;
11771182 const input_file = file_off.get(contents);
11781183 const parent_dir = cache.prefixes()[input_file.flags.prefix].handle;
1179 const file_path = file_off.path(contents);
1184 const file_path = file_off.pathOrDot(contents);
11801185 const gpa = cache.gpa;
11811186
11821187 if (input_path.have_digest) return;
......@@ -1352,7 +1357,7 @@ pub const Manifest = struct {
13521357 const disk_file = file_off.get(disk_contents);
13531358 const input_file = file_off.get(input_contents);
13541359 const parent_dir = cache.prefixes()[disk_file.flags.prefix].handle;
1355 const file_path = file_off.path(disk_contents);
1360 const file_path = file_off.pathOrDot(disk_contents);
13561361
13571362 assert(disk_file.flags == input_file.flags);
13581363
......@@ -1536,7 +1541,7 @@ pub const Manifest = struct {
15361541 const gpa = cache.gpa;
15371542 const io = cache.io;
15381543 const parent_dir = cache.prefixes()[file.flags.prefix].handle;
1539 const file_path = file_off.path(contents);
1544 const file_path = file_off.pathOrDot(contents);
15401545
15411546 if (file.flags.metadata_only) {
15421547 const actual_stat = parent_dir.statFile(io, file_path, .{}) catch |err| switch (err) {