summaryrefslogtreecommitdiff
path: root/src/builtins.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/builtins.zig')
-rw-r--r--src/builtins.zig47
1 files changed, 32 insertions, 15 deletions
diff --git a/src/builtins.zig b/src/builtins.zig
index de69c545..2b7a9c1e 100644
--- a/src/builtins.zig
+++ b/src/builtins.zig
@@ -705,31 +705,48 @@ pub const Kill = struct {
}
};
-/// Write the session's panes and layout to a dump file, for Restore.
+/// Write the session's panes and layout to the state file, for Restore;
+/// `Dump export <path>` writes them to a file of their own instead.
pub const Dump = struct {
pub const scope: Scope = .session;
+ pub const takes_arg = true;
pub fn run(c: Ctx) void {
+ var to: ?[]const u8 = null;
+ if (c.arg) |arg| {
+ const trimmed = std.mem.trim(u8, arg, " \t");
+ if (!std.mem.startsWith(u8, trimmed, "export ")) return c.p.reportFailure(c.id, "Dump: takes export <path>, or nothing");
+ const path = std.mem.trim(u8, trimmed["export".len..], " \t");
+ if (path.len == 0) return c.p.reportFailure(c.id, "Dump: takes export <path>, or nothing");
+ to = path;
+ }
// Never a Dump said done that wrote nothing: its failure is said.
- dump.dumpState(c.p) catch |err| c.p.reportError(c.id, "Dump", err);
+ dump.dumpTo(c.p, to) catch |err| c.p.reportError(c.id, "Dump", err);
}
};
-/// Replace every pane with those of a dump file, the last one Dump wrote when bare.
+/// Replace every pane with those of a dump: the state file's of that label,
+/// or a file's; bare, the last one this session made, else the newest.
pub const Restore = struct {
pub const scope: Scope = .session;
pub const takes_arg = true;
pub fn run(c: Ctx) void {
- const typed = c.arg orelse (c.p.last_dump orelse return c.p.reportFailure(c.id, "Restore: no dump yet; name one"));
- // The file it reads, whole (`~`, the DumpDir, the directory it runs
- // in): what the log's `restore` record and every message name.
+ const typed: ?[]const u8 = c.arg orelse c.p.last_dump;
+ // A file it names, its whole path (`~`, the DumpDir, the directory
+ // it runs in): what the log's `restore` record and every message
+ // name. Else a label of the state file's.
var full_buf: [4096]u8 = undefined;
- const path = @import("fs.zig").restorePath(typed, c.p.settings.dump_dir.get(), &full_buf);
- if (path.len > c.p.restore_buf.len) return c.p.reportFailure(c.id, "Restore: that name is too long");
- // A dump that cannot be read is said now, and fails a ctl write: the
- // host reads it only after this step, where nobody hears. First,
- // so a Restore that could never happen spends no warning.
- {
- const bytes = @import("fs.zig").readRestore(c.p.gpa, path, c.p.settings.dump_dir.get()) catch |err| {
+ var label_buf: [256]u8 = undefined;
+ const file = if (typed) |t| dump.restoreFile(t, c.p.settings.dump_dir.get(), &full_buf) else null;
+ const name = if (file) |path| path else pardes.tape.authority(pardes.Db.labelled, .{ &c.p.db, c.p, typed, @as([]u8, &label_buf) }) orelse {
+ var buf: [320]u8 = undefined;
+ return c.p.reportFailure(c.id, if (typed) |t| std.fmt.bufPrint(&buf, "Restore: no dump labelled {s}", .{t[0..@min(t.len, 256)]}) catch "Restore: no dump of that label" else "Restore: no dump yet; name one");
+ };
+ if (name.len > c.p.restore_buf.len) return c.p.reportFailure(c.id, "Restore: that name is too long");
+ // A file that cannot be read is said now, and fails a ctl write:
+ // the host reads it only after this step, where nobody hears.
+ // First, so a Restore that could never happen spends no warning.
+ if (file) |path| {
+ const bytes = @import("fs.zig").readFile(c.p.gpa, path) catch |err| {
var buf: [limits.host_path_cap + 64]u8 = undefined;
var words: [128]u8 = undefined;
const why = switch (err) {
@@ -752,8 +769,8 @@ pub const Restore = struct {
// acme's Load adds a dump's windows to the ones there; a Restore
// replaces them all, so it asks what Exit asks first.
if (warnModifiedIn(c, .Restore, .all)) return;
- @memcpy(c.p.restore_buf[0..path.len], path);
- c.p.restore_req = c.p.restore_buf[0..path.len];
+ @memcpy(c.p.restore_buf[0..name.len], name);
+ c.p.restore_req = c.p.restore_buf[0..name.len];
}
};