hadoop_common/fs/
file_system.rs1use super::{
2 common_configuration_keys, common_configuration_keys_public, permission::FsPermission, Path,
3};
4use crate::conf::Configuration;
5use anyhow::Error;
6use iref::Iri;
7use std::any::type_name;
8
9pub const FS_DEFAULT_NAME_KEY: &str = common_configuration_keys::FS_DEFAULT_NAME_KEY;
10pub const DEFAULT_FS: &str = common_configuration_keys::FS_DEFAULT_NAME_DEFAULT;
11pub const TRASH_PREFIX: &str = ".Trash";
13pub const USER_HOME_PREFIX: &str = "/user";
14
15pub trait FileSystem {
20 type FileSystemImpl: FileSystem;
21
22 fn new(uri: &Iri, conf: &Configuration) -> anyhow::Result<Self::FileSystemImpl>;
23
24 fn get_resolve_symlinks(conf: &Configuration) -> bool {
25 conf.get_bool(
26 common_configuration_keys_public::FS_CLIENT_RESOLVE_REMOTE_SYMLINKS_KEY,
27 common_configuration_keys_public::FS_CLIENT_RESOLVE_REMOTE_SYMLINKS_DEFAULT,
28 )
29 }
30
31 fn get_default_uri(conf: &Configuration) -> anyhow::Result<Iri> {
33 Ok(Iri::new(conf.get_trimmed_with_default(
34 common_configuration_keys::FS_DEFAULT_NAME_KEY,
35 common_configuration_keys::FS_DEFAULT_NAME_DEFAULT,
36 ))?)
37 }
38
39 fn resolve_symlinks(&self) -> bool;
41
42 fn get_scheme(&self) -> anyhow::Result<&str> {
44 Err(Error::msg(format!(
45 "Not implemented by the {} FileSystem implementation",
46 type_name::<Self>().split("::").last().unwrap_or_default()
47 )))
48 }
49
50 fn get_uri(&self) -> Iri;
52
53 fn get_home_directory(&self) -> anyhow::Result<Path>;
56
57 fn get_working_directory(&self) -> &Path;
59
60 fn mkdirs(&self, f: &Path, permission: Option<&FsPermission>) -> anyhow::Result<bool>;
64
65 fn fix_relative_part(&self, p: &Path) -> anyhow::Result<Path> {
67 if p.is_uri_path_absolute() {
68 Ok(p.clone())
69 } else {
70 Path::from_parent(self.get_working_directory(), p)
71 }
72 }
73}