Skip to content

Commit

Permalink
Never return an error after a partial write
Browse files Browse the repository at this point in the history
If LineWriter fails to flush, return the number of bytes written instead
of an error.

Fixes #32085
  • Loading branch information
Stebalien committed Mar 7, 2016
1 parent 388ccda commit 6ea8222
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/libstd/io/buffered.rs
Expand Up @@ -762,8 +762,10 @@ impl<W: Write> Write for LineWriter<W> {
match memchr::memrchr(b'\n', buf) {
Some(i) => {
let n = try!(self.inner.write(&buf[..i + 1]));
if n != i + 1 { return Ok(n) }
try!(self.inner.flush());
if n != i + 1 || self.inner.flush().is_err() {
// Do not return errors on partial writes.
return Ok(n);
}
self.inner.write(&buf[i + 1..]).map(|i| n + i)
}
None => self.inner.write(buf),
Expand Down

0 comments on commit 6ea8222

Please sign in to comment.