Skip to content

Commit 44a6430

Browse files
committed
tee: do not retry on EINTR
1 parent 53761c0 commit 44a6430

1 file changed

Lines changed: 11 additions & 18 deletions

File tree

src/uu/tee/src/tee.rs

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -249,26 +249,19 @@ enum Writer {
249249

250250
impl Writer {
251251
pub fn write_all(&mut self, buf: &[u8]) -> Result<()> {
252-
let mut buf = buf;
253-
while !buf.is_empty() {
254-
match self {
255-
Self::File(f) => match f.write(buf) {
256-
Ok(0) => return Err(Error::new(ErrorKind::WriteZero, "failed to write whole buffer")),
257-
Ok(n) => buf = &buf[n..],
258-
Err(e) => return Err(e),
259-
},
260-
Self::Stdout(s) => match s.write(buf) {
261-
Ok(0) => return Err(Error::new(ErrorKind::WriteZero, "failed to write whole buffer")),
262-
Ok(n) => {
263-
buf = &buf[n..];
264-
#[cfg(not(any(unix, target_os = "wasi")))]
265-
s.flush()?;
266-
}
267-
Err(e) => return Err(e),
268-
},
252+
use uucore::io::AsFdExt as _;
253+
match self {
254+
// File does not have line buffering
255+
Self::File(f) => f.write_all_no_retry(buf),
256+
#[cfg(any(unix, target_os = "wasi"))]
257+
Self::Stdout(s) => s.0.write_all_no_retry(buf),
258+
#[cfg(not(any(unix, target_os = "wasi")))]
259+
Self::Stdout(s) => {
260+
s.write_all(buf)?;
261+
// needs unsafe to remove buffering... flush after write_all to keep overhead minimal
262+
s.flush()
269263
}
270264
}
271-
Ok(())
272265
}
273266
}
274267

0 commit comments

Comments
 (0)