Skip to content

Commit

Permalink
Fix flushing data and reading data in forward_available
Browse files Browse the repository at this point in the history
  • Loading branch information
NobodyXu committed Sep 7, 2024
1 parent a7dbbfc commit 9d489ba
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions src/command_helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,6 @@ impl StderrForwarder {
fn forward_available(&mut self) -> bool {
if let Some((stderr, buffer)) = self.inner.as_mut() {
loop {
let old_data_end = buffer.len();

// For non-blocking we check to see if there is data available, so we should try to
// read at least that much. For blocking, always read at least the minimum amount.
#[cfg(not(feature = "parallel"))]
Expand Down Expand Up @@ -165,8 +163,7 @@ impl StderrForwarder {
buffer.resize(self.bytes_buffered + to_reserve, 0);
}

// Safety: stderr.read only writes to the spare part of the buffer, it never reads from it
match stderr.read(&buffer[self.bytes_buffered..]) {
match stderr.read(&mut buffer[self.bytes_buffered..]) {
Err(err) if err.kind() == std::io::ErrorKind::WouldBlock => {
// No data currently, yield back.
break false;
Expand All @@ -187,13 +184,13 @@ impl StderrForwarder {
}
if consumed > 0 && consumed < self.bytes_buffered {
// Remove the consumed bytes from buffer
bytes.copy_within(consumed.., 0);
buffer.copy_within(consumed.., 0);
}
self.bytes_buffered -= consumed;
}
res => {
// End of stream: flush remaining data and bail.
if old_data_end > 0 {
if self.bytes_buffered > 0 {
write_warning(&buffer[..self.bytes_buffered]);
}
if let Err(err) = res {
Expand Down

0 comments on commit 9d489ba

Please sign in to comment.