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 {...@@ -514,6 +514,11 @@ pub const Manifest = struct {
514 pub fn path(off: File.Offset, contents: []const u8) [:0]const u8 {514 pub fn path(off: File.Offset, contents: []const u8) [:0]const u8 {
515 return pathFallible(off, contents) catch unreachable;515 return pathFallible(off, contents) catch unreachable;
516 }516 }
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 }
517 };522 };
518523
519 /// Intentionally matches if the files are different only by flags other than prefix.524 /// Intentionally matches if the files are different only by flags other than prefix.
...@@ -1176,7 +1181,7 @@ pub const Manifest = struct {...@@ -1176,7 +1181,7 @@ pub const Manifest = struct {
1176 const io = cache.io;1181 const io = cache.io;
1177 const input_file = file_off.get(contents);1182 const input_file = file_off.get(contents);
1178 const parent_dir = cache.prefixes()[input_file.flags.prefix].handle;1183 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);
1180 const gpa = cache.gpa;1185 const gpa = cache.gpa;
11811186
1182 if (input_path.have_digest) return;1187 if (input_path.have_digest) return;
...@@ -1352,7 +1357,7 @@ pub const Manifest = struct {...@@ -1352,7 +1357,7 @@ pub const Manifest = struct {
1352 const disk_file = file_off.get(disk_contents);1357 const disk_file = file_off.get(disk_contents);
1353 const input_file = file_off.get(input_contents);1358 const input_file = file_off.get(input_contents);
1354 const parent_dir = cache.prefixes()[disk_file.flags.prefix].handle;1359 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
1357 assert(disk_file.flags == input_file.flags);1362 assert(disk_file.flags == input_file.flags);
13581363
...@@ -1536,7 +1541,7 @@ pub const Manifest = struct {...@@ -1536,7 +1541,7 @@ pub const Manifest = struct {
1536 const gpa = cache.gpa;1541 const gpa = cache.gpa;
1537 const io = cache.io;1542 const io = cache.io;
1538 const parent_dir = cache.prefixes()[file.flags.prefix].handle;1543 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
1541 if (file.flags.metadata_only) {1546 if (file.flags.metadata_only) {
1542 const actual_stat = parent_dir.statFile(io, file_path, .{}) catch |err| switch (err) {1547 const actual_stat = parent_dir.statFile(io, file_path, .{}) catch |err| switch (err) {