pub mod cas;
pub(crate) mod keys;
pub(crate) mod marks;
pub mod output;
pub(crate) mod pointer;
pub(crate) mod record;
pub mod repolock;
pub(crate) mod schema;
pub mod store;
pub mod tombstone;
pub(crate) mod write;
use std::path::{Path, PathBuf};
pub(crate) use record::{OutputRoot, Record, SealedDir};
pub(crate) use write::Durability;
pub(crate) struct Datastore {
root: PathBuf,
}
impl Datastore {
/// pass the output root here, a generation directory holds no records.
pub(crate) fn at(output_root: &Path) -> Self {
Self {
root: output_root.to_path_buf(),
}
}
pub(crate) fn record<R: Record<Area = OutputRoot>>(&self, key: &R::Key) -> record::Rec<'_, R>
where
R::Key: Clone,
{
record::Rec::new(&self.root, key)
}
pub(crate) fn marks<M: marks::MarkSet<Area = OutputRoot>>(&self) -> marks::Marks<M> {
marks::Marks::new(&self.root)
}
pub(crate) fn pointer(&self) -> pointer::ServingPointer<'_> {
pointer::ServingPointer::new(&self.root)
}
}
pub(crate) struct SealedStore {
dir: PathBuf,
}
impl SealedStore {
pub(crate) fn open(config: &crate::config::ValidatedConfig) -> Self {
let store = Self {
dir: config.oauth_dir(),
};
store.private();
store
}
fn private(&self) {
let _ = write::Access::Private.create_dir_all(&self.dir);
}
#[cfg(test)]
pub(crate) fn at(dir: &Path) -> Self {
let store = Self {
dir: dir.to_path_buf(),
};
store.private();
store
}
pub(crate) fn record<R: Record<Area = SealedDir>>(&self, key: &R::Key) -> record::Rec<'_, R>
where
R::Key: Clone,
{
record::Rec::new(&self.dir, key)
}
}