From 2348776791e9dd17afeb12a06ba42a4a71917bcf Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Fri, 30 Oct 2026 21:34:41 -0300 Subject: sketchbook: a drawing layer on top, host fixes for replay and migration --- src/host/root.zig | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'src/host/root.zig') diff --git a/src/host/root.zig b/src/host/root.zig index 2876c0f..8cc15e1 100644 --- a/src/host/root.zig +++ b/src/host/root.zig @@ -59,6 +59,22 @@ pub fn main(init: std.process.Init, linked: ?abi.Sketch) !void { } if (linked == null and options.library == null) fatal("no sketch library given (see --help)"); + // A scripted run from fresh state works on files of its own, moved to + // the given path at exit: two runs of one build step (two `zig build`s + // at once share its output path) never share a state, store or + // recordings file, nor fail on the store's lock. + var private_buf: [std.fs.max_path_bytes]u8 = undefined; + const given = options.state; + const private = script_path != null and options.fresh; + if (private) options.state = std.mem.print(&private_buf, "{s}.{d}", .{ given, std.os.linux.getpid() }) catch fatal("--state path too long"); + defer if (private) for ([_][]const u8{ "", ".inputs", ".store" }) |suffix| { + var from: [std.fs.max_path_bytes + 16]u8 = undefined; + var to: [std.fs.max_path_bytes + 16]u8 = undefined; + const a = std.mem.printSentinel(&from, "{s}{s}", .{ options.state, suffix }, 0) catch continue; + const b = std.mem.printSentinel(&to, "{s}{s}", .{ given, suffix }, 0) catch continue; + _ = std.os.linux.rename(a.ptr, b.ptr); + }; + sdl_heap.install(); { var host: Host = undefined; -- cgit v1.3