diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/File.zig | 4 | ||||
| -rw-r--r-- | src/builtins.zig | 3 | ||||
| -rw-r--r-- | src/ninep/pane.zig | 18 | ||||
| -rw-r--r-- | src/pardes.zig | 14 |
4 files changed, 13 insertions, 26 deletions
diff --git a/src/File.zig b/src/File.zig index 43b921e3..84cec879 100644 --- a/src/File.zig +++ b/src/File.zig @@ -61,10 +61,6 @@ pub const State = struct { /// edit to another length cannot be back to it, and is not hashed. saved_len: ?usize = null, watch_after_save: bool = false, - /// Save makes the file's directory, and any above it, first: `Config`'s - /// pane for an init file that is not there yet, whose directory may not - /// be either. - make_dirs: bool = false, /// The file changed on disk under unsaved edits, which were kept (see /// `changed`): its hash, so the same change is said once, until a Save /// or get settles it. A Save warns once before overwriting it, as acme's diff --git a/src/builtins.zig b/src/builtins.zig index 8fe49649..5a2037cf 100644 --- a/src/builtins.zig +++ b/src/builtins.zig @@ -1304,9 +1304,8 @@ pub const Config = struct { // Not there yet: a pane named for it, which Save makes. const free = c.p.freeSlot() orelse return c.p.reportError(c.id, "Config", error.NoPaneSlots); c.p.newScratchFor(c.id, .scratch); - const pane = c.p.panes[free] orelse return; + if (c.p.panes[free] == null) return; @import("ninep/pane.zig").nameBuffer(c.p, free, path, false) catch |err| return c.p.reportError(c.id, "Config", err); - pane.file.?.make_dirs = true; c.p.active = free; } }; diff --git a/src/ninep/pane.zig b/src/ninep/pane.zig index 6a0fbba5..de7f7cd4 100644 --- a/src/ninep/pane.zig +++ b/src/ninep/pane.zig @@ -867,11 +867,6 @@ fn writeName(p: *Pardes, req: Req, id: usize, pane: *Pane) Reply { error.OutOfMemory => E.NOMEM, else => E.INVAL, }); - // A name into a directory not there yet asks for it, as Config's pane - // does: its Save makes the directories (`pardes new/dir/f` forwarded). - if (comptime pardes.hosted) if (fs.localPath(std.fs.path.dirname(full) orelse "/")) |local| { - if (!exec.isDirectory(local)) fileOf(pane).?.make_dirs = true; - }; return .{ .tag = req.tag, .written = @intCast(req.data.len) }; } @@ -1392,19 +1387,6 @@ test "a name with a component over 255 bytes is refused, and a long path's faile try testing.expect(std.mem.endsWith(u8, late, "/f.txt: no such directory")); } -test "a name into a directory not there has Save make it; one into a directory there does not" { - if (comptime !pardes.hosted) return error.SkipZigTest; - const p = try withFile(testing.allocator, "x\n"); - defer p.deinit(); - const serial = serialOf(p); - const f = fileOf(p.panes[p.paneBySerial(serial).?].?).?; - try testing.expectEqual(Status.ok, wr(p, Node.of(serial, .name), "/tmp/pardes-no-such-dir-mk/sub/f.txt\n").reply.status); - try testing.expect(f.make_dirs); - f.make_dirs = false; - try testing.expectEqual(Status.ok, wr(p, Node.of(serial, .name), "/tmp/f.txt\n").reply.status); - try testing.expect(!f.make_dirs); -} - test "a name cut across writes is one name, applied once at its newline or its close" { const p = try withFile(testing.allocator, "x\n"); defer p.deinit(); 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 => { |
