Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make the recursive option of cargo-sweep recurse past Cargo directories #78

Merged
merged 8 commits into from
Feb 5, 2023
3 changes: 2 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,8 @@ fn find_cargo_projects(root: &Path, include_hidden: bool) -> Vec<PathBuf> {
}
if let Some(target_directory) = is_cargo_root(entry.path()) {
target_paths.insert(target_directory);
iter.skip_current_dir(); // no reason to look at the src and such
// Previously cargo-sweep skipped subdirectories here, but it is valid for
// subdirectories to contain cargo roots.
}
}
}
Expand Down
23 changes: 21 additions & 2 deletions src/util.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/// Formats a number of bytes into the closest binary SI unit, i.e KiB, MiB etc.
pub fn format_bytes(bytes: u64) -> String {
let prefixes = ["bytes", "KiB", "MiB", "GiB", "TiB"];
let prefixes = ["B", "KiB", "MiB", "GiB", "TiB"];
let mut bytes = bytes as f64;
for prefix in prefixes.iter() {
if bytes < 1024. {
Expand All @@ -18,7 +18,26 @@ mod tests {
#[test]
fn test_format_bytes() {
assert_eq!(format_bytes(1024), "1.00 KiB");
assert_eq!(format_bytes(1023), "1023.00 bytes");
assert_eq!(format_bytes(1023), "1023.00 B");
assert_eq!(format_bytes(500 * 1024 * 1024), "500.00 MiB");

// Assert that the human-size crate can parse the output from cargo-sweep
assert_eq!("1.00 B".parse::<human_size::Size>().unwrap().to_bytes(), 1);
assert_eq!(
"1.00 KiB".parse::<human_size::Size>().unwrap().to_bytes(),
1024
);
assert_eq!(
"1.00 MiB".parse::<human_size::Size>().unwrap().to_bytes(),
1024 * 1024
);
assert_eq!(
"1.00 GiB".parse::<human_size::Size>().unwrap().to_bytes(),
1024 * 1024 * 1024
);
assert_eq!(
"1.00 TiB".parse::<human_size::Size>().unwrap().to_bytes(),
1024 * 1024 * 1024 * 1024
);
}
}
Loading