65 lines
1.3 KiB
Rust
65 lines
1.3 KiB
Rust
|
use std::{
|
||
|
borrow::Borrow,
|
||
|
path::{Path, PathBuf},
|
||
|
};
|
||
|
|
||
|
use super::{UpEndDatabase, UpEndConnection};
|
||
|
use crate::util::{hash::Hash, jobs::JobContainer};
|
||
|
|
||
|
pub mod fs;
|
||
|
|
||
|
#[derive(Debug, Clone)]
|
||
|
pub enum StoreError {
|
||
|
NotFound,
|
||
|
Unknown(String),
|
||
|
}
|
||
|
|
||
|
impl std::fmt::Display for StoreError {
|
||
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||
|
write!(f, "STORE ERROR")
|
||
|
}
|
||
|
}
|
||
|
|
||
|
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),
|
||
|
Removed(PathBuf),
|
||
|
Failed(PathBuf, StoreError),
|
||
|
}
|
||
|
pub trait UpStore {
|
||
|
fn retrieve(&self, hash: &Hash) -> Result<Vec<Blob>>;
|
||
|
fn retrieve_all(&self) -> Result<Vec<Blob>>;
|
||
|
fn store<S: Into<Option<String>>>(
|
||
|
&self,
|
||
|
connection: UpEndConnection,
|
||
|
blob: Blob,
|
||
|
name_hint: S,
|
||
|
) -> Result<Hash>;
|
||
|
fn update<D: Borrow<UpEndDatabase>>(
|
||
|
&self,
|
||
|
database: D,
|
||
|
job_container: JobContainer,
|
||
|
) -> Result<Vec<UpdatePathOutcome>>;
|
||
|
}
|