Skip to content

Commit

Permalink
#419: Add game context to walkdir error logs
Browse files Browse the repository at this point in the history
  • Loading branch information
mtkennerly committed Nov 20, 2024
1 parent 0625c60 commit 96ba96b
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 15 deletions.
6 changes: 3 additions & 3 deletions src/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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();
Expand All @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions src/prelude.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<walkdir::DirEntry, walkdir::Error>) -> Option<walkdir::DirEntry> {
pub fn filter_map_walkdir(context: &str, e: Result<walkdir::DirEntry, walkdir::Error>) -> Option<walkdir::DirEntry> {
if let Err(e) = &e {
log::warn!("failed to walk: {:?} | {e:?}", e.path());
log::warn!("[{context}] failed to walk: {:?} | {e:?}", e.path());
}
e.ok()
}
Expand Down
2 changes: 1 addition & 1 deletion src/scan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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('\\') {
Expand Down
18 changes: 9 additions & 9 deletions src/scan/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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 =
Expand All @@ -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();
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -1938,15 +1938,15 @@ 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())
.max_depth(100)
.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());
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 96ba96b

Please sign in to comment.