diff options
| author | Gabriel Schneider <[email protected]> | 2026-09-30 14:02:59 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-10-01 00:12:17 -0300 |
| commit | b43866d6ab784e518df8dbef374147367358ada9 (patch) | |
| tree | b49ffadf36cac764cb3fb6f4d343fa25d09dab73 /src/pardes.zig | |
| parent | 9ca008a27c4ab83a29c1798f4eb081eef372624c (diff) | |
| download | pardes-b43866d6ab784e518df8dbef374147367358ada9.tar.gz pardes-b43866d6ab784e518df8dbef374147367358ada9.zip | |
Save makes the directories its file goes in, always: for the pane's own name and Save path alike
Whether a Save made missing directories depended on how the name had
come about. Config's pane did, a name written into a missing directory did
(since kkrqxtsp), and `Save path` and every other name did not, failing
ENOENT instead. There is now one rule: a Save makes the parent
directories of the file it writes, a pane's own or a terminal's
scrollback included, and the make_dirs flag is gone. A directory it
cannot make still fails the write with why, as fs.py's
/nonexistent-pardes-dir case shows. fs.py now also saves into missing
directories by Save path and by a written name.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Diffstat (limited to 'src/pardes.zig')
| -rw-r--r-- | src/pardes.zig | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/src/pardes.zig b/src/pardes.zig index d8124588..841faf7a 100644 --- a/src/pardes.zig +++ b/src/pardes.zig @@ -5401,6 +5401,15 @@ pub const Pardes = struct { p.noteLateFailure(id); } + /// A Save makes the directories its file goes in, and any above them, + /// first: one rule, for the pane's own name and `Save path` alike. A + /// directory it cannot make leaves the write to fail and say why. + fn makeParents(path: []const u8) void { + if (comptime !hosted) return; + const local = filesystem.localPath(path) orelse return; + filesystem.makeDirs(std.fs.path.dirname(local) orelse "/"); + } + pub fn saveFailed(p: *Pardes, id: u8, path: []const u8, err: anyerror) void { if (p.panes[id]) |pane| if (pane.file) |*f| { // The `-%` spelling fs.zig already uses for "make this dirty". @@ -5490,8 +5499,7 @@ pub const Pardes = struct { const was = f.saved_revision; const failures = p.fs.failures; f.saved_revision = f.revision; - if (f.make_dirs) if (filesystem.localPath(f.path)) |local| - filesystem.makeDirs(std.fs.path.dirname(local) orelse "/"); + makeParents(f.path); p.hostWriteFile(sf.pane, f.path, f.content); const saved_pane = p.panes[sf.pane] orelse return; if (saved_pane.serial != serial) return; @@ -5520,6 +5528,7 @@ pub const Pardes = struct { if (pane.file) |*f| { const was = f.saved_revision; const failures = p.fs.failures; + makeParents(st.path.slice()); p.hostWriteFile(st.pane, st.path.slice(), f.content); const after = p.panes[st.pane] orelse return; if (after.serial != st.serial) return; @@ -5535,6 +5544,7 @@ pub const Pardes = struct { if (!pane.isTerminal()) return; const text = panes.terminal.screenTextAlloc(pane, p.gpa) catch return; defer p.gpa.free(text); + makeParents(st.path.slice()); p.hostWriteFile(st.pane, st.path.slice(), text); }, .write_dump => { |
