diff --git a/src-tauri/src/filesystem/cache.rs b/src-tauri/src/filesystem/cache.rs index a05fd2e..b4683aa 100644 --- a/src-tauri/src/filesystem/cache.rs +++ b/src-tauri/src/filesystem/cache.rs @@ -141,8 +141,16 @@ fn save_to_cache(state: &mut MutexGuard) { } /// Reads and decodes the cache file and stores it in memory for quick access. -pub fn load_system_cache(state_mux: &StateSafe) { +/// Returns false if the cache was unable to deserialize. +pub fn load_system_cache(state_mux: &StateSafe) -> bool { let state = &mut state_mux.lock().unwrap(); let file_contents = fs::read_to_string(CACHE_FILE_PATH).unwrap(); - state.system_cache = serde_json::from_str(&file_contents).unwrap(); -} + + let deserialize_result = serde_json::from_str(&file_contents); + if let Ok(system_cache) = deserialize_result { + state.system_cache = system_cache; + return true; + } + + false +} \ No newline at end of file diff --git a/src-tauri/src/filesystem/volume.rs b/src-tauri/src/filesystem/volume.rs index d5fcaa8..4b388c4 100644 --- a/src-tauri/src/filesystem/volume.rs +++ b/src-tauri/src/filesystem/volume.rs @@ -180,9 +180,9 @@ pub fn get_volumes(state_mux: State) -> Vec { let mut sys = System::new_all(); sys.refresh_all(); - let cache_exists = fs::metadata(CACHE_FILE_PATH).is_ok(); + let mut cache_exists = fs::metadata(CACHE_FILE_PATH).is_ok(); if cache_exists { - load_system_cache(&state_mux); + cache_exists = load_system_cache(&state_mux); } else { File::create(CACHE_FILE_PATH).unwrap(); }