Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 10 additions & 14 deletions src/uu/tee/src/tee.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,22 +231,18 @@ fn copy(mut input: impl Read, mut output: impl Write) -> Result<usize> {
let mut len = 0;

loop {
let received = match input.read(&mut buffer) {
Ok(bytes_count) => bytes_count,
Err(e) if e.kind() == ErrorKind::Interrupted => continue,
match input.read(&mut buffer) {
Ok(0) => return Ok(len), // end of file
Ok(received) => {
output.write_all(&buffer[..received])?;
// flush the buffer to comply with POSIX requirement that
// `tee` does not buffer the input.
output.flush()?;
len += received;
}
Err(e) if e.kind() == ErrorKind::Interrupted => {}
Err(e) => return Err(e),
};

if received == 0 {
return Ok(len);
}

output.write_all(&buffer[0..received])?;

// We need to flush the buffer here to comply with POSIX requirement that
// `tee` does not buffer the input.
output.flush()?;
len += received;
}
}

Expand Down
Loading