Skip to content

Commit a6b071b

Browse files
committed
Add total_size function to estimator module
1 parent 17b1253 commit a6b071b

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

src/crufty/estimator.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,15 @@ use walkdir::WalkDir;
44

55
use super::types::{ArtifactCandidate, Size};
66

7+
pub fn total_size(artifacts: &[ArtifactCandidate]) -> u64 {
8+
artifacts.iter().fold(0, |acc, artifact| {
9+
match &artifact.size {
10+
Size::UnknownSize => acc,
11+
Size::KnownSize(size) => acc + size,
12+
}
13+
})
14+
}
15+
716
pub fn estimate(artifact: &mut ArtifactCandidate) -> &ArtifactCandidate {
817
let size = estimate_path(&artifact.path);
918
artifact.size = size;
@@ -18,7 +27,7 @@ fn estimate_path(path: &PathBuf) -> Size {
1827
}
1928

2029
fn calculate_dir_size(path: &PathBuf) -> std::io::Result<u64> {
21-
let mut total_size = 0;
30+
let mut total = 0;
2231

2332
for entry in WalkDir::new(path)
2433
.follow_links(false)
@@ -27,11 +36,11 @@ fn calculate_dir_size(path: &PathBuf) -> std::io::Result<u64> {
2736
.filter(|e| e.file_type().is_file())
2837
{
2938
if let Ok(metadata) = fs::metadata(entry.path()) {
30-
total_size += metadata.len();
39+
total += metadata.len();
3140
}
3241
}
3342

34-
Ok(total_size)
43+
Ok(total)
3544
}
3645

3746
#[cfg(test)]

0 commit comments

Comments
 (0)