From f1114968986ae6493ab097f51f02e1430346be5b Mon Sep 17 00:00:00 2001 From: Alex Muscar Date: Tue, 3 Feb 2026 20:29:09 +0000 Subject: [PATCH] du: don't panic when writing to stdout fails This fixes https://github.com/uutils/coreutils/issues/10560 --- src/uu/du/src/du.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/uu/du/src/du.rs b/src/uu/du/src/du.rs index d8bfd4446a1..8bbe0e9de8f 100644 --- a/src/uu/du/src/du.rs +++ b/src/uu/du/src/du.rs @@ -8,10 +8,9 @@ use clap::{Arg, ArgAction, ArgMatches, Command, builder::PossibleValue}; use glob::Pattern; use std::collections::HashSet; -use std::env; use std::ffi::{OsStr, OsString}; use std::fs::{self, DirEntry, File, Metadata}; -use std::io::{BufRead, BufReader, stdout}; +use std::io::{BufRead, BufReader, Write, stdout}; #[cfg(not(windows))] use std::os::unix::fs::MetadataExt; #[cfg(windows)] @@ -20,6 +19,7 @@ use std::path::{Path, PathBuf}; use std::str::FromStr; use std::sync::mpsc; use std::thread; +use std::{env, io}; use thiserror::Error; use uucore::display::{Quotable, print_verbatim}; use uucore::error::{FromIo, UError, UResult, USimpleError, set_exit_code}; @@ -884,7 +884,7 @@ impl StatPrinter { } fn print_stat(&self, stat: &Stat, size: u64) -> UResult<()> { - print!("{}\t", self.convert_size(size)); + write!(io::stdout(), "{}\t", self.convert_size(size))?; if let Some(md_time) = &self.time { if let Some(time) = metadata_get_time(&stat.metadata, *md_time) { @@ -900,8 +900,8 @@ impl StatPrinter { } } - print_verbatim(&stat.path).unwrap(); - print!("{}", self.line_ending); + print_verbatim(&stat.path)?; + write!(io::stdout(), "{}", self.line_ending)?; Ok(()) }