use crate::model::{Entry, LinkSupport, NodeKind, Via};
use crate::path::RelPath;
pub type FsResult<T> = Result<T, FsError>;
#[derive(Debug, thiserror::Error)]
#[error("failed to {operation} `{path}`")]
pub struct FsError {
pub operation: &'static str,
pub path: String,
#[source]
pub source: std::io::Error,
}
impl FsError {
pub fn new(operation: &'static str, path: &RelPath, source: std::io::Error) -> Self {
Self {
operation,
path: path.to_string(),
source,
}
}
}
pub trait Workspace {
fn probe(&self, path: &RelPath) -> FsResult<Option<Entry>>;
fn read(&self, path: &RelPath) -> FsResult<String>;
fn write(&self, path: &RelPath, contents: &str) -> FsResult<()>;
fn create_dir_all(&self, path: &RelPath) -> FsResult<()>;
fn link(&self, via: Via, node: NodeKind, canonical: &RelPath, target: &RelPath)
-> FsResult<()>;
fn remove_link(&self, path: &RelPath, node: NodeKind) -> FsResult<()>;
fn remove_file(&self, path: &RelPath) -> FsResult<()>;
fn remove_empty_dir(&self, path: &RelPath) -> FsResult<()>;
fn rename(&self, from: &RelPath, to: &RelPath) -> FsResult<()>;
fn is_empty_dir(&self, path: &RelPath) -> FsResult<bool>;
fn support(&self) -> LinkSupport;
}