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 ++++++++++++++++++++++++ src/ninep/events.zig | 2 +- src/ninep/pane.zig | 2 +- 3 files changed, 26 insertions(+), 2 deletions(-) (limited to 'src/ninep') 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(); diff --git a/src/ninep/events.zig b/src/ninep/events.zig index 2fe25071..add0d750 100644 --- a/src/ninep/events.zig +++ b/src/ninep/events.zig @@ -141,7 +141,7 @@ pub fn announce(p: *Pardes) void { pane.fs.unannounced = false; noteLog(p, .new, pane); // A file opened (a look, a Restore, a boot): first in Recent. - if (pane.file) |f| if (f.output == null) p.recent.opened(p.recentGpa(), f.path); + if (pane.file) |f| if (f.output == null and pardes.Pardes.recentKeeps(f.path)) p.recent.opened(p.recentGpa(), f.path); } } diff --git a/src/ninep/pane.zig b/src/ninep/pane.zig index 0b6f04a4..5ed3f6f4 100644 --- a/src/ninep/pane.zig +++ b/src/ninep/pane.zig @@ -687,7 +687,7 @@ pub fn nameBuffer(p: *Pardes, id: usize, full: []const u8, preserve_tag: bool) ! look.invalidateLookHover(p, id); p.emit(.{ .watch = .{ .pane = @intCast(id), .on = false } }); events.noteLog(p, .rename, pane); - if (f.output == null) p.recent.opened(p.recentGpa(), f.path); + if (f.output == null and pardes.Pardes.recentKeeps(f.path)) p.recent.opened(p.recentGpa(), f.path); } /// Diagnostics go to the +Errors buffer of the pane's directory. -- cgit v1.3