Skip to content

Commit e90d61f

Browse files
author
Alex Muscar
committed
du: don't panic when writing to stdout fails
This fixes #10560
1 parent ba1afb0 commit e90d61f

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/uu/du/src/du.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use rustc_hash::FxHashSet as HashSet;
1111
use std::env;
1212
use std::ffi::{OsStr, OsString};
1313
use std::fs::{self, DirEntry, File, Metadata};
14-
use std::io::{BufRead, BufReader, stdout};
14+
use std::io::{BufRead, BufReader, Write, stdout};
1515
#[cfg(not(windows))]
1616
use std::os::unix::fs::MetadataExt;
1717
#[cfg(windows)]
@@ -888,7 +888,7 @@ impl StatPrinter {
888888
}
889889

890890
fn print_stat(&self, stat: &Stat, size: u64) -> UResult<()> {
891-
print!("{}\t", self.convert_size(size));
891+
write!(stdout(), "{}\t", self.convert_size(size))?;
892892

893893
if let Some(md_time) = &self.time {
894894
if let Some(time) = metadata_get_time(&stat.metadata, *md_time) {
@@ -904,8 +904,8 @@ impl StatPrinter {
904904
}
905905
}
906906

907-
print_verbatim(&stat.path).unwrap();
908-
print!("{}", self.line_ending);
907+
print_verbatim(&stat.path)?;
908+
write!(stdout(), "{}", self.line_ending)?;
909909

910910
Ok(())
911911
}

0 commit comments

Comments
 (0)