Skip to content

Commit 5c9327a

Browse files
committed
tee: move fn write_flush to NamedWriter
1 parent a6a7b12 commit 5c9327a

1 file changed

Lines changed: 24 additions & 12 deletions

File tree

src/uu/tee/src/tee.rs

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -196,19 +196,12 @@ impl MultiWriter {
196196
let mut errors = 0;
197197
let mode = self.output_error_mode;
198198
self.writers.retain_mut(|writer| {
199-
let res = (|| {
200-
writer.inner.write_all(buf)?;
201-
writer.inner.flush()
202-
})();
203-
match res {
204-
Ok(()) => true,
205-
Err(e) => {
206-
if let Err(e) = process_error(mode, e, writer, &mut errors) {
207-
aborted.get_or_insert(e);
208-
}
199+
writer
200+
.write_flush(buf, mode, &mut errors)
201+
.unwrap_or_else(|e| {
202+
aborted.get_or_insert(e);
209203
false
210-
}
211-
}
204+
})
212205
});
213206
self.ignored_errors += errors;
214207
aborted.map_or(
@@ -225,6 +218,25 @@ impl MultiWriter {
225218
}
226219
}
227220

221+
impl NamedWriter {
222+
// this should be part of NamedWriter to support splice() fast-path easier
223+
fn write_flush(
224+
&mut self,
225+
buf: &[u8],
226+
mode: Option<OutputErrorMode>,
227+
ignored_errors: &mut usize,
228+
) -> Result<bool> {
229+
match (|| {
230+
self.inner.write_all(buf)?;
231+
self.inner.flush()
232+
})() {
233+
Ok(()) => Ok(true),
234+
Err(e) => process_error(mode, e, self, ignored_errors).map(|_| false),
235+
}
236+
}
237+
}
238+
239+
#[inline]
228240
fn process_error(
229241
mode: Option<OutputErrorMode>,
230242
e: Error,

0 commit comments

Comments
 (0)