summaryrefslogtreecommitdiff
path: root/core/Dir.zig
diff options
context:
space:
mode:
Diffstat (limited to 'core/Dir.zig')
-rw-r--r--core/Dir.zig13
1 files changed, 6 insertions, 7 deletions
diff --git a/core/Dir.zig b/core/Dir.zig
index 1be67378..3c74d704 100644
--- a/core/Dir.zig
+++ b/core/Dir.zig
@@ -46,17 +46,17 @@ pub fn ofName(name: []const u8) []const u8 {
/// (plan9port lib9 dirread, acme's dircmp): every name but `.` and `..`,
/// dotfiles too; a directory's, a link to one's too, ending in `/`; sorted
/// bytewise, the `/` counted; each ending in a newline.
-pub fn read(gpa: std.mem.Allocator, dir: []const u8) ![]u8 {
+pub fn read(tape: *pardes.tape.Tape, gpa: std.mem.Allocator, dir: []const u8) ![]u8 {
if (comptime !filesystem.platform_has_fs) return error.FileNotFound;
const local = filesystem.localPath(dir) orelse return error.NotLocal;
// Its own copy: the caller's may be a pane's, gone while the turn is out.
var own: [4096]u8 = undefined;
if (local.len > own.len) return error.NameTooLong;
@memcpy(own[0..local.len], local);
- return pardes.tape.site(.dir_listing, gpa, readHost, .{ gpa, own[0..local.len] });
+ return tape.site(.dir_listing, gpa, readHost, .{ gpa, own[0..local.len] });
}
-fn readHost(gpa: std.mem.Allocator, local: []const u8) ![]u8 {
+fn readHost(io: std.Io, gpa: std.mem.Allocator, local: []const u8) ![]u8 {
var entries: std.ArrayList([]u8) = .empty;
defer {
for (entries.items) |entry| gpa.free(entry);
@@ -64,7 +64,6 @@ fn readHost(gpa: std.mem.Allocator, local: []const u8) ![]u8 {
}
var total: usize = 0;
{
- const io = std.Io.Threaded.global_single_threaded.io();
var d = try std.Io.Dir.cwd().openDir(io, local, .{ .iterate = true });
defer d.close(io);
var it = d.iterate();
@@ -165,7 +164,7 @@ pub fn fit(p: *Pardes, pane: *Pane, cols: usize) void {
pub fn refresh(p: *Pardes, id: usize) !void {
const pane = p.panes[id] orelse return error.NoPane;
const serial = pane.serial;
- const names = try read(p.gpa, ofName(pane.file.?.path));
+ const names = try read(p.tape, p.gpa, ofName(pane.file.?.path));
// The pane may have closed while the turn was out.
const now = p.panes[id] orelse return p.gpa.free(names);
if (now.serial != serial) return p.gpa.free(names);
@@ -195,7 +194,7 @@ pub fn look(p: *Pardes, from: usize, dir: []const u8) void {
}
var said: [limits.host_path_cap + 16]u8 = undefined;
const what = std.fmt.bufPrint(&said, "look: {s}", .{name[0..@min(name.len, limits.host_path_cap)]}) catch unreachable; // cap and 6 fit
- const names = read(p.gpa, dir) catch |err| {
+ const names = read(p.tape, p.gpa, dir) catch |err| {
p.gpa.free(name);
return p.reportError(from, what, err);
};
@@ -307,7 +306,7 @@ test "a directory reads as acme lists it: dotfiles kept, . and .. not, directori
try tmp.dir.symLink(io, "a", "link", .{ .is_directory = true });
var buf: [4096]u8 = undefined;
const dir = buf[0..try tmp.dir.realPath(io, &buf)];
- const names = try read(testing.allocator, dir);
+ const names = try read(&pardes.tape.none, testing.allocator, dir);
defer testing.allocator.free(names);
// Bytewise, as dircmp's memcmp: `.` before capitals before small
// letters, and `a.d/` before `a/` because `.` is before `/`.