From b175d50a3b7f8434ef087536af5c32e97e2b4f0b Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Wed, 4 Nov 2026 23:25:03 -0300 Subject: selection_pipe: runOne, a wrapper only its tests called, goes; the tests call runIn, which is private now and carries the doc comment Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge --- src/selection_pipe.zig | 31 ++++++++++--------------------- 1 file changed, 10 insertions(+), 21 deletions(-) (limited to 'src/selection_pipe.zig') diff --git a/src/selection_pipe.zig b/src/selection_pipe.zig index 7bb919e1..a03ab3eb 100644 --- a/src/selection_pipe.zig +++ b/src/selection_pipe.zig @@ -290,21 +290,6 @@ fn abandon(io: std.Io, child: std.process.Child) void { thread.detach(); } -/// Run one POSIX shell command with exact stdin, concurrently draining stdout -/// and stderr so a producer cannot deadlock against a full pipe. The caller is -/// already a worker. Nonzero exit, signal, timeout, IO failure, or either -/// output ceiling is reported as `null`; only an exited-zero command transfers -/// ownership of stdout to the caller. -pub fn runOne( - gpa: std.mem.Allocator, - io: std.Io, - command: []const u8, - cwd: []const u8, - input: []const u8, -) Outcome { - return runIn(gpa, io, "", command, cwd, input, 0, &.{}); -} - /// The commands running for a stoppable request (`Request.token`), so /// another thread can stop them: each is a process group of its own, which /// `stop` kills whole, a `sleep` under the shell too. @@ -367,8 +352,12 @@ pub fn newToken() u32 { } var next_token: std.atomic.Value(u32) = .init(1); -/// `runOne` through `shell -c` (/bin/sh when it is empty). -pub fn runIn( +/// Run one command through `shell -c` (/bin/sh when it is empty) with exact +/// stdin, draining stdout and stderr together so a producer cannot deadlock +/// against a full pipe. The caller is already a worker. Only a command that +/// exits 0 hands its stdout over (`.ok`); anything else is `.failed`, with +/// the command's stderr. +fn runIn( gpa: std.mem.Allocator, io: std.Io, shell: []const u8, @@ -568,7 +557,7 @@ test "native selection filters use the physical directory of an explicit OS moun const job = try Job.copy(gpa, .{ .id = 1, .command = "pwd", .cwd = declared, .inputs = &.{.{ .bytes = "" }} }); defer job.deinit(gpa); try std.testing.expectEqualStrings(directory, job.cwd); - switch (runOne(gpa, std.testing.io, job.command, job.cwd, "")) { + switch (runIn(gpa, std.testing.io, "", job.command, job.cwd, "", 0, &.{})) { .ok => |bytes| { defer gpa.free(bytes); try std.testing.expectEqualStrings(directory, std.mem.trimEnd(u8, bytes, "\n")); @@ -583,7 +572,7 @@ test "native selection filters use the physical directory of an explicit OS moun test "native pipe runner preserves stdin/stdout bytes and reports how it failed" { const gpa = std.testing.allocator; const io = std.testing.io; - const output = switch (runOne(gpa, io, "printf 'prefix:'; cat; printf '\\n'", "/tmp", "a\x00b\n")) { + const output = switch (runIn(gpa, io, "", "printf 'prefix:'; cat; printf '\\n'", "/tmp", "a\x00b\n", 0, &.{})) { .ok => |bytes| bytes, .failed => return error.PipeCommandFailed, }; @@ -593,7 +582,7 @@ test "native pipe runner preserves stdin/stdout bytes and reports how it failed" // A NONZERO EXIT COMES HOME WITH ITS REASON. The status and the command's // own stderr are the whole of what a human needs to fix a typo'd filter, // and both used to be freed on the floor. - switch (runOne(gpa, io, "echo trouble >&2; exit 7", "/tmp", "")) { + switch (runIn(gpa, io, "", "echo trouble >&2; exit 7", "/tmp", "", 0, &.{})) { .ok => |bytes| { gpa.free(bytes); return error.PipeShouldHaveFailed; @@ -615,7 +604,7 @@ test "native pipe runner preserves stdin/stdout bytes and reports how it failed" @memset(big, 'x'); big[0] = 'a'; big[1] = '\n'; - switch (runOne(gpa, io, "head -1", "/tmp", big)) { + switch (runIn(gpa, io, "", "head -1", "/tmp", big, 0, &.{})) { .ok => |bytes| { defer gpa.free(bytes); try std.testing.expectEqualSlices(u8, "a\n", bytes); -- cgit v1.3