Skip to content

Commit

Permalink
add default order for the result
Browse files Browse the repository at this point in the history
  • Loading branch information
seamile committed Jan 9, 2023
1 parent ff41f9c commit 6fd165a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
7 changes: 7 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@ fn main() {
let n_thread = args.get_threads_num();
counters = walker::parallel_walk(directories, args.all_files, args.count_size, n_thread);
}

if args.count_size {
counters.sort_by(|c1, c2| c2.size().cmp(&c1.size()));
} else {
counters.sort_by(|c1, c2| c2.n_files.cmp(&c1.n_files));
}

Counter::output(&counters, args.count_size);
}

Expand Down
12 changes: 6 additions & 6 deletions src/walker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ pub type DirDetail = (DirList, Counter);

#[derive(Debug)]
pub struct Counter {
dirpath: PathBuf,
n_files: u64,
n_dirs: u64,
sz_map: SizeMap,
pub dirpath: PathBuf,
pub n_files: u64,
pub n_dirs: u64,
pub sz_map: SizeMap,
}

#[allow(unused)]
Expand All @@ -55,13 +55,13 @@ impl Counter {
return (blksz * (sz / blksz).ceil()) as u64;
}

pub fn total_size(&self) -> u64 {
pub fn size(&self) -> u64 {
self.sz_map.values().sum()
}

// Make "size" more readable
pub fn readable_size(&self) -> String {
let mut sz = self.total_size() as f64;
let mut sz = self.size() as f64;
let mut str_sz = String::new();

for unit in Self::SZ_UNIT {
Expand Down

0 comments on commit 6fd165a

Please sign in to comment.