Skip to content
Closed
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
35 changes: 23 additions & 12 deletions src/uu/tee/src/tee.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,19 +196,12 @@ impl MultiWriter {
let mut errors = 0;
let mode = self.output_error_mode;
self.writers.retain_mut(|writer| {
let res = (|| {
writer.inner.write_all(buf)?;
writer.inner.flush()
})();
match res {
Ok(()) => true,
Err(e) => {
if let Err(e) = process_error(mode, e, writer, &mut errors) {
aborted.get_or_insert(e);
}
writer
.write_flush(buf, mode, &mut errors)
.unwrap_or_else(|e| {
aborted.get_or_insert(e);
false
}
}
})
});
self.ignored_errors += errors;
aborted.map_or(
Expand All @@ -225,6 +218,24 @@ impl MultiWriter {
}
}

impl NamedWriter {
// this should be part of NamedWriter to support splice() fast-path easier
fn write_flush(
&mut self,
buf: &[u8],
mode: Option<OutputErrorMode>,
ignored_errors: &mut usize,
) -> Result<bool> {
match (|| {
self.inner.write_all(buf)?;
self.inner.flush()
})() {
Ok(()) => Ok(true),
Err(e) => process_error(mode, e, self, ignored_errors).map(|_| false),
}
}
}

fn process_error(
mode: Option<OutputErrorMode>,
e: Error,
Expand Down
Loading