summaryrefslogtreecommitdiff
path: root/src/selection_pipe.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/selection_pipe.zig')
-rw-r--r--src/selection_pipe.zig29
1 files changed, 13 insertions, 16 deletions
diff --git a/src/selection_pipe.zig b/src/selection_pipe.zig
index a03ab3eb..7832a75d 100644
--- a/src/selection_pipe.zig
+++ b/src/selection_pipe.zig
@@ -16,8 +16,6 @@ pub const max_total_stdout_bytes: usize = 4 * 1024 * 1024;
pub const max_stderr_bytes: usize = 64 * 1024;
pub const command_timeout_seconds: u64 = 10;
-pub const Input = struct { bytes: []const u8 };
-
/// Borrowed view exposed by the core while an effect is being drained.
/// An Edit's `<`, `|` and `>` (src/edit_cmd.zig) run a command of their own
/// per input, each in its file's directory: `commands` and `cwds`, when
@@ -27,7 +25,7 @@ pub const Request = struct {
id: u32,
command: []const u8,
cwd: []const u8,
- inputs: []const Input,
+ inputs: []const []const u8,
commands: []const []const u8 = &.{},
cwds: []const []const u8 = &.{},
shell: []const u8 = "",
@@ -66,30 +64,29 @@ pub const Job = struct {
errdefer gpa.free(job.command);
job.cwd = try gpa.dupe(u8, filesystem.localPath(request.cwd) orelse request.cwd);
errdefer gpa.free(job.cwd);
- job.inputs = try dupeAll(gpa, request.inputs.len, request.inputs, false);
+ job.inputs = try dupeAll(gpa, request.inputs, false);
errdefer freeAll(gpa, job.inputs);
- job.commands = try dupeAll(gpa, request.commands.len, request.commands, false);
+ job.commands = try dupeAll(gpa, request.commands, false);
errdefer freeAll(gpa, job.commands);
- job.cwds = try dupeAll(gpa, request.cwds.len, request.cwds, true);
+ job.cwds = try dupeAll(gpa, request.cwds, true);
errdefer freeAll(gpa, job.cwds);
job.shell = try gpa.dupe(u8, request.shell);
errdefer gpa.free(job.shell);
- job.env = try dupeAll(gpa, request.env.len, request.env, false);
+ job.env = try dupeAll(gpa, request.env, false);
return job;
}
- /// Owned copies of `items` (Inputs or strings); a directory as the
- /// host's own path, as `cwd` is.
- fn dupeAll(gpa: std.mem.Allocator, n: usize, items: anytype, dirs: bool) ![][]u8 {
- const out = try gpa.alloc([]u8, n);
+ /// Owned copies of `items`; a directory as the host's own path, as
+ /// `cwd` is.
+ fn dupeAll(gpa: std.mem.Allocator, items: []const []const u8, dirs: bool) ![][]u8 {
+ const out = try gpa.alloc([]u8, items.len);
var made: usize = 0;
errdefer {
for (out[0..made]) |item| gpa.free(item);
gpa.free(out);
}
for (items) |item| {
- const bytes: []const u8 = if (@TypeOf(item) == Input) item.bytes else item;
- out[made] = try gpa.dupe(u8, if (dirs) filesystem.localPath(bytes) orelse bytes else bytes);
+ out[made] = try gpa.dupe(u8, if (dirs) filesystem.localPath(item) orelse item else item);
made += 1;
}
return out;
@@ -554,7 +551,7 @@ test "native selection filters use the physical directory of an explicit OS moun
const directory = directory_buf[0..try tmp.dir.realPath(std.testing.io, &directory_buf)];
var declared_buf: [4102]u8 = undefined;
const declared = try std.fmt.bufPrint(&declared_buf, "/n/os{s}", .{directory});
- const job = try Job.copy(gpa, .{ .id = 1, .command = "pwd", .cwd = declared, .inputs = &.{.{ .bytes = "" }} });
+ const job = try Job.copy(gpa, .{ .id = 1, .command = "pwd", .cwd = declared, .inputs = &.{""} });
defer job.deinit(gpa);
try std.testing.expectEqualStrings(directory, job.cwd);
switch (runIn(gpa, std.testing.io, "", job.command, job.cwd, "", 0, &.{})) {
@@ -619,7 +616,7 @@ test "a request may give each input its own command and directory, run by the sh
.id = 3,
.command = "",
.cwd = "",
- .inputs = &.{ .{ .bytes = "" }, .{ .bytes = "abc" } },
+ .inputs = &.{ "", "abc" },
.commands = &.{ "pwd", "tr a-z A-Z" },
.cwds = &.{ "/tmp", "/" },
.shell = "/bin/sh",
@@ -639,7 +636,7 @@ test "stop kills a running request's commands, the whole group, and starts none
.id = 1,
.command = "",
.cwd = "",
- .inputs = &.{ .{ .bytes = "" }, .{ .bytes = "" } },
+ .inputs = &.{ "", "" },
.commands = &.{ "sleep 30; echo late", "echo never" },
.token = token,
});