upend/db/src/stores/mod.rs

82 lines
1.8 KiB
Rust
Raw Normal View History

use std::path::{Path, PathBuf};
use super::{UpEndConnection, UpEndDatabase};
use crate::OperationContext;
2023-11-05 14:19:04 +01:00
use crate::{jobs::JobContainer, BlobMode};
2023-06-29 14:29:38 +02:00
use upend_base::hash::UpMultihash;
pub mod fs;
#[derive(Debug, Clone)]
pub enum StoreError {
Unknown(String),
}
impl std::fmt::Display for StoreError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(
f,
"STORE ERROR: {}",
match self {
StoreError::Unknown(err) => err,
}
)
}
}
impl std::error::Error for StoreError {}
type Result<T> = std::result::Result<T, StoreError>;
pub struct Blob {
file_path: PathBuf,
}
impl Blob {
pub fn from_filepath<P: AsRef<Path>>(path: P) -> Blob {
Blob {
file_path: PathBuf::from(path.as_ref()),
}
}
pub fn get_file_path(&self) -> &Path {
self.file_path.as_path()
}
}
#[derive(Debug)]
pub enum UpdatePathOutcome {
Added(PathBuf),
Unchanged(PathBuf),
2022-10-18 18:29:23 +02:00
Skipped(PathBuf),
Removed(PathBuf),
Failed(PathBuf, StoreError),
}
pub trait UpStore {
2023-06-29 14:29:38 +02:00
fn retrieve(&self, hash: &UpMultihash) -> Result<Vec<Blob>>;
fn retrieve_all(&self) -> Result<Vec<Blob>>;
fn store(
&self,
2024-01-17 20:31:20 +01:00
connection: &UpEndConnection,
blob: Blob,
name_hint: Option<String>,
blob_mode: Option<BlobMode>,
context: OperationContext,
2023-06-29 14:29:38 +02:00
) -> Result<UpMultihash>;
fn update(
&self,
database: &UpEndDatabase,
job_container: JobContainer,
options: UpdateOptions,
context: OperationContext,
) -> Result<Vec<UpdatePathOutcome>>;
fn stats(&self) -> Result<serde_json::Value>;
}
#[derive(Debug, Clone)]
pub struct UpdateOptions {
pub initial: bool,
2023-11-05 14:19:04 +01:00
pub tree_mode: BlobMode,
}