From 349a194060e45ed03dff9e6249de3c9b8d9ffa6f Mon Sep 17 00:00:00 2001 From: Joshua Goins Date: Mon, 29 Apr 2024 19:09:51 -0400 Subject: [PATCH] Remove possible panic when checking if a file exists Probably a leftover from me --- src/gamedata.rs | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/gamedata.rs b/src/gamedata.rs index f110344..d671029 100755 --- a/src/gamedata.rs +++ b/src/gamedata.rs @@ -157,7 +157,9 @@ impl GameData { /// } /// ``` pub fn exists(&mut self, path: &str) -> bool { - let index_path = self.get_index_filenames(path); + let Some(index_path) = self.get_index_filenames(path) else { + return false; + }; self.cache_index_file((&index_path.0, &index_path.1)); @@ -219,8 +221,8 @@ impl GameData { Some((&self.repositories[0], string_to_category(tokens[0])?)) } - fn get_index_filenames(&self, path: &str) -> (String, String) { - let (repository, category) = self.parse_repository_category(path).unwrap(); + fn get_index_filenames(&self, path: &str) -> Option<(String, String)> { + let (repository, category) = self.parse_repository_category(path)?; let index_path: PathBuf = [ &self.game_directory, @@ -240,10 +242,10 @@ impl GameData { .iter() .collect(); - ( + Some(( index_path.into_os_string().into_string().unwrap(), index2_path.into_os_string().into_string().unwrap(), - ) + )) } /// Read an excel sheet by name (e.g. "Achievement") @@ -419,7 +421,7 @@ impl GameData { } fn find_entry(&mut self, path: &str) -> Option { - let index_path = self.get_index_filenames(path); + let index_path = self.get_index_filenames(path)?; debug!( "Trying index files {index_path}, {index2_path}", index_path = index_path.0,