summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/replica.zig27
-rw-r--r--core/tape.zig7
2 files changed, 28 insertions, 6 deletions
diff --git a/core/replica.zig b/core/replica.zig
index 3e6be763..3627a07b 100644
--- a/core/replica.zig
+++ b/core/replica.zig
@@ -2356,6 +2356,10 @@ pub const Peers = struct {
ps.recording = true;
ps.samples = std.c.getenv("PARDES_REPLICA_STATS") != null;
}
+ // A join with no room lets go a view kept past its bound by the
+ // core's clock (Core.openView), which a wake by mail alone, as this
+ // join's, does not move (tui.zig `clockNow`): moved now, on the tape.
+ if (@popCount(core.views_open) == pardes.views.max) if (core.host.call(.now, .{})) |now| core.advance(now);
// A pair's first client, or the first back after a Restore with no
// client and no view kept for one: the view the session has is the
// joiner's. Any other attach (a detached session's too) opens one.
@@ -2364,7 +2368,14 @@ pub const Peers = struct {
const k = viewFor(core, joining.view, own) orelse {
core.unattended = ps.count() == 0 and ps.detached;
if (ps.count() == 0) ps.stop(core);
- return daemon.refuseReplica(fd, "that session has as many views as it takes");
+ const full = "that session has as many views as it takes";
+ var left: u64 = 0;
+ for (0..pardes.views.max) |i| if (pardes.views.isAway(core, @intCast(i))) {
+ const n = (core.views[i].?.away_ns + pardes.views.away_kept_ns) -| core.clock.now_ns;
+ left = if (left == 0) n else @min(left, n);
+ };
+ var why: [128]u8 = undefined;
+ return daemon.refuseReplica(fd, if (left == 0) full else std.fmt.bufPrint(&why, full ++ " (one is kept {d} s more for a client joining again)", .{(left + std.time.ns_per_s - 1) / std.time.ns_per_s}) catch full);
};
ps.seq += 1;
ps.unit(0, ps.seq);
@@ -6691,7 +6702,7 @@ test "a client's n in a kind's pane is a motion: it steps to the next place a re
/// `addon`: a kind whose state is its own on the session (a PDF's), which
/// the walk does not stand in (its Still has no search, place or word):
/// the soak's (test/replicas.zig) PDF and pictures are, judged by name.
-const On = enum { any, file, kind, shell, shell_normal, addon };
+const On = enum { any, file, kind, shell, shell_normal, addon, dir };
/// What a far client may wait a round trip for (the user's line, P14: a
/// side effect on the system may be slow; motions, edits and layout are
@@ -6712,6 +6723,12 @@ const may_wait = [_]Wait{
.{ .what = "LookPrev", .on = .any, .stop = "resolve", .why = "a Look's walk: each word asked of the disk" },
.{ .what = "Mini *", .on = .any, .stop = "resolve", .why = "a file opened by name, from the session's disk" },
.{ .what = "Get", .on = .any, .stop = "read_file", .why = "the file read again from the session's disk" },
+ .{ .what = "Get", .on = .dir, .stop = "dir_listing", .why = "a directory listed again from the session's disk" },
+ // A directory's pane (Dir.zig): its entries are names on the session's disk.
+ .{ .what = "Enter", .on = .dir, .stop = "resolve", .why = "the entry under the cursor opened, from the session's disk" },
+ .{ .what = "* Enter", .on = .dir, .stop = "resolve", .why = "the entry opened (Enter after a prefix still opens it)" },
+ .{ .what = "Tab", .on = .dir, .stop = "kind", .why = "what the entry under the cursor is, asked of the session's disk" },
+ .{ .what = "* Tab", .on = .dir, .stop = "kind", .why = "what the entry is (Tab after a prefix still asks)" },
.{ .what = "Save", .on = .any, .stop = "write_file", .why = "a save" },
// A program run, a shell opened or closed: the session's processes.
.{ .what = "Exec *", .on = .any, .stop = "kind", .why = "a program run: its name asked of the disk first" },
@@ -6987,12 +7004,16 @@ test "a far client's every word and key, on a file's pane, a kind's and a shell'
_ = try a.local(.{ .command = "Still" });
const kind = a.core.view().active;
try std.testing.expect(file != kind and a.core.panes[file].?.file != null and a.core.panes[kind].?.addon != null);
+ // A directory's pane (Dir.zig), listed from the disk.
+ _ = try a.local(.{ .command = try std.fmt.bufPrint(&line, "Look {s}/", .{dir}) });
+ const listing = a.core.view().active;
+ try std.testing.expect(a.core.panes[listing].?.file.?.listing != null);
var seen: [may_wait.len]bool = @splat(false);
var hit: [may_wait.len]bool = @splat(false);
var unlisted: u32 = 0;
var tried: u32 = 0;
- const stands = [_]struct { On, ?usize }{ .{ .file, file }, .{ .kind, kind }, .{ .shell, shell }, .{ .shell_normal, shell } };
+ const stands = [_]struct { On, ?usize }{ .{ .file, file }, .{ .kind, kind }, .{ .shell, shell }, .{ .shell_normal, shell }, .{ .dir, listing } };
for (stands) |stand| {
const on, const at = stand;
const id = at orelse continue;
diff --git a/core/tape.zig b/core/tape.zig
index d1e0527c..d32f8dd8 100644
--- a/core/tape.zig
+++ b/core/tape.zig
@@ -948,11 +948,11 @@ const pane_fields = walk.fieldNames(pardes.Pane);
const file_fields = walk.fieldNames(pardes.panes.File.State);
const places_fields = walk.fieldNames(pardes.panes.Places);
const view_fields = walk.fieldNames(Pardes.View);
-const Parts = [pardes_fields.len + stream_fields.len + pardes.views.max * view_fields.len + pardes.MAX_PANES * (2 + pane_fields.len + file_fields.len + places_fields.len)]u64;
+pub const Parts = [pardes_fields.len + stream_fields.len + pardes.views.max * view_fields.len + pardes.MAX_PANES * (2 + pane_fields.len + file_fields.len + places_fields.len)]u64;
/// The session's digest as one per field of the core's, its stream's, and
/// each pane's and its file's, so a divergence says where it is.
-fn digestParts(p: *const Pardes, parts: *Parts) []const u64 {
+pub fn digestParts(p: *const Pardes, parts: *Parts) []const u64 {
var n = walk.fieldDigests(Pardes, p, parts[0..pardes_fields.len]).len;
n += walk.fieldDigests(pardes.Stream, &p.stream, parts[n..][0..stream_fields.len]).len;
for (&p.views) |*slot| if (slot.*) |*v| {
@@ -974,7 +974,7 @@ fn digestParts(p: *const Pardes, parts: *Parts) []const u64 {
}
/// The fields whose digests differ, named.
-fn partsDiffer(got: []const u64, want: []const u64, a: std.mem.Allocator) []const u8 {
+pub fn partsDiffer(got: []const u64, want: []const u64, a: std.mem.Allocator) []const u8 {
var said: std.ArrayList(u8) = .empty;
if (got.len != want.len) said.print(a, "the panes there are ({d} parts, {d} recorded); ", .{ got.len, want.len }) catch {};
const n = @min(got.len, want.len);
@@ -1312,6 +1312,7 @@ pub fn recordDigest(t: *Tape) void {
t.record(.digest, []const u64, &d);
}
+
/// A core made outside the tape (a replica client's, from a dump) is the
/// one it replays into.
pub fn adoptCore(t: *Tape, p: *Pardes) void {