From 311f26541e0f19b5919c60462fe0c268d75286bb Mon Sep 17 00:00:00 2001 From: Jan Starke Date: Thu, 16 May 2024 10:25:04 +0200 Subject: [PATCH] explicit error handling for calls to metadata() --- src/bin/pf2bodyfile/main.rs | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/src/bin/pf2bodyfile/main.rs b/src/bin/pf2bodyfile/main.rs index 34dd336..32d3d1a 100644 --- a/src/bin/pf2bodyfile/main.rs +++ b/src/bin/pf2bodyfile/main.rs @@ -27,22 +27,23 @@ fn main() -> anyhow::Result<()> { if let Some(pf_os_filename) = input.path().file_name() { if let Some(pf_filename) = pf_os_filename.to_str() { let virtual_file = fs.open(Path::new(&pf_filename.to_string()))?; - let created = virtual_file - .metadata()? - .created_opt() - .and_then(|t| i64::try_from(*t).ok()); - let modified = virtual_file - .metadata()? - .modified_opt() - .and_then(|t| i64::try_from(*t).ok()); - let pf_file = read_prefetch_file(pf_filename, virtual_file)?; - - pf_file.display_prefetch_file( - pf_filename, - *cli.include_metrics(), - created, - modified, - )?; + match virtual_file.metadata() { + Ok(metadata) => { + let created = metadata.created_opt().and_then(|t| i64::try_from(*t).ok()); + let modified = metadata.modified_opt().and_then(|t| i64::try_from(*t).ok()); + let pf_file = read_prefetch_file(pf_filename, virtual_file)?; + + pf_file.display_prefetch_file( + pf_filename, + *cli.include_metrics(), + created, + modified, + )?; + } + Err(why) => { + log::error!("Unable to obtain metadata for {pf_filename}: {why}"); + }, + } } else { error!("invalid Unicode characters in filename: '{pf_os_filename:?}'") }