From b27aacf8207bab54f62bfe78b25d05a0a758d99d Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Thu, 17 Sep 2026 21:03:29 -0700 Subject: [PATCH] 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. --- lib/std/Build/Cache.zig | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/lib/std/Build/Cache.zig b/lib/std/Build/Cache.zig index d0a7d93e16b1207429222ee77a96361a345290e4..003c892cf3ac3be18151a5f9a6713714203b7f49 100644 --- a/lib/std/Build/Cache.zig +++ b/lib/std/Build/Cache.zig @@ -514,6 +514,11 @@ pub const Manifest = struct { pub fn path(off: File.Offset, contents: []const u8) [:0]const u8 { return pathFallible(off, contents) catch unreachable; } + + pub fn pathOrDot(off: File.Offset, contents: []const u8) [:0]const u8 { + const p = pathFallible(off, contents) catch unreachable; + return if (p.len == 0) "." else p; + } }; /// Intentionally matches if the files are different only by flags other than prefix. @@ -1176,7 +1181,7 @@ pub const Manifest = struct { const io = cache.io; const input_file = file_off.get(contents); const parent_dir = cache.prefixes()[input_file.flags.prefix].handle; - const file_path = file_off.path(contents); + const file_path = file_off.pathOrDot(contents); const gpa = cache.gpa; if (input_path.have_digest) return; @@ -1352,7 +1357,7 @@ pub const Manifest = struct { const disk_file = file_off.get(disk_contents); const input_file = file_off.get(input_contents); const parent_dir = cache.prefixes()[disk_file.flags.prefix].handle; - const file_path = file_off.path(disk_contents); + const file_path = file_off.pathOrDot(disk_contents); assert(disk_file.flags == input_file.flags); @@ -1536,7 +1541,7 @@ pub const Manifest = struct { const gpa = cache.gpa; const io = cache.io; const parent_dir = cache.prefixes()[file.flags.prefix].handle; - const file_path = file_off.path(contents); + const file_path = file_off.pathOrDot(contents); if (file.flags.metadata_only) { const actual_stat = parent_dir.statFile(io, file_path, .{}) catch |err| switch (err) { -- 2.54.0