mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 03:27:44 +00:00
commit
8aa9a7a5e2
1 changed files with 7 additions and 10 deletions
17
du/du.rs
17
du/du.rs
|
@ -39,10 +39,9 @@ struct Options {
|
|||
|
||||
// this takes `my_stat` to avoid having to stat files multiple times.
|
||||
fn du(path: &Path, mut my_stat: FileStat,
|
||||
options_arc: Arc<Options>, depth: uint) -> ~[Arc<FileStat>] {
|
||||
options: Arc<Options>, depth: uint) -> ~[Arc<FileStat>] {
|
||||
let mut stats = ~[];
|
||||
let mut futures = ~[];
|
||||
let options = options_arc.get();
|
||||
|
||||
if my_stat.kind == TypeDirectory {
|
||||
let read = match fs::readdir(path) {
|
||||
|
@ -57,7 +56,7 @@ fn du(path: &Path, mut my_stat: FileStat,
|
|||
for f in read.move_iter() {
|
||||
let this_stat = safe_unwrap!(fs::lstat(&f));
|
||||
if this_stat.kind == TypeDirectory {
|
||||
let oa_clone = options_arc.clone();
|
||||
let oa_clone = options.clone();
|
||||
futures.push(Future::spawn(proc() { du(&f, this_stat, oa_clone, depth + 1) }))
|
||||
} else {
|
||||
my_stat.size += this_stat.size;
|
||||
|
@ -70,14 +69,13 @@ fn du(path: &Path, mut my_stat: FileStat,
|
|||
}
|
||||
|
||||
for future in futures.mut_iter() {
|
||||
for stat_arc in future.get().move_rev_iter() {
|
||||
let stat = stat_arc.get();
|
||||
for stat in future.get().move_rev_iter() {
|
||||
if !options.separate_dirs && stat.path.dir_path() == my_stat.path {
|
||||
my_stat.size += stat.size;
|
||||
my_stat.unstable.blocks += stat.unstable.blocks;
|
||||
}
|
||||
if options.max_depth == None || depth < options.max_depth.unwrap() {
|
||||
stats.push(stat_arc.clone());
|
||||
stats.push(stat.clone());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -315,8 +313,7 @@ Try '{program} --help' for more information.", s, program = program);
|
|||
let iter = du(&path, stat, options_arc.clone(), 0).move_iter();
|
||||
let (_, len) = iter.size_hint();
|
||||
let len = len.unwrap();
|
||||
for (index, stat_arc) in iter.enumerate() {
|
||||
let stat = stat_arc.get();
|
||||
for (index, stat) in iter.enumerate() {
|
||||
let size = match matches.opt_present("apparent-size") {
|
||||
true => stat.unstable.nlink * stat.size,
|
||||
// C's stat is such that each block is assume to be 512 bytes
|
||||
|
@ -351,7 +348,7 @@ Try '{program} --help' for more information.", s, program = program);
|
|||
print!("{:<10} {}", convert_size(size), stat.path.display());
|
||||
}
|
||||
print!("{}", line_separator);
|
||||
if options_arc.get().total && index == (len - 1) {
|
||||
if options_arc.total && index == (len - 1) {
|
||||
// The last element will be the total size of the the path under
|
||||
// path_str. We add it to the grand total.
|
||||
grand_total += size;
|
||||
|
@ -359,7 +356,7 @@ Try '{program} --help' for more information.", s, program = program);
|
|||
}
|
||||
}
|
||||
|
||||
if options_arc.get().total {
|
||||
if options_arc.total {
|
||||
print!("{:<10} total", convert_size(grand_total));
|
||||
print!("{}", line_separator);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue