Actually buffer subproc output

This commit is contained in:
Zack Radisic
2024-02-22 17:45:28 -08:00
parent a687eb11a0
commit d0ee302e37
2 changed files with 7 additions and 2 deletions

View File

@@ -3625,7 +3625,8 @@ pub const Interpreter = struct {
log("cmd ({x}) close buffered stdout", .{@intFromPtr(this)});
if (this.io.stdout == .std and this.io.stdout.std.captured != null and !this.node.redirect.stdout) {
var buf = this.io.stdout.std.captured.?;
buf.append(bun.default_allocator, this.exec.subproc.child.stdout.pipe.slice()) catch bun.outOfMemory();
const the_slice = this.exec.subproc.child.stdout.pipe.slice();
buf.append(bun.default_allocator, the_slice) catch bun.outOfMemory();
}
this.exec.subproc.buffered_closed.close(this, .{ .stdout = &this.exec.subproc.child.stdout });
this.exec.subproc.child.closeIO(.stdout);

View File

@@ -683,6 +683,7 @@ pub const PipeReader = struct {
stdio_result: StdioResult,
captured_writer: CapturedWriter = .{},
out_type: bun.shell.subproc.ShellSubprocess.OutKind,
buffered: bun.ByteList = .{},
ref_count: u32 = 1,
pub usingnamespace bun.NewRefCounted(PipeReader, deinit);
@@ -819,6 +820,7 @@ pub const PipeReader = struct {
pub fn onReadChunk(ptr: *anyopaque, chunk: []const u8, has_more: bun.io.ReadState) bool {
var this: *PipeReader = @ptrCast(@alignCast(ptr));
this.buffered.append(bun.default_allocator, chunk) catch bun.outOfMemory();
log("PipeReader onReadChunk({x}, ...)", .{@intFromPtr(this)});
if (this.captured_writer.writer.getPoll() == null) {
this.captured_writer.writer.handle = .{ .poll = Async.FilePoll.init(this.eventLoop(), if (this.out_type == .stdout) bun.STDOUT_FD else bun.STDERR_FD, .{}, @TypeOf(this.captured_writer.writer), &this.captured_writer.writer) };
@@ -881,7 +883,7 @@ pub const PipeReader = struct {
}
pub fn slice(this: *PipeReader) []const u8 {
return this.reader.buffer().items[0..];
return this.buffered.slice();
}
pub fn toOwnedSlice(this: *PipeReader) []u8 {
@@ -980,6 +982,8 @@ pub const PipeReader = struct {
bun.default_allocator.free(this.state.done);
}
this.buffered.deinitWithAllocator(bun.default_allocator);
this.reader.deinit();
this.destroy();
}