From 24729dbbf8b32966a3f33c9bc20599b185856dd3 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Tue, 29 Sep 2026 05:29:45 -0300 Subject: get and a deleted file say what happened: the path, changed deleted, reloaded get on a file gone from disk failed with a bare ENOENT; it now says get: : no such file. A watched file deleted on disk was silent; the pane keeps its text and says deleted on disk (Save writes it again) once, logged changed deleted (only a path the watch has read: a pane renamed to a name never on disk is not deleted). A get that throws a dirty buffer's state away logs changed reloaded, as the watch's reload does. Co-Authored-By: Claude Opus 5.5 --- src/File.zig | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'src/File.zig') diff --git a/src/File.zig b/src/File.zig index 17399d8b..5f6d7097 100644 --- a/src/File.zig +++ b/src/File.zig @@ -64,6 +64,9 @@ pub const State = struct { /// Put does (exec.c:577, "modified since last read"). disk_newer: ?u64 = null, disk_newer_warned: bool = false, + /// Its file was deleted on disk: said once (`deleted`) until it is + /// written or found again. + disk_gone: bool = false, /// Seconds of the last content change, for the filesystem's stat; zero until edited. mtime: u32 = 0, /// Non-null for a generated output buffer rather than an on-disk file. @@ -970,6 +973,20 @@ pub fn redo(p: *Pardes, pane: *Pane) void { restoreSnap(pane, f, next); } +/// A pane's file deleted on disk: the text stays, and it says so once, +/// ` deleted on disk (Save writes it again)`, logged `changed +/// deleted`. +pub fn deleted(p: *Pardes, id: u8) void { + const pane = p.panes[id] orelse return; + const f = if (pane.file) |*file| file else return; + if (f.disk_gone) return; + f.disk_gone = true; + var said: [limits.host_path_cap + 64]u8 = undefined; + p.setMessage(id, std.fmt.bufPrint(&said, "{s} deleted on disk (Save writes it again)", .{f.path}) catch "deleted on disk (Save writes it again)"); + var rec: [32]u8 = undefined; + pardes.ctlfs.events.notePath(p, "changed", std.fmt.bufPrint(&rec, "{d} deleted", .{pane.serial}) catch ""); +} + /// A file rewritten on disk. A clean buffer takes the new text, committed /// onto the same undo history as typed edits. A buffer with unsaved edits /// is never reloaded under them: it keeps its text and stays dirty, and @@ -981,6 +998,7 @@ pub fn redo(p: *Pardes, pane: *Pane) void { pub fn changed(p: *Pardes, id: u8, bytes: []const u8) void { const pane = p.panes[id] orelse return; const f = if (pane.file) |*file| file else return; + f.disk_gone = false; if (std.mem.eql(u8, f.content, bytes)) return; if (f.saved_hash) |saved| if (f.revision != f.saved_revision and std.hash.Wyhash.hash(0, f.content) != saved) { const disk = std.hash.Wyhash.hash(0, bytes); -- cgit v1.3