Skip to content

Commit d75700a

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

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

src/uu/du/src/du.rs

Lines changed: 5 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)]
@@ -20,6 +20,7 @@ use std::path::{Path, PathBuf};
2020
use std::str::FromStr;
2121
use std::sync::mpsc;
2222
use std::thread;
23+
use std::{env, io};
2324
use thiserror::Error;
2425
use uucore::display::{Quotable, print_verbatim};
2526
use uucore::error::{FromIo, UError, UResult, USimpleError, set_exit_code};
@@ -888,7 +889,7 @@ impl StatPrinter {
888889
}
889890

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

893894
if let Some(md_time) = &self.time {
894895
if let Some(time) = metadata_get_time(&stat.metadata, *md_time) {
@@ -904,8 +905,8 @@ impl StatPrinter {
904905
}
905906
}
906907

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

910911
Ok(())
911912
}

0 commit comments

Comments
 (0)