From 96ba96ba1b1b075e899ce8ad9af6c2114f425316 Mon Sep 17 00:00:00 2001 From: mtkennerly Date: Tue, 19 Nov 2024 20:39:31 -0500 Subject: [PATCH] #419: Add game context to walkdir error logs --- src/path.rs | 6 +++--- src/prelude.rs | 4 ++-- src/scan.rs | 2 +- src/scan/layout.rs | 18 +++++++++--------- 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/path.rs b/src/path.rs index 147dda4..6969e9b 100644 --- a/src/path.rs +++ b/src/path.rs @@ -726,7 +726,7 @@ impl StrictPath { return Err(e); } - if let Err(e) = target_file.unset_readonly() { + if let Err(e) = target_file.unset_readonly(context) { log::warn!( "[{context}] failed to unset read-only on target: {} | {e}", target_file.raw() @@ -786,7 +786,7 @@ impl StrictPath { } } - pub fn unset_readonly(&self) -> Result<(), AnyError> { + pub fn unset_readonly(&self, context: &str) -> Result<(), AnyError> { let subject = self.as_std_path_buf()?; if self.is_file() { let mut perms = std::fs::metadata(&subject)?.permissions(); @@ -801,7 +801,7 @@ impl StrictPath { .follow_links(false) .into_iter() .skip(1) // the base path itself - .filter_map(crate::prelude::filter_map_walkdir) + .filter_map(|x| crate::prelude::filter_map_walkdir(context, x)) .filter(|x| x.file_type().is_file()) { let file = entry.path().display().to_string(); diff --git a/src/prelude.rs b/src/prelude.rs index 60ed475..da43ff9 100644 --- a/src/prelude.rs +++ b/src/prelude.rs @@ -166,9 +166,9 @@ pub fn app_dir() -> StrictPath { StrictPath::new(format!("{}/{}", CommonPath::Config.get().unwrap(), APP_DIR_NAME)) } -pub fn filter_map_walkdir(e: Result) -> Option { +pub fn filter_map_walkdir(context: &str, e: Result) -> Option { if let Err(e) = &e { - log::warn!("failed to walk: {:?} | {e:?}", e.path()); + log::warn!("[{context}] failed to walk: {:?} | {e:?}", e.path()); } e.ok() } diff --git a/src/scan.rs b/src/scan.rs index 699ad02..df056f5 100644 --- a/src/scan.rs +++ b/src/scan.rs @@ -685,7 +685,7 @@ pub fn scan_game_for_backup( .max_depth(100) .follow_links(true) .into_iter() - .filter_map(filter_map_walkdir) + .filter_map(|x| filter_map_walkdir(name, x)) { #[cfg(not(target_os = "windows"))] if child.path().to_string_lossy().contains('\\') { diff --git a/src/scan/layout.rs b/src/scan/layout.rs index 7e8d09c..89842a1 100644 --- a/src/scan/layout.rs +++ b/src/scan/layout.rs @@ -500,7 +500,7 @@ impl IndividualMapping { .max_depth(1) .follow_links(false) .into_iter() - .filter_map(crate::scan::filter_map_walkdir) + .filter_map(|x| crate::scan::filter_map_walkdir(&self.name, x)) { let name = child.file_name().to_string_lossy(); @@ -841,7 +841,7 @@ impl GameLayout { .max_depth(1) .follow_links(false) .into_iter() - .filter_map(crate::scan::filter_map_walkdir) + .filter_map(|x| crate::scan::filter_map_walkdir(&self.mapping.name, x)) { let raw_drive_dir = drive_dir.path().display().to_string(); let drive_mapping = @@ -851,7 +851,7 @@ impl GameLayout { .max_depth(100) .follow_links(false) .into_iter() - .filter_map(crate::scan::filter_map_walkdir) + .filter_map(|x| crate::scan::filter_map_walkdir(&self.mapping.name, x)) .filter(|x| x.file_type().is_file()) { let raw_file = file.path().display().to_string(); @@ -1820,7 +1820,7 @@ impl GameLayout { ); return Err(Box::new(e)); } - if let Err(e) = target.unset_readonly() { + if let Err(e) = target.unset_readonly(&self.mapping.name) { log::warn!( "[{}] failed to unset read-only on target: {:?} | {e}", self.mapping.name, @@ -1891,14 +1891,14 @@ impl GameLayout { .max_depth(1) .follow_links(false) .into_iter() - .filter_map(crate::scan::filter_map_walkdir) + .filter_map(|x| crate::scan::filter_map_walkdir(&self.mapping.name, x)) .filter(|x| x.file_name().to_string_lossy().starts_with("drive-")) { for file in walkdir::WalkDir::new(drive_dir.path()) .max_depth(100) .follow_links(false) .into_iter() - .filter_map(crate::scan::filter_map_walkdir) + .filter_map(|x| crate::scan::filter_map_walkdir(&self.mapping.name, x)) .filter(|x| x.file_type().is_file()) { let backup_file = StrictPath::new(file.path().display().to_string()); @@ -1938,7 +1938,7 @@ impl GameLayout { .max_depth(1) .follow_links(false) .into_iter() - .filter_map(crate::scan::filter_map_walkdir) + .filter_map(|x| crate::scan::filter_map_walkdir(&self.mapping.name, x)) .filter(|x| x.file_name().to_string_lossy().starts_with("drive-")) { for entry in walkdir::WalkDir::new(drive_dir.path()) @@ -1946,7 +1946,7 @@ impl GameLayout { .follow_links(false) .contents_first(true) .into_iter() - .filter_map(crate::scan::filter_map_walkdir) + .filter_map(|x| crate::scan::filter_map_walkdir(&self.mapping.name, x)) .filter(|x| x.file_type().is_dir()) { let empty = std::fs::read_dir(entry.path()).is_ok_and(|mut xs| xs.next().is_none()); @@ -2122,7 +2122,7 @@ impl BackupLayout { .follow_links(false) .into_iter() .skip(1) // the base path itself - .filter_map(crate::scan::filter_map_walkdir) + .filter_map(|x| crate::scan::filter_map_walkdir("ludusavi::BackupLayout", x)) .filter(|x| x.file_type().is_dir()) { let game_dir = StrictPath::from(&game_dir);