-
Notifications
You must be signed in to change notification settings - Fork 103
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
First basic implementation of aggregation; symlinks are not handled yet
- Loading branch information
Sebastian Thiel
committed
Jun 1, 2019
1 parent
449f964
commit 638be3c
Showing
3 changed files
with
103 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,69 @@ | ||
extern crate failure; | ||
extern crate jwalk; | ||
|
||
use failure::Error; | ||
pub struct WalkOptions { | ||
pub threads: usize, | ||
} | ||
|
||
impl WalkOptions { | ||
pub fn iter_from_path(&self, path: &Path) -> WalkDir { | ||
WalkDir::new(path) | ||
.preload_metadata(true) | ||
.skip_hidden(false) | ||
.num_threads(self.threads) | ||
} | ||
} | ||
|
||
#[derive(Default)] | ||
pub struct WalkResult { | ||
pub num_errors: usize, | ||
} | ||
|
||
pub fn fun() -> Result<(), Error> { | ||
unimplemented!(); | ||
impl fmt::Display for WalkResult { | ||
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { | ||
write!(f, "Encountered {} IO errors", self.num_errors) | ||
} | ||
} | ||
|
||
mod aggregate { | ||
use crate::{WalkOptions, WalkResult}; | ||
use failure::Error; | ||
use std::io; | ||
use std::path::Path; | ||
|
||
pub fn aggregate( | ||
mut out: impl io::Write, | ||
options: WalkOptions, | ||
paths: impl IntoIterator<Item = impl AsRef<Path>>, | ||
) -> Result<WalkResult, Error> { | ||
let mut res = WalkResult::default(); | ||
for path in paths.into_iter() { | ||
let mut num_bytes = 0u64; | ||
for entry in options.iter_from_path(path.as_ref()) { | ||
match entry { | ||
Ok(entry) => { | ||
num_bytes += match entry.metadata { | ||
Some(Ok(m)) => m.len(), | ||
Some(Err(_)) => { | ||
res.num_errors += 1; | ||
0 | ||
} | ||
None => unreachable!( | ||
"we ask for metadata, so we at least have Some(Err(..)))" | ||
), | ||
}; | ||
} | ||
Err(_) => res.num_errors += 1, | ||
} | ||
} | ||
|
||
writeln!(out, "{}\t{}", num_bytes, path.as_ref().display())?; | ||
} | ||
Ok(res) | ||
} | ||
} | ||
|
||
pub use aggregate::aggregate; | ||
use jwalk::WalkDir; | ||
use std::fmt; | ||
use std::path::Path; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
1258947 . |