Skip to content

Commit 85e77be

Browse files
committed
add create dir all to interface
1 parent b256021 commit 85e77be

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

src/store/fs.rs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,9 @@ pub trait Persistence: Clone {
455455
/// returning the bytes of the file in the success case
456456
/// and [Self::Err] in the error case
457457
fn read(&self, path: &Path) -> impl Future<Output = Result<Vec<u8>, Self::Err>>;
458+
459+
/// recursively ensure that the input path exists
460+
fn create_dir_all(&self, path: &Path) -> impl Future<Output = Result<(), Self::Err>>;
458461
}
459462

460463
/// A persistence layer that writes to the local file system
@@ -473,6 +476,11 @@ impl Persistence for FileSystemPersistence {
473476
let res = std::fs::read(path);
474477
async move { res }
475478
}
479+
480+
fn create_dir_all(&self, path: &Path) -> impl Future<Output = Result<(), Self::Err>> {
481+
let res = std::fs::create_dir_all(path);
482+
async move { res }
483+
}
476484
}
477485

478486
impl ImportSource {
@@ -822,6 +830,7 @@ impl<T> StoreInner<T>
822830
where
823831
T: Persistence,
824832
OuterError: From<T::Err>,
833+
io::Error: From<T::Err>,
825834
{
826835
fn new_sync_with_backend(
827836
path: PathBuf,
@@ -833,17 +842,17 @@ where
833842
"creating data directory: {}",
834843
options.path.data_path.display()
835844
);
836-
std::fs::create_dir_all(&options.path.data_path)?;
845+
rt.block_on(fs.create_dir_all(&options.path.data_path))?;
837846
tracing::trace!(
838847
"creating temp directory: {}",
839848
options.path.temp_path.display()
840849
);
841-
std::fs::create_dir_all(&options.path.temp_path)?;
850+
rt.block_on(fs.create_dir_all(&options.path.temp_path))?;
842851
tracing::trace!(
843852
"creating parent directory for db file{}",
844853
path.parent().unwrap().display()
845854
);
846-
std::fs::create_dir_all(path.parent().unwrap())?;
855+
rt.block_on(fs.create_dir_all(path.parent().unwrap()))?;
847856
let temp: Arc<RwLock<TempCounterMap>> = Default::default();
848857
let (actor, tx) = Actor::new(&path, options.clone(), temp.clone(), rt.clone())?;
849858
let handle = std::thread::Builder::new()
@@ -1036,7 +1045,7 @@ where
10361045
.into(),
10371046
)
10381047
})?;
1039-
std::fs::create_dir_all(parent)?;
1048+
Handle::current().block_on(self.fs.create_dir_all(parent))?;
10401049
let temp_tag = self.temp.temp_tag(HashAndFormat::raw(hash));
10411050
let (tx, rx) = oneshot::channel();
10421051
self.tx

0 commit comments

Comments
 (0)