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);