conditionally erase folders on drop of `BucketMap` (#33309)

This commit is contained in:
Jeff Washington (jwash) 2023-09-19 13:02:22 -07:00 committed by GitHub
parent 056e7cc240
commit 288e8a682a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 1 deletions

View File

@ -31,11 +31,14 @@ pub struct BucketMap<T: Clone + Copy + Debug + PartialEq + 'static> {
max_buckets_pow2: u8,
pub stats: Arc<BucketMapStats>,
pub temp_dir: Option<TempDir>,
/// true if dropping self removes all folders.
/// This is primarily for test environments.
pub erase_drives_on_drop: bool,
}
impl<T: Clone + Copy + Debug + PartialEq> Drop for BucketMap<T> {
fn drop(&mut self) {
if self.temp_dir.is_none() {
if self.temp_dir.is_none() && self.erase_drives_on_drop {
BucketMap::<T>::erase_previous_drives(&self.drives);
}
}
@ -103,6 +106,7 @@ impl<T: Clone + Copy + Debug + PartialEq> BucketMap<T> {
max_buckets_pow2: log2(config.max_buckets) as u8,
stats,
temp_dir,
erase_drives_on_drop: true,
}
}