summaryrefslogtreecommitdiff
path: root/core/dump.zig
diff options
context:
space:
mode:
Diffstat (limited to 'core/dump.zig')
-rw-r--r--core/dump.zig41
1 files changed, 22 insertions, 19 deletions
diff --git a/core/dump.zig b/core/dump.zig
index a37f46b9..e6e13a64 100644
--- a/core/dump.zig
+++ b/core/dump.zig
@@ -43,12 +43,12 @@ fn hostEnv(name: [*:0]const u8) ?[*:0]u8 {
/// Where the state file is (Db.zig) and relative Restore names are looked
/// up: the `DumpDir` setting when set (a leading `~/` is the home
/// directory), else the default.
-pub fn directory(buf: []u8, dir_setting: []const u8) ?[]const u8 {
+pub fn directory(tape: *pardes.tape.Tape, buf: []u8, dir_setting: []const u8) ?[]const u8 {
if (dir_setting.len == 0) return defaultDirectory(buf);
var joined: [4096]u8 = undefined;
// `~/x`, else a relative one from the directory pardes started in: the
// same place however it was written, and shown so.
- const raw = pardes.filesystem.expandHome(dir_setting, &joined);
+ const raw = pardes.filesystem.expandHome(tape, dir_setting, &joined);
var fba_buf: [4096]u8 = undefined;
var fba = std.heap.FixedBufferAllocator.init(&fba_buf);
var cwd_buf: [1024]u8 = undefined;
@@ -98,11 +98,11 @@ const Session = walk.Dump(&.{ Pardes, []const filesystem.Mount, OnDisk, []const
const SessionLoad = walk.Load(&.{ Pardes, []const filesystem.Mount, OnDisk, []const u8, []const views.Shares });
const OnDisk = [MAX_PANES]bool;
-fn onDisk(pane: *const pardes.panes.Pane) bool {
+fn onDisk(tape: *pardes.tape.Tape, pane: *const pardes.panes.Pane) bool {
const f = pane.file orelse return false;
if (f.output != null) return false;
const local = filesystem.localPath(f.path) orelse return false;
- return exec.kindOf(local) != null;
+ return exec.kindOf(tape, local) != null;
}
pub fn dumpState(p: *Pardes) !void {
@@ -177,8 +177,8 @@ pub fn dumpTo(p: *Pardes, to: ?[]const u8) !void {
/// with a `/` or `~/` (as it resolves, else as typed: the read says why),
/// or a bare word that names a file in the DumpDir or the directory pardes
/// runs in; null for one that names none: a label of the state file's.
-pub fn restoreFile(name: []const u8, dir_setting: []const u8, out: *[4096]u8) ?[]const u8 {
- const path = filesystem.restorePath(name, dir_setting, out);
+pub fn restoreFile(tape: *pardes.tape.Tape, name: []const u8, dir_setting: []const u8, out: *[4096]u8) ?[]const u8 {
+ const path = filesystem.restorePath(tape, name, dir_setting, out);
if (std.mem.indexOfScalar(u8, name, '/') != null or std.mem.startsWith(u8, name, "~")) return path;
return if (std.Io.Dir.path.isAbsolute(path)) path else null;
}
@@ -187,7 +187,7 @@ pub fn restoreFile(name: []const u8, dir_setting: []const u8, out: *[4096]u8) ?[
/// or an old byte dump), else the state file's dump of that label.
pub fn restoreBytes(p: *Pardes, gpa: std.mem.Allocator, name: []const u8) ![]u8 {
var buf: [4096]u8 = undefined;
- if (restoreFile(name, p.settings.dump_dir.get(), &buf)) |path| return filesystem.readFile(gpa, path);
+ if (restoreFile(p.tape, name, p.settings.dump_dir.get(), &buf)) |path| return filesystem.readFile(p.tape, gpa, path);
const got = p.db.getDump(p, gpa, name) catch |err| return if (err == error.OutOfMemory) error.OutOfMemory else error.BadDump;
return got orelse error.FileNotFound;
}
@@ -222,7 +222,7 @@ pub fn image(p: *Pardes, name: []const u8) ![]u8 {
var names: std.Io.Writer.Allocating = .init(gpa);
defer names.deinit();
for (p.panes, &on_disk) |slot, *on| if (slot) |pane| {
- on.* = onDisk(pane);
+ on.* = onDisk(p.tape, pane);
panes += 1;
const shown: []const u8 = if (pane.addon) |k| k.path else if (pane.file) |f| (if (f.output == null) f.path else "") else pane.cwdSlice();
if (shown.len == 0 or names.written().len + shown.len > 4096) continue;
@@ -263,15 +263,18 @@ pub fn image(p: *Pardes, name: []const u8) ![]u8 {
pub fn dumpJoin(p: *Pardes, deferred: *std.ArrayListUnmanaged(walk.Deferred)) ![]u8 {
slim_terminals = true;
defer slim_terminals = false;
- join_files = true;
- defer join_files = false;
+ // The join's file reads are the session's host's, between its steps:
+ // with its io, which the core's tape holds (a walk's hook takes no more).
+ join_files = p.tape.io;
+ defer join_files = null;
return dumpWith(p, deferred);
}
/// `dumpJoin`'s and `dumpExit`'s: a terminal dumps its size, not its emulator.
pub var slim_terminals = false;
-/// `dumpJoin`'s: a plain kind's pane carries its file (SlotRecord.file).
-var join_files = false;
+/// `dumpJoin`'s: a plain kind's pane carries its file (SlotRecord.file),
+/// read with this io.
+var join_files: ?std.Io = null;
fn dumpWith(p: *Pardes, deferred: ?*std.ArrayListUnmanaged(walk.Deferred)) ![]u8 {
var d = try Session.init(p.gpa);
@@ -282,7 +285,7 @@ fn dumpWith(p: *Pardes, deferred: ?*std.ArrayListUnmanaged(walk.Deferred)) ![]u8
try d.put([]const filesystem.Mount, &mounts);
var on_disk: OnDisk = @splat(false);
for (p.panes, &on_disk) |slot, *on| if (slot) |pane| {
- on.* = onDisk(pane);
+ on.* = onDisk(p.tape, pane);
};
try d.put(OnDisk, &on_disk);
const theme: []const u8 = colors.themes[@min(p.settings.theme, colors.themes.len - 1)].name;
@@ -691,7 +694,7 @@ fn revivePane(p: *Pardes, id: usize, pane: *pardes.panes.Pane, was_on_disk: bool
// Its file gone from disk since the dump: its text is nowhere else, so
// it is said deleted, and Del, Exit and Restore ask first. One never on
// disk (a name not yet saved) comes back as it was.
- if (was_on_disk and !onDisk(pane)) pardes.panes.File.deleted(p, @intCast(id));
+ if (was_on_disk and !onDisk(p.tape, pane)) pardes.panes.File.deleted(p, @intCast(id));
}
// ---- one pane to and from a dump: the store's, a handover's ----
@@ -808,10 +811,10 @@ pub fn slotWrite(s: *const Kind.Slot, gpa: std.mem.Allocator, w: *std.Io.Writer)
// Paid only at a client's join: the session keeps no file's bytes.
var file: ?[]u8 = null;
defer if (file) |f| s.gpa.free(f);
- if (join_files and s.plain != null and s.ops != null) if (filesystem.localPath(s.path)) |path| {
+ if (join_files) |io| if (s.plain != null and s.ops != null) if (filesystem.localPath(s.path)) |path| {
const z = try s.gpa.dupeSentinel(u8, path, 0);
defer s.gpa.free(z);
- file = filesystem.readHost(s.gpa, z, pardes.memory.limits.max_file_bytes) catch null;
+ file = filesystem.readHost(io, s.gpa, z, pardes.memory.limits.max_file_bytes) catch null;
r.file = file;
};
const bytes = try walk.save(SlotRecord, gpa, &r);
@@ -944,9 +947,9 @@ fn revivePdf(p: *Pardes, id: usize, pane: *pardes.panes.Pane, old: *pardes.panes
test "a DumpDir reads back absolute, however it was written" {
var buf: [4096]u8 = undefined;
- try std.testing.expectEqualStrings("/tmp/dumps", directory(&buf, "/tmp/dumps/").?);
- try std.testing.expectEqualStrings("/tmp/dumps", directory(&buf, "/tmp//x/../dumps").?);
- const rel = directory(&buf, "rel/");
+ try std.testing.expectEqualStrings("/tmp/dumps", directory(&pardes.tape.none, &buf, "/tmp/dumps/").?);
+ try std.testing.expectEqualStrings("/tmp/dumps", directory(&pardes.tape.none, &buf, "/tmp//x/../dumps").?);
+ const rel = directory(&pardes.tape.none, &buf, "rel/");
try std.testing.expect(std.Io.Dir.path.isAbsolute(rel.?) and std.mem.endsWith(u8, rel.?, "/rel"));
}