2024-04-28 12:37:15 +01:00
|
|
|
use std::path::PathBuf;
|
2024-04-27 20:31:23 +01:00
|
|
|
|
|
|
|
use derive_more::From;
|
|
|
|
|
2024-04-28 12:37:15 +01:00
|
|
|
use crate::fs::like::FileSystemLike;
|
|
|
|
|
|
|
|
mod like;
|
2024-04-27 20:31:23 +01:00
|
|
|
mod real;
|
|
|
|
mod temp;
|
|
|
|
|
|
|
|
#[derive(Debug, From, derive_more::Display)]
|
|
|
|
pub enum Error {
|
|
|
|
Io(std::io::Error),
|
|
|
|
|
|
|
|
#[display("Path access attempted outside of base ({base:?}): {path:?}")]
|
|
|
|
PathTraversal {
|
|
|
|
base: PathBuf,
|
|
|
|
path: PathBuf,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
pub type Result<T> = core::result::Result<T, Error>;
|
|
|
|
|
|
|
|
pub const fn new(base: PathBuf) -> FileSystem {
|
|
|
|
FileSystem::Real(real::new(base))
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn temp() -> Result<FileSystem> {
|
|
|
|
temp::new().map(FileSystem::Temp)
|
|
|
|
}
|
|
|
|
|
|
|
|
pub enum FileSystem {
|
|
|
|
Real(real::RealFileSystem),
|
|
|
|
Temp(temp::TempFileSystem),
|
|
|
|
}
|
|
|
|
impl std::ops::Deref for FileSystem {
|
|
|
|
type Target = dyn FileSystemLike;
|
|
|
|
|
|
|
|
fn deref(&self) -> &Self::Target {
|
|
|
|
match self {
|
|
|
|
Self::Real(fs) => fs,
|
|
|
|
Self::Temp(fs) => fs.deref(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|