Skip to content
This repository has been archived by the owner on Jan 22, 2025. It is now read-only.

Commit

Permalink
only delete if supposed to
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffwashington committed Oct 9, 2023
1 parent 2755d68 commit 52f13e9
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions accounts-db/src/cache_hash_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,9 +198,7 @@ pub(crate) struct CacheHashData {

impl Drop for CacheHashData {
fn drop(&mut self) {
if self.should_delete_old_cache_files_on_drop {
self.delete_old_cache_files();
}
self.delete_old_cache_files();
self.stats.report();
}
}
Expand All @@ -227,14 +225,16 @@ impl CacheHashData {

/// delete all pre-existing files that will not be used
pub(crate) fn delete_old_cache_files(&self) {
let old_cache_files = std::mem::take(&mut *self.pre_existing_cache_files.lock().unwrap());
if !old_cache_files.is_empty() {
self.stats
.unused_cache_files
.fetch_add(old_cache_files.len(), Ordering::Relaxed);
for file_name in old_cache_files.iter() {
let result = self.cache_dir.join(file_name);
let _ = fs::remove_file(result);
if self.should_delete_old_cache_files_on_drop {
let old_cache_files = std::mem::take(&mut *self.pre_existing_cache_files.lock().unwrap());
if !old_cache_files.is_empty() {
self.stats
.unused_cache_files
.fetch_add(old_cache_files.len(), Ordering::Relaxed);
for file_name in old_cache_files.iter() {
let result = self.cache_dir.join(file_name);
let _ = fs::remove_file(result);
}
}
}
}
Expand Down

0 comments on commit 52f13e9

Please sign in to comment.