From 2f187232227dde2755a7f2f2ce717f3e1f685f5c Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Tue, 29 Sep 2026 11:40:03 -0300 Subject: Recent keeps only files on disk, and its cap never drops an open one A renamed scratch never saved and a /virtual/ pane were recorded as recent files, and at 200 the oldest entry went even when that file was open. Opens, renames and closes now record a path only when it is a file on this host, and the cap drops the oldest closed entry. A name with a newline is not written to the kept list, where it would read back as two. Co-Authored-By: Claude Opus 5.5 --- src/ninep/ctl.zig | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'src/ninep/ctl.zig') diff --git a/src/ninep/ctl.zig b/src/ninep/ctl.zig index f4a3d730..dc2d9a84 100644 --- a/src/ninep/ctl.zig +++ b/src/ninep/ctl.zig @@ -2304,6 +2304,30 @@ test "Back and Forward over a closed file's entries: one reopen is that file's p try testing.expectEqual(c_serial, p.panes[p.active].?.serial); } +test "Recent keeps only files on disk: not a name never saved, nor the served tree's" { + const p = try withFile(testing.allocator, "x\n"); + defer p.deinit(); + var tmp = testing.tmpDir(.{}); + defer tmp.cleanup(); + try tmp.dir.writeFile(testing.io, .{ .sub_path = "real.txt", .data = "real\n" }); + var dir_buf: [4096]u8 = undefined; + const dir = dir_buf[0..try tmp.dir.realPath(testing.io, &dir_buf)]; + var line: [4200]u8 = undefined; + const names = [_][]const u8{ try std.fmt.allocPrint(testing.allocator, "{s}/c", .{dir}), try testing.allocator.dupe(u8, "/virtual/zz"), try std.fmt.allocPrint(testing.allocator, "{s}/real.txt", .{dir}) }; + defer for (names) |n| testing.allocator.free(n); + for (names) |name| { + const made = try th.newPane(p); + _ = wr(p, Node.of(made, .name), try std.fmt.bufPrint(&line, "{s}\n", .{name})); + p.sync(); + _ = wr(p, Node.of(made, .ctl), "Del\n"); + _ = wr(p, Node.of(made, .ctl), "Del\n"); + p.sync(); + } + try testing.expect(p.recent.get(names[0]) == null); + try testing.expect(p.recent.get(names[1]) == null); + try testing.expect(p.recent.get(names[2]) != null); +} + test "/recent shows a name as /index does, a newline in it escaped" { const p = try withFile(testing.allocator, "x\n"); defer p.deinit(); -- cgit v1.3