diff options
| -rw-r--r-- | src/File.zig | 10 | ||||
| -rw-r--r-- | src/ninep/ctl.zig | 19 |
2 files changed, 29 insertions, 0 deletions
diff --git a/src/File.zig b/src/File.zig index d41007c3..4fac0073 100644 --- a/src/File.zig +++ b/src/File.zig @@ -953,6 +953,16 @@ pub fn restore(p: *Pardes, id: usize, src: dump.Pane) !*Pane { if (std.hash.Wyhash.hash(0, bytes) != read_against) changed(p, @intCast(id), bytes); } else |_| {} }; + // An older dump says nothing of what the text was read against: its + // first Save asks, as for a file changed on disk, rather than guess. + if (saved.dirty and saved.disk_hash == null and output == null and onDisk(path)) { + if (filesystem.read(p, path)) |bytes| { + defer p.gpa.free(bytes); + const f = &pane.file.?; + f.disk_newer = std.hash.Wyhash.hash(0, bytes); + f.disk_newer_warned = false; + } else |_| {} + } return pane; } diff --git a/src/ninep/ctl.zig b/src/ninep/ctl.zig index 16fbabb4..554333bb 100644 --- a/src/ninep/ctl.zig +++ b/src/ninep/ctl.zig @@ -4409,3 +4409,22 @@ test "a command or a terminal refused for room is refused before anything is log p.update(.{ .resize = .{ .cols = 80, .rows = 24 } }); } } + +test "an unsaved pane from a dump that says nothing of its disk asks at its first Save" { + if (comptime !pardes.hosted) return; + const gpa = testing.allocator; + var tmp = testing.tmpDir(.{}); + defer tmp.cleanup(); + try tmp.dir.writeFile(testing.io, .{ .sub_path = "old.txt", .data = "disk\n" }); + var dir_buf: [4096]u8 = undefined; + const dir = dir_buf[0..try tmp.dir.realPath(testing.io, &dir_buf)]; + var path_buf: [4200]u8 = undefined; + const path = try std.fmt.bufPrint(&path_buf, "{s}/old.txt", .{dir}); + const p = try withFile(gpa, "x\n"); + defer p.deinit(); + const id = p.freeSlot().?; + const pane = try pardes.panes.File.restore(p, id, .{ .kind = .file, .tag = "", .body = "", .file = .{ .path = path, .content = "unsaved\n", .dirty = true } }); + try testing.expect(pane.file.?.disk_newer != null); + pardes.exec.saveFile(p, id); + try testing.expect(th.logHas(p, "modified on disk since read (Save again to overwrite)")); +} |
