diff --git a/src/cache_manager.rs b/src/cache_manager.rs index da35036..aa7cc61 100644 --- a/src/cache_manager.rs +++ b/src/cache_manager.rs @@ -119,14 +119,13 @@ impl CacheManager { pub async fn get_file(self: &Arc, info: &CacheFileInfo) -> Option>> { let path = info.to_path(&self.cache_dir); - let metadata = metadata(&path).await.ok()?; - // Check file exists + // Check exists and open file + let metadata = metadata(&path).await.ok()?; if !metadata.is_file() || metadata.len() != info.size() as u64 { warn!("Unexcepted cache file metadata: type={:?}, size={}", metadata.file_type(), metadata.len()); return None; } - let mut file = match File::open(&path).await { Ok(file) => file, Err(err) => { @@ -135,7 +134,7 @@ impl CacheManager { } }; - // Skip check if file is recently accessed + // Skip hash check if file is recently accessed let one_week_ago = SystemTime::now() - Duration::from_secs(60 * 60 * 24 * 7); if FileTime::from_last_modification_time(&metadata) >= one_week_ago.into() { return Some(ReaderStream::with_capacity(file, 64 * 1024).boxed());