From d1955996ce192df9e2dc4e150f204d6af53179e3 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Wed, 30 Sep 2026 17:17:29 -0300 Subject: A Restore logs and names the whole path of the dump it reads, not the name as typed `Restore x.dump.zon` read the DumpDir's x.dump.zon but logged `restore x.dump.zon`, and `~/d.zon` logged the tilde. A follower could not tell which file was restored. The builtin now resolves the name once (fs.restorePath: `~` expanded, a relative name the DumpDir's when one is there, else the current directory's) and hands that path to the host, which reads it and logs `restore `. Its messages name it too. Co-Authored-By: Claude Opus 5.5 --- src/fs.zig | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'src/fs.zig') diff --git a/src/fs.zig b/src/fs.zig index 7695d497..bc35e1cb 100644 --- a/src/fs.zig +++ b/src/fs.zig @@ -1232,6 +1232,28 @@ pub fn readRestore(gpa: std.mem.Allocator, typed: []const u8, dir_setting: []con return readRestoreIn(gpa, path, dir); } +/// The file a Restore of `typed` reads, whole: `~` expanded, a relative name +/// the DumpDir's when one is there, else the current directory's. What the +/// log and the message say, not the name as typed. `typed` itself (home +/// expanded) when nothing resolves: the read then says why. +pub fn restorePath(typed: []const u8, dir_setting: []const u8, out: *[4096]u8) []const u8 { + var home_buf: [4096]u8 = undefined; + const path = expandHome(typed, &home_buf); + if (!std.fs.path.isAbsolute(path)) { + var dir_buf: [4096]u8 = undefined; + if (@import("dump.zig").directory(&dir_buf, dir_setting)) |base| { + var buf: [4096]u8 = undefined; + if (std.fmt.bufPrint(&buf, "{s}/{s}", .{ base, path })) |candidate| { + if (resolveOs(candidate, out)) |r| if (!r.dir) return r.path; + } else |_| {} + } + } + if (resolveOs(path, out)) |r| return r.path; + const n = @min(path.len, out.len); + @memcpy(out[0..n], path[0..n]); + return out[0..n]; +} + fn readRestoreIn(gpa: std.mem.Allocator, path: []const u8, dir: ?[]const u8) ![]u8 { if (!std.fs.path.isAbsolute(path)) { if (dir) |base| { -- cgit v1.3