Skip to content

Commit

Permalink
Comment
Browse files Browse the repository at this point in the history
  • Loading branch information
james58899 committed Dec 17, 2024
1 parent 3d45fe3 commit 63914c9
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions src/cache_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,14 +119,13 @@ impl CacheManager {

pub async fn get_file(self: &Arc<Self>, info: &CacheFileInfo) -> Option<impl Stream<Item = Result<Bytes, Error>>> {
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) => {
Expand All @@ -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());
Expand Down

0 comments on commit 63914c9

Please sign in to comment.