瀏覽代碼

Added debug bool, Ignore hidden

This fixes a issue where rustpan could not be run from a Linux user's
home directory (os: permission denied)

By ignoring hidden files and directories we also eliminate directories
that should already be ignored (like .git, .cargo, .cache, and more)

To assist in verifing we are ignoring hidden files and directories, a
ECHO_PATHS bool was introduced (this should be compiled out of the final
binary)
apollo 2 天之前
父節點
當前提交
01fae74643
共有 1 個文件被更改,包括 33 次插入2 次删除
  1. 33 2
      src/lib.rs

+ 33 - 2
src/lib.rs

@@ -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 {