summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSebastian Thiel <sthiel@thoughtworks.com>2019-06-01 13:56:07 +0530
committerSebastian Thiel <sthiel@thoughtworks.com>2019-06-01 13:56:33 +0530
commit9ba5a348c67a898abb0ae648e686da48649a33df (patch)
tree6280fb3905bcbf2ecdfebf9c2f18fd5c2e9b4623
parent8b2ef49bf9f37d0e126fa68115175fe2cf82aaf5 (diff)
Make explicit that Sorting is disabled during aggregation; more spacing
-rw-r--r--src/aggregate.rs6
-rw-r--r--src/common.rs20
2 files changed, 15 insertions, 11 deletions
diff --git a/src/aggregate.rs b/src/aggregate.rs
index d2912a2..6e49a5a 100644
--- a/src/aggregate.rs
+++ b/src/aggregate.rs
@@ -1,4 +1,4 @@
-use crate::{WalkOptions, WalkResult};
+use crate::{Sorting, WalkOptions, WalkResult};
use failure::Error;
use std::borrow::Cow;
use std::{io, path::Path};
@@ -16,7 +16,7 @@ pub fn aggregate(
num_roots += 1;
let mut num_bytes = 0u64;
let mut num_errors = 0u64;
- for entry in options.iter_from_path(path.as_ref()) {
+ for entry in options.iter_from_path(path.as_ref(), Sorting::None) {
match entry {
Ok(entry) => {
num_bytes += match entry.metadata {
@@ -60,7 +60,7 @@ fn write_path(
) -> Result<(), io::Error> {
writeln!(
out,
- "{}\t{}{}",
+ "{:8}\t{}{}",
options.format_bytes(num_bytes),
path.as_ref().display(),
if num_errors == 0 {
diff --git a/src/common.rs b/src/common.rs
index afeaf1f..91a24f1 100644
--- a/src/common.rs
+++ b/src/common.rs
@@ -1,5 +1,5 @@
use jwalk::WalkDir;
-use std::{fmt, path::Path};
+use std::path::Path;
pub enum ByteFormat {
Metric,
@@ -7,6 +7,11 @@ pub enum ByteFormat {
Bytes,
}
+pub enum Sorting {
+ None,
+ Alphabetical,
+}
+
pub struct WalkOptions {
pub threads: usize,
pub format: ByteFormat,
@@ -25,9 +30,14 @@ impl WalkOptions {
.get_appropriate_unit(binary)
.format(2)
}
- pub fn iter_from_path(&self, path: &Path) -> WalkDir {
+
+ pub fn iter_from_path(&self, path: &Path, sort: Sorting) -> WalkDir {
WalkDir::new(path)
.preload_metadata(true)
+ .sort(match sort {
+ Sorting::Alphabetical => true,
+ Sorting::None => false,
+ })
.skip_hidden(false)
.num_threads(self.threads)
}
@@ -37,9 +47,3 @@ impl WalkOptions {
pub struct WalkResult {
pub num_errors: u64,
}
-
-impl fmt::Display for WalkResult {
- fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
- write!(f, "Encountered {} IO error(s)", self.num_errors)
- }
-}