1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-28 11:37:44 +00:00

Merge pull request #145 from Arcterus/fixes

du: fix for latest Rust
This commit is contained in:
Heather 2014-03-26 05:17:55 +03:00
commit 8aa9a7a5e2

View file

@ -39,10 +39,9 @@ struct Options {
// this takes `my_stat` to avoid having to stat files multiple times. // this takes `my_stat` to avoid having to stat files multiple times.
fn du(path: &Path, mut my_stat: FileStat, 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 stats = ~[];
let mut futures = ~[]; let mut futures = ~[];
let options = options_arc.get();
if my_stat.kind == TypeDirectory { if my_stat.kind == TypeDirectory {
let read = match fs::readdir(path) { let read = match fs::readdir(path) {
@ -57,7 +56,7 @@ fn du(path: &Path, mut my_stat: FileStat,
for f in read.move_iter() { for f in read.move_iter() {
let this_stat = safe_unwrap!(fs::lstat(&f)); let this_stat = safe_unwrap!(fs::lstat(&f));
if this_stat.kind == TypeDirectory { 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) })) futures.push(Future::spawn(proc() { du(&f, this_stat, oa_clone, depth + 1) }))
} else { } else {
my_stat.size += this_stat.size; 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 future in futures.mut_iter() {
for stat_arc in future.get().move_rev_iter() { for stat in future.get().move_rev_iter() {
let stat = stat_arc.get();
if !options.separate_dirs && stat.path.dir_path() == my_stat.path { if !options.separate_dirs && stat.path.dir_path() == my_stat.path {
my_stat.size += stat.size; my_stat.size += stat.size;
my_stat.unstable.blocks += stat.unstable.blocks; my_stat.unstable.blocks += stat.unstable.blocks;
} }
if options.max_depth == None || depth < options.max_depth.unwrap() { 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 iter = du(&path, stat, options_arc.clone(), 0).move_iter();
let (_, len) = iter.size_hint(); let (_, len) = iter.size_hint();
let len = len.unwrap(); let len = len.unwrap();
for (index, stat_arc) in iter.enumerate() { for (index, stat) in iter.enumerate() {
let stat = stat_arc.get();
let size = match matches.opt_present("apparent-size") { let size = match matches.opt_present("apparent-size") {
true => stat.unstable.nlink * stat.size, true => stat.unstable.nlink * stat.size,
// C's stat is such that each block is assume to be 512 bytes // 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!("{:<10} {}", convert_size(size), stat.path.display());
} }
print!("{}", line_separator); 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 // The last element will be the total size of the the path under
// path_str. We add it to the grand total. // path_str. We add it to the grand total.
grand_total += size; 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!("{:<10} total", convert_size(grand_total));
print!("{}", line_separator); print!("{}", line_separator);
} }