diff options
| author | Gabriel Schneider <[email protected]> | 2026-10-29 22:56:07 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-10-29 23:37:00 -0300 |
| commit | 370913ae34c69b7958911c6146612c77275f6ebf (patch) | |
| tree | 61e4fd328e104afbb381d2fd161029d1be637aa7 /src/upgrade.zig | |
| parent | ddcfd860ef05c37f5536038d8828cc81c0c4125c (diff) | |
| download | pardes-370913ae34c69b7958911c6146612c77275f6ebf.tar.gz pardes-370913ae34c69b7958911c6146612c77275f6ebf.zip | |
upgrade: a newer build at the path a session started from is said at a focus-in, once a build, the path read just after the first frame (off a startup's way); an upgraded process lets the binary it replaced go (held, its deleted file kept its blocks) and sweeps its old image's prompt files (kept for an exec that failed); test/daemon.py --upgrade asks through /ctl, checks the fds and prompt files level, and runs on FreeBSD (procstat, the daemon's registry, no kept old binary there)
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Diffstat (limited to 'src/upgrade.zig')
| -rw-r--r-- | src/upgrade.zig | 50 |
1 files changed, 43 insertions, 7 deletions
diff --git a/src/upgrade.zig b/src/upgrade.zig index c49d2370..49e8aff5 100644 --- a/src/upgrade.zig +++ b/src/upgrade.zig @@ -32,21 +32,53 @@ var exe_buf: [4096:0]u8 = undefined; var exe_len: usize = 0; /// The arguments it was started with (an upgrade's record left out). var given: []const [:0]const u8 = &.{}; +/// The file at that path when it started, and the newer one last said. +var started_inode: ?u64 = null; +var told_inode: ?u64 = null; -/// Its path asked of the system now, at its start (one readlink), and its -/// arguments kept; an upgraded process takes the path its record names -/// (the system would name a fallback's old binary, deleted). +var located = false; + +/// Its arguments kept, at its start; an upgraded process's path is the one +/// its record names (the system would name a fallback's old binary, +/// deleted). pub fn remember(args: []const [:0]const u8) void { given = if (args.len > 1 and std.mem.startsWith(u8, args[1], flag)) args[2..] else if (args.len > 0) args[1..] else &.{}; if (resumed) |*rec| if (rec.exe.len > 0 and rec.exe.len < exe_buf.len) { @memcpy(exe_buf[0..rec.exe.len], rec.exe); exe_buf[rec.exe.len] = 0; exe_len = rec.exe.len; - return; }; - const n = std.process.executablePath(std.Io.Threaded.global_single_threaded.io(), &exe_buf) catch 0; - exe_buf[n] = 0; - exe_len = n; +} + +/// Its path asked of the system (a readlink) and the file there now (a +/// stat), once: after the first frame, off a startup's way (the hosts' +/// loops; nothing is reinstalled within a frame of a start). +pub fn locate() void { + if (located) return; + located = true; + if (exe_len == 0) { + const n = std.process.executablePath(std.Io.Threaded.global_single_threaded.io(), &exe_buf) catch 0; + exe_buf[n] = 0; + exe_len = n; + } + if (exe()) |path| started_inode = inodeOf(path); +} + +fn inodeOf(path: [:0]const u8) ?u64 { + const st = std.Io.Dir.cwd().statFile(std.Io.Threaded.global_single_threaded.io(), path, .{}) catch return null; + return @intCast(st.inode); +} + +/// A newer build installed at that path since this process started, said +/// in a line, once a build: asked at a focus-in, where one comes back from +/// rebuilding (a stat). ponytail: explicit only, no watch and no automatic +/// upgrade. +pub fn noticeNewer(core: *pardes.Pardes) void { + const was = started_inode orelse return; + const now = inodeOf(exe() orelse return) orelse return; + if (now == was or told_inode == now) return; + told_inode = now; + core.setMessage(core.active, "a newer pardes is installed: Upgrade (SPC s U) moves this session onto it"); } pub fn exe() ?[:0]const u8 { @@ -336,6 +368,10 @@ pub fn load(gpa: std.mem.Allocator, core_gpa: std.mem.Allocator, opts: pardes.Op var buf: [700]u8 = undefined; if (loaded) |p| { _ = libc.unlink(path); + // The binary it replaced, let go: held, its file (deleted) would + // keep its blocks for as long as this session runs. + if (rec.old >= 0) _ = libc.close(rec.old); + rec.old = -1; p.setMessage(p.active, if (rec.refused.len > 0) std.fmt.bufPrint(&buf, "Upgrade: the new build could not load this session ({s}); it goes on as {s}", .{ rec.refused[0..@min(rec.refused.len, 200)], version_line }) catch "Upgrade: the new build could not load this session; it goes on as before" else |
