1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-08-02 14:07:46 +00:00

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.
This commit is contained in:
bootandy 2018-03-13 15:45:23 -04:00
parent fa0b7ed41b
commit f0e25e5537

View file

@ -91,16 +91,23 @@ fn du(mut my_stat: Stat, options: &Options, depth: usize) -> Box<DoubleEndedIter
}; };
for f in read.into_iter() { for f in read.into_iter() {
let entry = crash_if_err!(1, f); match f {
let this_stat = Stat::new(entry.path()); Ok(entry) => match fs::symlink_metadata(entry.path()) {
if this_stat.is_dir { Ok(_) => {
futures.push(du(this_stat, options, depth + 1)); let this_stat = Stat::new(entry.path());
} else { if this_stat.is_dir {
my_stat.size += this_stat.size; futures.push(du(this_stat, options, depth + 1));
my_stat.blocks += this_stat.blocks; } else {
if options.all { my_stat.size += this_stat.size;
stats.push(this_stat); my_stat.blocks += this_stat.blocks;
} if options.all {
stats.push(this_stat);
}
}
}
Err(error) => show_error!("{}", error),
},
Err(error) => show_error!("{}", error),
} }
} }
} }