diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-05 14:11:56 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-05 19:16:19 -0300 |
| commit | 4e096f6dc6db043caa630514fa75bd18438cb15b (patch) | |
| tree | 2628101ed3a7e432030918b019935e47240b1c64 /src/dump.zig | |
| parent | 38d21b0cb34ef1f555e5bda8155150bda9bfbaee (diff) | |
| download | pardes-4e096f6dc6db043caa630514fa75bd18438cb15b.tar.gz pardes-4e096f6dc6db043caa630514fa75bd18438cb15b.zip | |
store: Recent is a value of the user's state file, `pardes.xitdb` in the DumpDir (src/Db.zig: the xitdb database the architecture's §14 puts everything pardes keeps on disk in), which every session shares: read at a session's start (now after the startup config, whose DumpDir says where the file is) and again on use when the file's committed size has moved, written at the end of a step that changed it in one transaction under the file's lock, taken without waiting (busy, the next step tries again), another session's commit read and merged under this one's changes first; not fsynced, as the `recent` file was not (a xitdb commit costs 20 us without fsync and 5.2 ms with its two on this btrfs); a file there that is no database of pardes's is kept aside as `pardes.xitdb.broken` and a new one started; Store.zig keeps the closed panes alone (its file half goes: the path and its inode/size/mtime stamp, load, refresh, read, flush and write, and W4's one-time read of the old `store`, which comes back with the migration), Options.recent_path becomes Options.state (off, disk, memory), main.recentPath goes, a Restore's new core takes the old one's database, and the test host's sessions keep theirs in a `.memory` database, the same code; measured (Debug, 200 files listed): flush after an open 133-135 us (W4's file: 124), refresh after another session's write 239-247 us (198), refresh with nothing new 3 us (1), a session started on it 1144-1194 us (1214), and a Recent change adds 12,325 bytes to the file (its 12,089 bytes of lines and 236 of xitdb's); tests: Store.zig's four Recent tests become Db.zig's three (two windows sharing Recent through a busy lock, the newest 200, a file that is no database kept aside; the old store's migration test goes with that read), the closed-pane test keeps its second window on a state file in its DumpDir, the behaviour suite gains 'two sessions on one state file share Recent', and the process tests and the canary look for the state file where they looked for `recent`
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge
Diffstat (limited to 'src/dump.zig')
| -rw-r--r-- | src/dump.zig | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/src/dump.zig b/src/dump.zig index 1b3bcb5c..3ded45ca 100644 --- a/src/dump.zig +++ b/src/dump.zig @@ -385,7 +385,7 @@ pub fn upgradePath(buf: *[1024:0]u8, dir_setting: []const u8) ?[:0]const u8 { return std.fmt.bufPrintSentinel(buf, "{s}/pardes-upgrade-{d}.dump", .{ dir, std.c.getpid() }, 0) catch null; } -fn loadAndRevive(gpa: std.mem.Allocator, opts: Options, bytes: []const u8, previous: ?*const Pardes, kept: ?*const [MAX_PANES]bool) !*Pardes { +fn loadAndRevive(gpa: std.mem.Allocator, opts: Options, bytes: []const u8, previous: ?*Pardes, kept: ?*const [MAX_PANES]bool) !*Pardes { var notes: std.ArrayList(u8) = .empty; defer notes.deinit(gpa); var on_disk: OnDisk = @splat(false); @@ -408,9 +408,10 @@ fn loadAndRevive(gpa: std.mem.Allocator, opts: Options, bytes: []const u8, previ /// A loaded core given to this host (with `revivePane` for each of its /// panes): the store and Recent read (a Restore's carried from the session -/// it replaces) and its ThemeFile asked for again. An upgrade's (`resumed`) -/// keeps its views, whose clients come back with it, and its settings. -fn reviveSession(p: *Pardes, previous: ?*const Pardes, resumed: bool) !void { +/// it replaces, with its state file) and its ThemeFile asked for again. An +/// upgrade's (`resumed`) keeps its views, whose clients come back with it, +/// and its settings. +fn reviveSession(p: *Pardes, previous: ?*Pardes, resumed: bool) !void { // ponytail: one client loads it, so it is one view, the live one's; a // replica joining (phase 5) takes `load`'s, every view. if (!resumed) views.only(p); @@ -424,9 +425,13 @@ fn reviveSession(p: *Pardes, previous: ?*const Pardes, resumed: bool) !void { p.cell_pixels = old.cell_pixels; p.row_metrics = old.row_metrics; p.native_images = old.native_images; + // Its panes close here, each noted where it was, as at its end. + for (old.panes) |slot| if (slot) |pane| old.noteClosed(pane); p.recent = old.recent.clone(p.recentGpa()); p.store = old.store.clone(p.recentGpa()); - } else p.loadRecent(); + p.db = old.db; + old.db = .{}; + } config.tab_now = p.settings.tab; // A ThemeFile is a request the host answers by reading the file again; // until it has (and for good if it fails) the theme the dump had shows. @@ -443,6 +448,8 @@ fn reviveSession(p: *Pardes, previous: ?*const Pardes, resumed: bool) !void { // reflows would lose where a terminal's view was. p.sync(); if (!resumed) exec.applyStartupConfig(p); + // After the startup config, whose DumpDir says where the state file is. + if (previous == null) p.loadRecent(); colors.finishThemeInitialization(p); p.sync(); _ = p.takeHaptic(); // see init: a restored session is not a gesture |
