summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/image.zig8
-rw-r--r--test/fs_namespace.zig11
2 files changed, 12 insertions, 7 deletions
diff --git a/src/image.zig b/src/image.zig
index 9f635d1c..324d445f 100644
--- a/src/image.zig
+++ b/src/image.zig
@@ -855,8 +855,12 @@ pub fn dumpPane(
path: []const u8,
raw: []const u8,
) !dump.Pane {
- const bytes = if (raw.len > 0) raw else filesystem.read(p, path) catch &.{};
- defer if (raw.len == 0) p.gpa.free(bytes);
+ // A picture or PDF on disk is read from there at Restore, as a clean
+ // file's text is: the dump keeps only the bytes of one that is not
+ // (megabytes of a PDF per dump, and a stale copy, otherwise).
+ _ = p;
+ const on_disk = if (filesystem.localPath(path)) |local| @import("exec.zig").kindOf(local) == .file else false;
+ const bytes: []const u8 = if (on_disk) &.{} else raw;
return .{
.kind = .image,
.tag = tag,
diff --git a/test/fs_namespace.zig b/test/fs_namespace.zig
index 5bce9eda..30c656ca 100644
--- a/test/fs_namespace.zig
+++ b/test/fs_namespace.zig
@@ -286,7 +286,7 @@ test "owned cwd failed file opens never publish a pane or retain a reservation"
try std.testing.expect(succeeded);
}
-test "images decode and dump through explicit filesystem mounts" {
+test "images decode through explicit filesystem mounts, and a dump reads one on disk from there" {
if (!filesystem.platform_has_fs) return error.SkipZigTest;
const gpa = std.testing.allocator;
pardes.image.start(std.testing.io, gpa);
@@ -308,8 +308,9 @@ test "images decode and dump through explicit filesystem mounts" {
const state = pane.image.?;
try std.testing.expectEqual(@as(usize, 1), state.iw);
try std.testing.expectEqual(@as(usize, 1), state.ih);
- const saved = try pardes.panes.Image.dumpPane(p, arena.allocator(), pane, "", "", 0, path, &.{});
- const decoded = try pardes.dump.decodeBytes(gpa, saved.image.?.bytes_b64);
- defer gpa.free(decoded);
- try std.testing.expectEqualStrings(bytes, decoded);
+ // On disk, the picture is no part of the dump: Restore reads it there.
+ const saved = try pardes.panes.Image.dumpPane(p, arena.allocator(), pane, "", "", 0, path, state.raw);
+ try std.testing.expectEqualStrings("", saved.image.?.bytes_b64);
+ const restored = try pardes.panes.Image.restore(p, p.freeSlot().?, saved);
+ try std.testing.expectEqualStrings(bytes, restored.image.?.raw);
}