From 261eb7ac3f090c8ce47ad47c0f58f824a9b162a6 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Tue, 29 Sep 2026 11:43:08 -0300 Subject: A Dump into a DumpDir that is no directory says so; the doc says a missing last directory is made DumpDir /dev/null said no such directory though it is there, and the doc claimed a missing DumpDir always fails, where its last component is made at the Dump. Co-Authored-By: Claude Opus 5.5 --- docs/fs.md | 6 ++++-- src/exec.zig | 12 +++++++++--- src/ninep/ctl.zig | 4 ++++ src/pardes.zig | 12 ++++++++---- 4 files changed, 25 insertions(+), 9 deletions(-) diff --git a/docs/fs.md b/docs/fs.md index b588b1f1..e13af3c2 100644 --- a/docs/fs.md +++ b/docs/fs.md @@ -254,8 +254,10 @@ takes (`Verbose on`, `WindowOpacity 70`, `PanelSlide off`, `DumpDir back changes nothing; a setting the frontend cannot show (`Lift`, `GripWidth` on a terminal) is refused as `Lift is GUI-only, invalid here` (EINVAL: a request this build cannot take); a `Shell` or `Tty` naming no -shell says `no shell "x", not found` (ENOENT); a Dump into a `DumpDir` -that is not there says `Dump : no such directory` (ENOENT); platform and startup facts are `/status`'s and the +shell says `no shell "x", not found` (ENOENT); a `DumpDir` whose last +directory is missing has it made at the Dump, and one further up missing +says `Dump : no such directory` (ENOENT), one that is no directory +(`/dev/null`) `Dump : /dev/null is not a directory`; platform and startup facts are `/status`'s and the Config window's, not settings. A pane's `ctl` takes the builtins that act on a pane (`Del`, or `Del k`/`Del j` to give its rows to the pane above or below, `Save f`, `Collapse`, which folds that pane, `Undo` and diff --git a/src/exec.zig b/src/exec.zig index fdb9bdb7..683b2f04 100644 --- a/src/exec.zig +++ b/src/exec.zig @@ -397,12 +397,18 @@ pub fn isDirectory(path: []const u8) bool { /// Whether `path` is a plain file on this host, the turn out while it asks. pub fn isFile(path: []const u8) bool { + return kindOf(path) == .file; +} + +/// What `path` is on this host, null when it is not there; the turn out +/// while it asks. +pub fn kindOf(path: []const u8) ?std.Io.File.Kind { var buf: [4096]u8 = undefined; - const z = std.fmt.bufPrintSentinel(&buf, "{s}", .{path}, 0) catch return false; + const z = std.fmt.bufPrintSentinel(&buf, "{s}", .{path}, 0) catch return null; pardes.turn.yield(); defer pardes.turn.back(); - const stat = std.Io.Dir.cwd().statFile(std.Io.Threaded.global_single_threaded.io(), z, .{}) catch return false; - return stat.kind == .file; + const stat = std.Io.Dir.cwd().statFile(std.Io.Threaded.global_single_threaded.io(), z, .{}) catch return null; + return stat.kind; } /// With `BootShell replace`, a doc landing in `col` closes a lone pristine diff --git a/src/ninep/ctl.zig b/src/ninep/ctl.zig index dc2d9a84..ea0a0bc6 100644 --- a/src/ninep/ctl.zig +++ b/src/ninep/ctl.zig @@ -1667,6 +1667,10 @@ test "a Restore of a file that is no dump fails the write before any warning, an p.fs.late_failure_len = 0; p.dumpFailed("/nowhere/pardes.dump.zon", error.FileNotFound); try testing.expectEqualStrings("Dump /nowhere/pardes.dump.zon: no such directory", p.fs.late_failure[0..p.fs.late_failure_len]); + // A DumpDir that is there but no directory says that. + p.fs.late_failure_len = 0; + p.dumpFailed("/dev/null/pardes.dump.zon", error.NotDir); + try testing.expectEqualStrings("Dump /dev/null/pardes.dump.zon: /dev/null is not a directory", p.fs.late_failure[0..p.fs.late_failure_len]); } test "a setting this frontend cannot show says GUI-only, and DumpDir reads back the directory in effect" { diff --git a/src/pardes.zig b/src/pardes.zig index 2bf594c4..f6032ac5 100644 --- a/src/pardes.zig +++ b/src/pardes.zig @@ -5425,11 +5425,15 @@ pub const Pardes = struct { pub fn dumpFailed(p: *Pardes, path: []const u8, err: anyerror) void { var what: [limits.host_path_cap + 8]u8 = undefined; const operation = std.fmt.bufPrint(&what, "Dump {s}", .{path}) catch "Dump"; - // Into a DumpDir that is not there: said so, ENOENT, as a Save is. + // Into a DumpDir that is not there: said so, ENOENT, as a Save is; + // one that is there but no directory (`/dev/null`) says that. const parent = std.fs.path.dirname(path) orelse "/"; - const no_dir = err == error.FileNotFound or err == error.NotDir or - (if (comptime hosted) (if (filesystem.localPath(parent)) |local| !exec.isDirectory(local) else false) else false); - if (no_dir) { + const kind: ?std.Io.File.Kind = if (comptime hosted) (if (filesystem.localPath(parent)) |local| exec.kindOf(local) else .directory) else .directory; + const no_dir = err == error.FileNotFound or err == error.NotDir or kind != .directory; + if (kind != null and kind != .directory) { + var said: [limits.host_path_cap + 48]u8 = undefined; + p.reportFailure(p.active, std.fmt.bufPrint(&said, "{s}: {s} is not a directory", .{ operation, parent }) catch "Dump: not a directory"); + } else if (no_dir) { var said: [limits.host_path_cap + 48]u8 = undefined; p.reportFailure(p.active, std.fmt.bufPrint(&said, "{s}: no such directory", .{operation}) catch "Dump: no such directory"); } else p.reportError(p.active, operation, err); -- cgit v1.3