summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Output.zig5
-rw-r--r--src/ninep/ctl.zig16
2 files changed, 20 insertions, 1 deletions
diff --git a/src/Output.zig b/src/Output.zig
index 4aa0c021..1160c455 100644
--- a/src/Output.zig
+++ b/src/Output.zig
@@ -656,7 +656,10 @@ pub fn openUnsaved(p: *Pardes, id: usize, content: []u8) void {
return;
}
const pane = p.panes[id] orelse return p.gpa.free(content);
- const dir = if (pane.file) |f| (std.fs.path.dirname(f.path) orelse "/") else pane.cwdSlice();
+ const own = if (pane.file) |f| (std.fs.path.dirname(f.path) orelse "/") else pane.cwdSlice();
+ // Its directory gone (or never there, a name not yet saved): the list
+ // goes in the session's, where a look from it can still resolve.
+ const dir = if (comptime pardes.hosted) (if (pardes.filesystem.localPath(own)) |local| (if (exec.isDirectory(local)) own else p.sessionDir()) else own) else own;
const free = p.freeSlot() orelse return p.gpa.free(content);
_ = open(p, free, dir, .unsaved, "", content) catch return;
exec.placeNew(p, id, id, free, .doc);
diff --git a/src/ninep/ctl.zig b/src/ninep/ctl.zig
index f8391672..e0c4b21b 100644
--- a/src/ninep/ctl.zig
+++ b/src/ninep/ctl.zig
@@ -1777,6 +1777,22 @@ test "exec Save writes the named file through the host" {
try testing.expectEqualStrings(pane.file.?.content, p.fallback.get("/tmp/renamed.txt").?);
}
+test "a refusal's +Unsaved goes in the session's directory when the active pane's directory is not there" {
+ if (comptime !pardes.hosted) return;
+ const p = try withFile(testing.allocator, "x\n");
+ defer p.deinit();
+ const serial = serialOf(p);
+ try testing.expectEqual(Status.ok, wr(p, Node.of(serial, .name), "/tmp/pardes-no-such-dir-zz/x.txt\n").reply.status);
+ try testing.expectEqual(Status.ok, wr(p, Node.of(serial, .body), "edited\n").reply.status);
+ try testing.expectEqual(Status.err, wr(p, @intFromEnum(tree.TopFile.ctl), "Exit\n").reply.status);
+ const unsaved = for (p.panes) |slot| {
+ const pane = slot orelse continue;
+ const f = pane.file orelse continue;
+ if (f.output) |o| if (o.from == .unsaved) break f.path;
+ } else return error.NoUnsavedPane;
+ try testing.expectEqualStrings(p.sessionDir(), std.fs.path.dirname(unsaved).?);
+}
+
test "a look at a file it may not read fails the write naming the file" {
if (comptime !pardes.hosted) return;
const p = try withFile(testing.allocator, "x\n");