mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-08-01 05:27:45 +00:00
Merge pull request #1157 from bootandy/master
Fix edge case for du on mac
This commit is contained in:
commit
3015a19230
1 changed files with 81 additions and 70 deletions
27
src/du/du.rs
27
src/du/du.rs
|
@ -16,7 +16,7 @@ extern crate uucore;
|
|||
|
||||
use std::fs;
|
||||
use std::iter;
|
||||
use std::io::{stderr, Write};
|
||||
use std::io::{stderr, Result, Write};
|
||||
use std::os::unix::fs::MetadataExt;
|
||||
use std::path::PathBuf;
|
||||
use time::Timespec;
|
||||
|
@ -54,9 +54,9 @@ struct Stat {
|
|||
}
|
||||
|
||||
impl Stat {
|
||||
fn new(path: PathBuf) -> Stat {
|
||||
let metadata = safe_unwrap!(fs::symlink_metadata(&path));
|
||||
Stat {
|
||||
fn new(path: PathBuf) -> Result<Stat> {
|
||||
let metadata = fs::symlink_metadata(&path)?;
|
||||
Ok(Stat {
|
||||
path: path,
|
||||
is_dir: metadata.is_dir(),
|
||||
size: metadata.len(),
|
||||
|
@ -65,7 +65,7 @@ impl Stat {
|
|||
created: metadata.mtime() as u64,
|
||||
accessed: metadata.atime() as u64,
|
||||
modified: metadata.mtime() as u64,
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -91,8 +91,9 @@ fn du(mut my_stat: Stat, options: &Options, depth: usize) -> Box<DoubleEndedIter
|
|||
};
|
||||
|
||||
for f in read.into_iter() {
|
||||
let entry = crash_if_err!(1, f);
|
||||
let this_stat = Stat::new(entry.path());
|
||||
match f {
|
||||
Ok(entry) => match Stat::new(entry.path()) {
|
||||
Ok(this_stat) => {
|
||||
if this_stat.is_dir {
|
||||
futures.push(du(this_stat, options, depth + 1));
|
||||
} else {
|
||||
|
@ -103,6 +104,11 @@ fn du(mut my_stat: Stat, options: &Options, depth: usize) -> Box<DoubleEndedIter
|
|||
}
|
||||
}
|
||||
}
|
||||
Err(error) => show_error!("{}", error),
|
||||
},
|
||||
Err(error) => show_error!("{}", error),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
stats.extend(
|
||||
|
@ -327,7 +333,9 @@ Try '{} --help' for more information.",
|
|||
let mut grand_total = 0;
|
||||
for path_str in strs.into_iter() {
|
||||
let path = PathBuf::from(path_str);
|
||||
let iter = du(Stat::new(path), &options, 0).into_iter();
|
||||
match Stat::new(path) {
|
||||
Ok(stat) => {
|
||||
let iter = du(stat, &options, 0).into_iter();
|
||||
let (_, len) = iter.size_hint();
|
||||
let len = len.unwrap();
|
||||
for (index, stat) in iter.enumerate() {
|
||||
|
@ -390,6 +398,9 @@ Try '{} --help' for more information.",
|
|||
}
|
||||
}
|
||||
}
|
||||
Err(error) => show_error!("{}", error),
|
||||
}
|
||||
}
|
||||
|
||||
if options.total {
|
||||
print!("{}\ttotal", convert_size(grand_total));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue