|
@@ -1,14 +1,18 @@
|
|
use std::{fs, path::PathBuf, process, env};
|
|
use std::{fs, path::PathBuf, process, env};
|
|
|
|
|
|
fn find_target_dir(path: PathBuf) -> Result<bool, std::io::Error> {
|
|
fn find_target_dir(path: PathBuf) -> Result<bool, std::io::Error> {
|
|
|
|
+ let mut found_target_dir: bool = false;
|
|
|
|
+ let mut found_cargo_toml: bool = false;
|
|
for entry in fs::read_dir(path)? {
|
|
for entry in fs::read_dir(path)? {
|
|
let entry = entry?;
|
|
let entry = entry?;
|
|
let p = entry.path();
|
|
let p = entry.path();
|
|
if p.is_dir() && p.ends_with("target") {
|
|
if p.is_dir() && p.ends_with("target") {
|
|
- return Ok(true);
|
|
|
|
|
|
+ found_target_dir = true;
|
|
|
|
+ } else if p.is_file() && p.file_name().unwrap() == "Cargo.toml" {
|
|
|
|
+ found_cargo_toml = true;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- Ok(false)
|
|
|
|
|
|
+ Ok(found_target_dir && found_cargo_toml)
|
|
}
|
|
}
|
|
|
|
|
|
fn execute_clean(path: PathBuf) -> Result<(), std::io::Error> {
|
|
fn execute_clean(path: PathBuf) -> Result<(), std::io::Error> {
|
|
@@ -32,18 +36,8 @@ fn clean_in_dir(path: PathBuf) -> Result<u64, std::io::Error> {
|
|
cleaned += 1;
|
|
cleaned += 1;
|
|
} else {
|
|
} else {
|
|
// Maybe nested?
|
|
// Maybe nested?
|
|
- for ent in fs::read_dir(p)? {
|
|
|
|
- let ent = ent?;
|
|
|
|
- let p2 = ent.path();
|
|
|
|
- if p2.is_dir() {
|
|
|
|
- let needed = find_target_dir(p2.clone())?;
|
|
|
|
- if needed {
|
|
|
|
- println!(" => {}", p2.display());
|
|
|
|
- execute_clean(p2)?;
|
|
|
|
- cleaned += 1;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
|
|
+ let r = clean_in_dir(p)?;
|
|
|
|
+ cleaned += r;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -51,9 +45,13 @@ fn clean_in_dir(path: PathBuf) -> Result<u64, std::io::Error> {
|
|
}
|
|
}
|
|
|
|
|
|
fn main() -> Result<(), std::io::Error> {
|
|
fn main() -> Result<(), std::io::Error> {
|
|
- println!("Rust Pan");
|
|
|
|
|
|
+ println!("Sweeping...");
|
|
let cwd = env::current_dir()?;
|
|
let cwd = env::current_dir()?;
|
|
- let cleand = clean_in_dir(cwd)?;
|
|
|
|
- println!("Cleaned {} crates", cleand);
|
|
|
|
|
|
+ let cleaned = clean_in_dir(cwd)?;
|
|
|
|
+ if cleaned == 1 {
|
|
|
|
+ println!("Cleaned 1 crate");
|
|
|
|
+ } else {
|
|
|
|
+ println!("Cleaned {} crates", cleaned);
|
|
|
|
+ }
|
|
Ok(())
|
|
Ok(())
|
|
}
|
|
}
|