use super::{
common_configuration_keys, common_configuration_keys_public, permission::FsPermission, Path,
};
use crate::conf::Configuration;
use anyhow::Error;
use iref::Iri;
use std::any::type_name;
pub const FS_DEFAULT_NAME_KEY: &str = common_configuration_keys::FS_DEFAULT_NAME_KEY;
pub const DEFAULT_FS: &str = common_configuration_keys::FS_DEFAULT_NAME_DEFAULT;
pub const TRASH_PREFIX: &str = ".Trash";
pub const USER_HOME_PREFIX: &str = "/user";
pub trait FileSystem {
type FileSystemImpl: FileSystem;
fn new(uri: &Iri, conf: &Configuration) -> anyhow::Result<Self::FileSystemImpl>;
fn get_resolve_symlinks(conf: &Configuration) -> bool {
conf.get_bool(
common_configuration_keys_public::FS_CLIENT_RESOLVE_REMOTE_SYMLINKS_KEY,
common_configuration_keys_public::FS_CLIENT_RESOLVE_REMOTE_SYMLINKS_DEFAULT,
)
}
fn get_default_uri(conf: &Configuration) -> anyhow::Result<Iri> {
Ok(Iri::new(conf.get_trimmed_with_default(
common_configuration_keys::FS_DEFAULT_NAME_KEY,
common_configuration_keys::FS_DEFAULT_NAME_DEFAULT,
))?)
}
fn resolve_symlinks(&self) -> bool;
fn get_scheme(&self) -> anyhow::Result<&str> {
Err(Error::msg(format!(
"Not implemented by the {} FileSystem implementation",
type_name::<Self>().split("::").last().unwrap_or_default()
)))
}
fn get_uri(&self) -> Iri;
fn get_home_directory(&self) -> anyhow::Result<Path>;
fn get_working_directory(&self) -> &Path;
fn mkdirs(&self, f: &Path, permission: Option<&FsPermission>) -> anyhow::Result<bool>;
fn fix_relative_part(&self, p: &Path) -> anyhow::Result<Path> {
if p.is_uri_path_absolute() {
Ok(p.clone())
} else {
Path::from_parent(self.get_working_directory(), p)
}
}
}