-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(rocks_db): move ShallowTempDir to benches crate
- Loading branch information
Showing
4 changed files
with
46 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
use rand::RngCore; | ||
use std::{ | ||
env, | ||
path::PathBuf, | ||
}; | ||
|
||
/// Reimplementation of `tempdir::TempDir` that allows creating a new | ||
/// instance without actually creating a new directory on the filesystem. | ||
/// This is needed since rocksdb requires empty directory for checkpoints. | ||
pub struct ShallowTempDir { | ||
path: PathBuf, | ||
} | ||
|
||
impl Default for ShallowTempDir { | ||
fn default() -> Self { | ||
Self::new() | ||
} | ||
} | ||
|
||
impl ShallowTempDir { | ||
/// Creates a random directory. | ||
pub fn new() -> Self { | ||
let mut rng = rand::thread_rng(); | ||
let mut path = env::temp_dir(); | ||
path.push(format!("fuel-core-shallow-{}", rng.next_u64())); | ||
Self { path } | ||
} | ||
|
||
/// Returns the path of the directory. | ||
pub fn path(&self) -> &PathBuf { | ||
&self.path | ||
} | ||
} | ||
|
||
impl Drop for ShallowTempDir { | ||
fn drop(&mut self) { | ||
// Ignore errors | ||
let _ = std::fs::remove_dir_all(&self.path); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters