Skip to content

Commit 8bd888a

Browse files
authored
tee: remove dummy definition & unused return (#11923)
1 parent 0366d3c commit 8bd888a

File tree

1 file changed

+24
-34
lines changed

1 file changed

+24
-34
lines changed

src/uu/tee/src/tee.rs

Lines changed: 24 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -162,9 +162,7 @@ impl MultiWriter {
162162
// fast-path for small input
163163
match input.read(&mut buffer) {
164164
Ok(0) => return Ok(()), // end of file
165-
Ok(received) => {
166-
self.write_all(&buffer[..received])?;
167-
}
165+
Ok(received) => self.write_flush(&buffer[..received])?,
168166
Err(e) if e.kind() != ErrorKind::Interrupted => return Err(e),
169167
_ => {}
170168
}
@@ -174,9 +172,7 @@ impl MultiWriter {
174172
loop {
175173
match input.read(&mut buffer) {
176174
Ok(0) => return Ok(()), // end of file
177-
Ok(received) => {
178-
self.write_all(&buffer[..received])?;
179-
}
175+
Ok(received) => self.write_flush(&buffer[..received])?,
180176
Err(e) if e.kind() != ErrorKind::Interrupted => return Err(e),
181177
_ => {}
182178
}
@@ -194,33 +190,8 @@ impl MultiWriter {
194190
fn error_occurred(&self) -> bool {
195191
self.ignored_errors != 0
196192
}
197-
}
198-
199-
fn process_error(
200-
mode: Option<OutputErrorMode>,
201-
e: Error,
202-
writer: &NamedWriter,
203-
ignored_errors: &mut usize,
204-
) -> Result<()> {
205-
let ignore_pipe = matches!(
206-
mode,
207-
None | Some(OutputErrorMode::WarnNoPipe) | Some(OutputErrorMode::ExitNoPipe)
208-
);
209-
210-
if ignore_pipe && e.kind() == ErrorKind::BrokenPipe {
211-
return Ok(());
212-
}
213-
let _ = writeln!(stderr(), "{}: {e}", writer.name.maybe_quote());
214-
if let Some(OutputErrorMode::Exit | OutputErrorMode::ExitNoPipe) = mode {
215-
Err(e)
216-
} else {
217-
*ignored_errors += 1;
218-
Ok(())
219-
}
220-
}
221193

222-
impl Write for MultiWriter {
223-
fn write(&mut self, buf: &[u8]) -> Result<usize> {
194+
fn write_flush(&mut self, buf: &[u8]) -> Result<()> {
224195
let mut aborted = None;
225196
let mut errors = 0;
226197
let mode = self.output_error_mode;
@@ -247,13 +218,32 @@ impl Write for MultiWriter {
247218
// `copy`
248219
Err(Error::from(ErrorKind::Other))
249220
} else {
250-
Ok(buf.len())
221+
Ok(())
251222
},
252223
Err,
253224
)
254225
}
226+
}
255227

256-
fn flush(&mut self) -> Result<()> {
228+
fn process_error(
229+
mode: Option<OutputErrorMode>,
230+
e: Error,
231+
writer: &NamedWriter,
232+
ignored_errors: &mut usize,
233+
) -> Result<()> {
234+
let ignore_pipe = matches!(
235+
mode,
236+
None | Some(OutputErrorMode::WarnNoPipe) | Some(OutputErrorMode::ExitNoPipe)
237+
);
238+
239+
if ignore_pipe && e.kind() == ErrorKind::BrokenPipe {
240+
return Ok(());
241+
}
242+
let _ = writeln!(stderr(), "{}: {e}", writer.name.maybe_quote());
243+
if let Some(OutputErrorMode::Exit | OutputErrorMode::ExitNoPipe) = mode {
244+
Err(e)
245+
} else {
246+
*ignored_errors += 1;
257247
Ok(())
258248
}
259249
}

0 commit comments

Comments
 (0)