From 951d95c623350075a0b4142f8bc862a05bfb89df Mon Sep 17 00:00:00 2001 From: Rohit Goswami Date: Mon, 16 Nov 2026 09:21:21 +0000 Subject: [PATCH] test(keep): the copy test makes the .zig-cache it writes into The unit test of a failed copy made its scratch directory in .zig-cache under the directory it runs in, with a mkdirat whose result it dropped. zig build runs a test in the directory zig build was started in, and that directory has no .zig-cache when the cache is elsewhere. zig-common's CI builds this repository from $GITHUB_WORKSPACE/tool while setup-zig sets ZIG_LOCAL_CACHE_DIR to $GITHUB_WORKSPACE/.zig-cache: the mkdirat failed with ENOENT and the test failed at fsx.openDir with NotFound, with zig-common 0.8.1 as with its main. `zig build test` started in src/ fails the same way. This repository's CI passed only because its checkout is $GITHUB_WORKSPACE, where the cache is. The test now makes the directory with atomic.makedirs, parents and all, as eb-local's tests do, stops on any other error, and removes the directory even when it cannot open it. --- changelog.d/+scratch-dir.misc.md | 1 + src/main.zig | 11 +++++------ 2 files changed, 6 insertions(+), 6 deletions(-) create mode 100644 changelog.d/+scratch-dir.misc.md diff --git a/changelog.d/+scratch-dir.misc.md b/changelog.d/+scratch-dir.misc.md new file mode 100644 index 0000000..f4110c5 --- /dev/null +++ b/changelog.d/+scratch-dir.misc.md @@ -0,0 +1 @@ +`zig build test` passes when the directory it runs in has no `.zig-cache`, as when `ZIG_LOCAL_CACHE_DIR` puts the cache elsewhere: the unit test of a failed copy makes its scratch directory with its parents instead of failing with `NotFound`. diff --git a/src/main.zig b/src/main.zig index d72faac..d89b59b 100644 --- a/src/main.zig +++ b/src/main.zig @@ -681,13 +681,12 @@ test "a failed copy does not replace a log already kept" { const here = try fsx.realpath(fsx.cwd, ".", &cwd_buf); const base = try std.fmt.allocPrint(gpa, "{s}/.zig-cache/eb-keep-logs-copy-{d}", .{ here, linux.getpid() }); defer gpa.free(base); - var zb: [sys.path_max:0]u8 = undefined; - _ = linux.mkdirat(fsx.cwd, (try sys.z(&zb, base)).ptr, 0o700); + // The test runs where `zig build` was started, which has no .zig-cache + // when the cache is elsewhere, as with ZIG_LOCAL_CACHE_DIR. + try common.atomic.makedirs(base); + defer fsx.deleteTree(gpa, fsx.cwd, base) catch {}; const dir = try fsx.openDir(fsx.cwd, base, false); - defer { - fsx.deleteTree(gpa, fsx.cwd, base) catch {}; - sys.close(dir); - } + defer sys.close(dir); const dst = try sys.openat(dir, "kept.log", .{ .ACCMODE = .WRONLY, .CREAT = true }, 0o640); try sys.writeAll(dst, "OLDDATA\n"); sys.close(dst);