use std::path::{Path, PathBuf};
use object_store::{Error as ObjectStoreError, local::LocalFileSystem};
use super::super::ObjectStorage;
#[derive(Clone, Debug)]
pub struct LocalObjectStorageBuilder {
name: String,
root: PathBuf,
automatic_cleanup: bool,
fsync: bool,
}
impl LocalObjectStorageBuilder {
pub(crate) fn new(name: impl Into<String>, root: impl AsRef<Path>) -> Self {
Self {
name: name.into(),
root: root.as_ref().to_path_buf(),
automatic_cleanup: false,
fsync: false,
}
}
#[must_use]
pub const fn with_automatic_cleanup(mut self, automatic_cleanup: bool) -> Self {
self.automatic_cleanup = automatic_cleanup;
self
}
#[must_use]
pub const fn with_fsync(mut self, fsync: bool) -> Self {
self.fsync = fsync;
self
}
pub fn build(self) -> Result<ObjectStorage<LocalFileSystem>, ObjectStoreError> {
let store = LocalFileSystem::new_with_prefix(self.root)?
.with_automatic_cleanup(self.automatic_cleanup)
.with_fsync(self.fsync);
Ok(ObjectStorage::from_store(self.name, store))
}
}