|
|
@@ -2,13 +2,24 @@ use std::{fs, process, path::PathBuf, time::SystemTime};
|
|
|
use anyhow::Result as anyResult;
|
|
|
|
|
|
pub const SECS_IN_DAY: u64 = 86400;
|
|
|
+pub const ECHO_PATHS: bool = false;
|
|
|
|
|
|
pub fn find_target_dir(path: PathBuf) -> anyResult<bool> {
|
|
|
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 p = entry.path();
|
|
|
+ let n = entry.file_name().into_string().ok().unwrap_or(String::from(".derp"));
|
|
|
+ if ECHO_PATHS && n == ".derp" {
|
|
|
+ println!("(find_target_dir) : {} : path = {} - file_name derp!", path.to_str().unwrap_or(&String::from("derp!")), p.to_str().unwrap_or(&String::from("derp!")));
|
|
|
+ }
|
|
|
+ if n.starts_with(".") {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ if ECHO_PATHS {
|
|
|
+ println!("(find_target_dir) : {} : path = {}", path.to_str().unwrap_or(&String::from("derp!")), p.to_str().unwrap_or(&String::from("derp!")));
|
|
|
+ }
|
|
|
if p.is_dir() && p.ends_with("target") {
|
|
|
found_target_dir = true;
|
|
|
} else if p.is_file() && p.file_name().unwrap() == "Cargo.toml" {
|
|
|
@@ -24,9 +35,19 @@ pub fn find_newest_file(path: PathBuf) -> anyResult<PathBuf> {
|
|
|
for entry in fs::read_dir(&path)? {
|
|
|
let entry = entry?;
|
|
|
let p = entry.path();
|
|
|
+ let n = entry.file_name().into_string().ok().unwrap_or(String::from(".derp"));
|
|
|
+ if ECHO_PATHS && n == ".derp" {
|
|
|
+ println!("(find_newest_file) : {} : path = {} - file_name derp!", path.to_str().unwrap_or(&String::from("derp!")), p.to_str().unwrap_or(&String::from("derp!")));
|
|
|
+ }
|
|
|
+ if n.starts_with(".") {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
if !p.is_file() {
|
|
|
continue;
|
|
|
}
|
|
|
+ if ECHO_PATHS {
|
|
|
+ println!("(find_newest_file) : {} : path = {}", path.to_str().unwrap_or(&String::from("derp!")), p.to_str().unwrap_or(&String::from("derp!")));
|
|
|
+ }
|
|
|
let meta = entry.metadata()?;
|
|
|
let modif = meta.modified()?;
|
|
|
let access = meta.accessed()?;
|
|
|
@@ -59,9 +80,19 @@ pub fn execute_clean(path: PathBuf) -> anyResult<()> {
|
|
|
|
|
|
pub fn clean_in_dir(path: PathBuf, forced: bool, days: u64) -> anyResult<u64> {
|
|
|
let mut cleaned: u64 = 0;
|
|
|
- for entry in fs::read_dir(path)? {
|
|
|
+ for entry in fs::read_dir(&path)? {
|
|
|
let entry = entry?;
|
|
|
let p = entry.path();
|
|
|
+ let n = entry.file_name().into_string().ok().unwrap_or(String::from(".derp"));
|
|
|
+ if ECHO_PATHS && n == ".derp" {
|
|
|
+ println!("(clean_in_dir) : path={} forced={} days={} : path = {} - file_name derp!", path.to_str().unwrap_or(&String::from("derp!")), forced, days, p.to_str().unwrap_or(&String::from("derp!")));
|
|
|
+ }
|
|
|
+ if n.starts_with(".") {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ if ECHO_PATHS {
|
|
|
+ println!("(clean_in_dir) : path={} forced={} days={} : path = {}", path.to_str().unwrap_or(&String::from("derp!")), forced, days, p.to_str().unwrap_or(&String::from("derp!")));
|
|
|
+ }
|
|
|
if p.is_dir() {
|
|
|
let needed = find_target_dir(p.clone())?;
|
|
|
if needed {
|