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
21 changes: 3 additions & 18 deletions src/uu/tee/src/tee.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,6 @@ impl MultiWriter {
Ok(0) => return Ok(()), // end of file
Ok(received) => {
self.write_all(&buffer[..received])?;
self.flush()?; // avoid buffering
}
Err(e) if e.kind() != ErrorKind::Interrupted => return Err(e),
_ => {}
Expand All @@ -177,8 +176,6 @@ impl MultiWriter {
Ok(0) => return Ok(()), // end of file
Ok(received) => {
self.write_all(&buffer[..received])?;
// avoid buffering
self.flush()?;
}
Err(e) if e.kind() != ErrorKind::Interrupted => return Err(e),
_ => {}
Expand Down Expand Up @@ -230,6 +227,7 @@ impl Write for MultiWriter {
self.writers.retain_mut(|writer| {
writer
.write_all(buf)
.and_then(|_| writer.flush()) // avoid buffering
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This pattern is unidiomatic, see #11919

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you provide more detail?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Specifically the unused arg for and_then

Copy link
Copy Markdown
Contributor Author

@oech3 oech3 Apr 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But this very reasonable way to chain flush. Is there any alternative without a bunch of dupes?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See #11893

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let res = (|| {
    writer.write_all(buf)?;
    writer.flush()?;
    Ok(())
})();

is long...

Copy link
Copy Markdown
Contributor

@xtqqczze xtqqczze Apr 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can be reduced to:

(|| {
    writer.write_all(buf)?;
    writer.flush()
})()

Once try_blocks are stabilised, this becomes cleaner:

try {
    writer.write_all(buf)?;
    writer.flush()?;
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we keep chain with the form?

.map_err(|f| {
let _ = process_error(mode.as_ref(), f, writer, &mut errors)
.map_err(|e| aborted.get_or_insert(e));
Expand All @@ -248,22 +246,9 @@ impl Write for MultiWriter {
Ok(buf.len())
}
}

// merged into write
fn flush(&mut self) -> Result<()> {
let mut aborted = None;
let mode = self.output_error_mode.clone();
let mut errors = 0;
self.writers.retain_mut(|writer| {
writer
.flush()
.map_err(|f| {
let _ = process_error(mode.as_ref(), f, writer, &mut errors)
.map_err(|e| aborted.get_or_insert(e));
})
.is_ok()
});
self.ignored_errors += errors;
aborted.map_or(Ok(()), Err)
Ok(())
}
}

Expand Down
Loading