From f0e25e5537d06d176c0b9827da02b12b893f9261 Mon Sep 17 00:00:00 2001 From: bootandy Date: Tue, 13 Mar 2018 15:45:23 -0400 Subject: [PATCH] Fix edgecase for du on mac When du encounters a file that cannot be read it logs an error and continues to analysise the rest of the directory. This behaviour brings it inline with the original du. --- src/du/du.rs | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/src/du/du.rs b/src/du/du.rs index eda6755eb..59d3bb022 100644 --- a/src/du/du.rs +++ b/src/du/du.rs @@ -91,16 +91,23 @@ fn du(mut my_stat: Stat, options: &Options, depth: usize) -> Box match fs::symlink_metadata(entry.path()) { + Ok(_) => { + let this_stat = Stat::new(entry.path()); + if this_stat.is_dir { + futures.push(du(this_stat, options, depth + 1)); + } else { + my_stat.size += this_stat.size; + my_stat.blocks += this_stat.blocks; + if options.all { + stats.push(this_stat); + } + } + } + Err(error) => show_error!("{}", error), + }, + Err(error) => show_error!("{}", error), } } }