summaryrefslogtreecommitdiff
path: root/src/host_io.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/host_io.zig')
-rw-r--r--src/host_io.zig60
1 files changed, 30 insertions, 30 deletions
diff --git a/src/host_io.zig b/src/host_io.zig
index 44061c4d..a363a578 100644
--- a/src/host_io.zig
+++ b/src/host_io.zig
@@ -919,7 +919,7 @@ pub const Lsp = struct {
const job = try snapshot(gpa, core, .{ .id = 1, .kind = .hover, .pane = @intCast(core.view().active), .offset = 0, .arg = "" });
defer job.free(gpa);
try std.testing.expectEqualStrings(case.native, job.path);
- try std.testing.expectEqualStrings(std.fs.path.dirname(case.native).?, job.root);
+ try std.testing.expectEqualStrings(std.Io.Dir.path.dirname(case.native).?, job.root);
try std.testing.expectEqualStrings(case.path, pane.file.?.path);
}
}
@@ -1312,11 +1312,11 @@ pub const Shell = struct {
try tmp.dir.createDirPath(std.testing.io, "paths.d");
try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "paths.d/20-last", .data = "/opt/local/bin\n/usr/bin\n" });
try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "paths.d/10-first", .data = "/opt/homebrew/bin\n/bin\n" });
- var root_buf: [std.fs.max_path_bytes]u8 = undefined;
+ var root_buf: [std.Io.Dir.max_path_bytes]u8 = undefined;
const root = root_buf[0..try tmp.dir.realPath(std.testing.io, &root_buf)];
- var file_buf: [std.fs.max_path_bytes]u8 = undefined;
+ var file_buf: [std.Io.Dir.max_path_bytes]u8 = undefined;
const paths_file = try std.fmt.bufPrintSentinel(&file_buf, "{s}/paths", .{root}, 0);
- var dir_buf: [std.fs.max_path_bytes]u8 = undefined;
+ var dir_buf: [std.Io.Dir.max_path_bytes]u8 = undefined;
const paths_dir = try std.fmt.bufPrint(&dir_buf, "{s}/paths.d", .{root});
var buf: [path_capacity]u8 = undefined;
var len: usize = 0;
@@ -1348,7 +1348,7 @@ pub const Shell = struct {
const base = if (std.mem.lastIndexOfScalar(u8, bin, '/')) |s| bin[s + 1 ..] else bin;
for ([_][]const u8{ "sh", "dash", "zsh", "ksh", "mksh", "yash", "nu", "elvish", "xonsh", "tcsh", "csh" }) |known|
if (std.mem.eql(u8, base, known)) return .none;
- var real: [std.fs.max_path_bytes]u8 = undefined;
+ var real: [std.Io.Dir.max_path_bytes]u8 = undefined;
if (libc.realpath(path, &real)) |r| {
const by_link = family(std.mem.span(@as([*:0]const u8, @ptrCast(r))));
if (by_link != .none) return by_link;
@@ -1577,7 +1577,7 @@ pub const Shell = struct {
};
// Resolve in the parent. The path buffer and prompt files must survive through exec.
- pub fn resolve(bin: []const u8, buf: *[std.fs.max_path_bytes]u8, prompt_rcs: *const PromptFiles) Spawn {
+ pub fn resolve(bin: []const u8, buf: *[std.Io.Dir.max_path_bytes]u8, prompt_rcs: *const PromptFiles) Spawn {
const path = find(bin, buf) orelse fallback(buf);
const marks: [2]?[*:0]const u8 = switch (familyOf(path)) {
.bash => if (prompt_rcs.bashPath()) |rc| .{ "--rcfile", rc.ptr } else .{ null, null },
@@ -1607,7 +1607,7 @@ pub const Shell = struct {
/// A shell by its path or its name in the usual directories, or null.
/// A path may be under a mount this editor serves: the turn goes out
/// with the lookups (pardes.Turn.yield).
- pub fn find(bin: []const u8, buf: *[std.fs.max_path_bytes]u8) ?[*:0]const u8 {
+ pub fn find(bin: []const u8, buf: *[std.Io.Dir.max_path_bytes]u8) ?[*:0]const u8 {
if (bin.len == 0 or bin.len + 1 > buf.len) return null;
pardes.turn.yield();
defer pardes.turn.back();
@@ -1638,7 +1638,7 @@ pub const Shell = struct {
/// Why `bin` is no shell, for the words that name one (Term, Shell);
/// null when it is one.
pub fn refusal(bin: []const u8, said: []u8) ?[]const u8 {
- var buf: [std.fs.max_path_bytes]u8 = undefined;
+ var buf: [std.Io.Dir.max_path_bytes]u8 = undefined;
if (find(bin, &buf)) |found| {
// A script whose `#!` names a program that is not there: its
// exec fails ENOENT as a missing shell's does, so told apart.
@@ -1697,7 +1697,7 @@ pub const Shell = struct {
try std.testing.expect(std.mem.endsWith(u8, refusal(plain, &said).?, "plain is not executable"));
}
- fn fallback(buf: *[std.fs.max_path_bytes]u8) [*:0]const u8 {
+ fn fallback(buf: *[std.Io.Dir.max_path_bytes]u8) [*:0]const u8 {
for (fallbacks) |f| {
@memcpy(buf[0..f.len], f);
buf[f.len] = 0;
@@ -1723,7 +1723,7 @@ pub const Shell = struct {
test "a path is taken at its word, a name is looked up, and both pick their own marks" {
if (builtin.os.tag == .windows) return;
- var buf: [std.fs.max_path_bytes]u8 = undefined;
+ var buf: [std.Io.Dir.max_path_bytes]u8 = undefined;
var prompt_rcs = PromptFiles.init();
defer prompt_rcs.deinit();
@@ -1767,13 +1767,13 @@ pub const Shell = struct {
test "prompt files are one per content under the runtime dir, or private and cleaned up without it" {
if (builtin.os.tag == .windows) return;
- var saved_buf: [std.fs.max_path_bytes:0]u8 = @splat(0);
+ var saved_buf: [std.Io.Dir.max_path_bytes:0]u8 = @splat(0);
const saved: ?[:0]const u8 = if (std.c.getenv("XDG_RUNTIME_DIR")) |v| std.fmt.bufPrintSentinel(&saved_buf, "{s}", .{std.mem.span(v)}, 0) catch null else null;
defer _ = if (saved) |v| setenv("XDG_RUNTIME_DIR", v.ptr, 1) else testUnsetenv("XDG_RUNTIME_DIR");
var tmp = std.testing.tmpDir(.{});
defer tmp.cleanup();
- var dir_buf: [std.fs.max_path_bytes:0]u8 = @splat(0);
+ var dir_buf: [std.Io.Dir.max_path_bytes:0]u8 = @splat(0);
const dir_len = try tmp.dir.realPath(std.testing.io, &dir_buf);
_ = setenv("XDG_RUNTIME_DIR", dir_buf[0..dir_len :0].ptr, 1);
@@ -1797,7 +1797,7 @@ pub const Shell = struct {
a.deinit();
b.deinit();
try std.testing.expect(libc.access(&kept, 0) == 0);
- try tmp.dir.writeFile(std.testing.io, .{ .sub_path = std.fs.path.basename(kept[0..a_bash.len]), .data = "half" });
+ try tmp.dir.writeFile(std.testing.io, .{ .sub_path = std.Io.Dir.path.basename(kept[0..a_bash.len]), .data = "half" });
var c = PromptFiles.init();
defer c.deinit();
try std.testing.expectEqualStrings(bash_rc, readSmall(c.bashPath().?, &buf) orelse return error.ReadFailed);
@@ -1810,7 +1810,7 @@ pub const Shell = struct {
const d_bash = d.bashPath() orelse return error.TempCreateFailed;
try std.testing.expect(!std.mem.eql(u8, d_bash, e.bashPath().?));
try std.testing.expect(std.mem.startsWith(u8, d_bash, "/tmp/pardes-osc133-bash-"));
- try std.testing.expectEqual(@as(?std.c.pid_t, std.c.getpid()), rcPid(std.fs.path.basename(d_bash)));
+ try std.testing.expectEqual(@as(?std.c.pid_t, std.c.getpid()), rcPid(std.Io.Dir.path.basename(d_bash)));
@memcpy(kept[0..d_bash.len], d_bash);
kept[d_bash.len] = 0;
d.deinit();
@@ -1985,15 +1985,15 @@ pub const ChildEnv = struct {
/// another; plain `pardes -` where the path cannot be read or quoted.
fn pardesPagers() []const [*:0]const u8 {
const S = struct {
- var pager: [std.fs.max_path_bytes + 32:0]u8 = undefined;
- var git_pager: [std.fs.max_path_bytes + 32:0]u8 = undefined;
- var systemd_pager: [std.fs.max_path_bytes + 32:0]u8 = undefined;
+ var pager: [std.Io.Dir.max_path_bytes + 32:0]u8 = undefined;
+ var git_pager: [std.Io.Dir.max_path_bytes + 32:0]u8 = undefined;
+ var systemd_pager: [std.Io.Dir.max_path_bytes + 32:0]u8 = undefined;
var entries: [4][*:0]const u8 = undefined;
var ready = false;
};
if (!S.ready) {
- var exe_buf: [std.fs.max_path_bytes]u8 = undefined;
- var quoted_buf: [std.fs.max_path_bytes + 2]u8 = undefined;
+ var exe_buf: [std.Io.Dir.max_path_bytes]u8 = undefined;
+ var quoted_buf: [std.Io.Dir.max_path_bytes + 2]u8 = undefined;
const n = if (comptime builtin.os.tag == .linux) libc.readlink("/proc/self/exe", &exe_buf, exe_buf.len) else -1;
const exe: []const u8 = if (n > 0 and @as(usize, @intCast(n)) < exe_buf.len) exe_buf[0..@intCast(n)] else "pardes";
const command = pagerCommand(exe, &quoted_buf);
@@ -2176,7 +2176,7 @@ pub fn forkShell(
break :dir path;
};
var master: c_int = -1;
- var path_buf: [std.fs.max_path_bytes]u8 = undefined;
+ var path_buf: [std.Io.Dir.max_path_bytes]u8 = undefined;
// A terminal opened on a shell of its own (`Term fish`) runs that one,
// copied: looking it up gives the turn up, and the pane may go.
var own_buf: [256]u8 = undefined;
@@ -2390,7 +2390,7 @@ extern "c" fn proc_pidinfo(pid: c_int, flavor: c_int, arg: u64, buffer: *anyopaq
/// prompt files (bash, zsh, fish), which a pane's runs wait on.
pub fn marksPrompts(pid: libc.pid_t) bool {
var buf: [pardes.memory.limits.host_path_cap + 1]u8 = undefined;
- const exe = std.fs.path.basename(processExe(pid, &buf) orelse return false);
+ const exe = std.Io.Dir.path.basename(processExe(pid, &buf) orelse return false);
for ([_][]const u8{ "bash", "zsh", "fish" }) |shell| if (std.mem.eql(u8, exe, shell)) return true;
return false;
}
@@ -2465,8 +2465,8 @@ fn kernProc(pid: libc.pid_t, what: c_int, buf: []u8) ?usize {
/// foreground group when that is the same shell, and while a job holds the
/// foreground there is no answer, the last one standing.
pub fn ttyCwd(shell_pid: libc.pid_t, master_fd: c_int, shell_exe: []const u8, buf: []u8) ?[]const u8 {
- var exe_buf: [std.fs.max_path_bytes]u8 = undefined;
- var shell_buf: [std.fs.max_path_bytes]u8 = undefined;
+ var exe_buf: [std.Io.Dir.max_path_bytes]u8 = undefined;
+ var shell_buf: [std.Io.Dir.max_path_bytes]u8 = undefined;
const shell = realShell(shell_exe, &shell_buf) orelse return shellCwd(shell_pid, buf);
const exe = processExe(shell_pid, &exe_buf) orelse return shellCwd(shell_pid, buf);
if (std.mem.eql(u8, exe, shell)) return shellCwd(shell_pid, buf);
@@ -2477,8 +2477,8 @@ pub fn ttyCwd(shell_pid: libc.pid_t, master_fd: c_int, shell_exe: []const u8, bu
}
/// `shell_exe` as /proc/<pid>/exe would read it: its links followed.
-fn realShell(shell_exe: []const u8, buf: *[std.fs.max_path_bytes]u8) ?[]const u8 {
- var z: [std.fs.max_path_bytes:0]u8 = undefined;
+fn realShell(shell_exe: []const u8, buf: *[std.Io.Dir.max_path_bytes]u8) ?[]const u8 {
+ var z: [std.Io.Dir.max_path_bytes:0]u8 = undefined;
const path = std.fmt.bufPrintSentinel(&z, "{s}", .{shell_exe}, 0) catch return null;
const r = libc.realpath(path, buf) orelse return null;
return std.mem.span(@as([*:0]const u8, @ptrCast(r)));
@@ -2600,8 +2600,8 @@ const tty_probe_platform = switch (builtin.os.tag) {
};
const TtyProbe = struct {
- self_exe: [std.fs.max_path_bytes]u8 = undefined,
- exe: [std.fs.max_path_bytes]u8 = undefined,
+ self_exe: [std.Io.Dir.max_path_bytes]u8 = undefined,
+ exe: [std.Io.Dir.max_path_bytes]u8 = undefined,
blob: [4096]u8 = undefined,
pending: [occ_max_visited]Node = undefined,
@@ -3060,7 +3060,7 @@ pub fn foregroundName(shell_pid: libc.pid_t, master_fd: c_int, buf: []u8) ?[]con
if (comptime builtin.os.tag != .linux and builtin.os.tag != .freebsd) return null;
const fg = tcgetpgrp(master_fd);
if (fg <= 0 or fg == shell_pid) return null;
- if (comptime builtin.os.tag == .freebsd) return std.fs.path.basename(processExe(fg, buf) orelse return null);
+ if (comptime builtin.os.tag == .freebsd) return std.Io.Dir.path.basename(processExe(fg, buf) orelse return null);
var name: [64:0]u8 = undefined;
const path = std.fmt.bufPrintSentinel(&name, "/proc/{d}/comm", .{@as(u32, @intCast(fg))}, 0) catch return null;
const comm = std.mem.trimEnd(u8, readProc(path, buf) orelse return null, "\n");
@@ -3534,8 +3534,8 @@ test "the walk reaches the leaf: bash -c 'sleep 30' takes the tty" {
var pending: usize = 0;
try std.testing.expectEqual(Pushed.pushed, pushChildren(&probe, &pending, sh.pid, 1));
try std.testing.expectEqual(@as(usize, 1), pending);
- var wrapper_buf: [std.fs.max_path_bytes]u8 = undefined;
- var shell_buf: [std.fs.max_path_bytes]u8 = undefined;
+ var wrapper_buf: [std.Io.Dir.max_path_bytes]u8 = undefined;
+ var shell_buf: [std.Io.Dir.max_path_bytes]u8 = undefined;
try std.testing.expectEqualStrings(
processExe(sh.pid, &shell_buf).?,
processExe(probe.pending[0].pid, &wrapper_buf).?,