use std::path::{Path, PathBuf};
use super::backend::FileBackend;
use super::error::ZebFsError;
use super::local::LocalZebFs;
use super::model::{ZebFsEntry, ZebFsObject, ZebFsStat};
use super::s3::S3ZebFs;
#[derive(Debug, Clone)]
pub enum ZebFs {
Local(LocalZebFs),
S3(S3ZebFs),
}
impl ZebFs {
pub fn backend(&self) -> FileBackend {
match self {
Self::Local(_) => FileBackend::Zebfs,
Self::S3(_) => FileBackend::S3,
}
}
pub fn local_root(&self) -> Option<&Path> {
match self {
Self::Local(local) => Some(local.root()),
Self::S3(_) => None,
}
}
pub fn local_path(&self, path: &str) -> Result<Option<PathBuf>, ZebFsError> {
match self {
Self::Local(local) => local.resolve_object_path(path).map(|(_, abs)| Some(abs)),
Self::S3(_) => Ok(None),
}
}
pub fn put(&self, path: &str, bytes: &[u8]) -> Result<ZebFsStat, ZebFsError> {
match self {
Self::Local(s) => s.put(path, bytes),
Self::S3(s) => s.put(path, bytes),
}
}
pub fn get(&self, path: &str) -> Result<ZebFsObject, ZebFsError> {
match self {
Self::Local(s) => s.get(path),
Self::S3(s) => s.get(path),
}
}
pub fn head(&self, path: &str) -> Result<ZebFsStat, ZebFsError> {
match self {
Self::Local(s) => s.head(path),
Self::S3(s) => s.head(path),
}
}
pub fn list(&self, prefix: &str) -> Result<Vec<ZebFsEntry>, ZebFsError> {
match self {
Self::Local(s) => s.list(prefix),
Self::S3(s) => s.list(prefix),
}
}
pub fn create_prefix(&self, prefix: &str) -> Result<ZebFsStat, ZebFsError> {
match self {
Self::Local(s) => s.create_prefix(prefix),
Self::S3(s) => s.create_prefix(prefix),
}
}
pub fn delete(&self, path: &str) -> Result<(), ZebFsError> {
match self {
Self::Local(s) => s.delete(path),
Self::S3(s) => s.delete(path),
}
}
pub fn copy(&self, from: &str, to: &str) -> Result<ZebFsStat, ZebFsError> {
match self {
Self::Local(s) => s.copy(from, to),
Self::S3(s) => s.copy(from, to),
}
}
pub fn read_reserved(&self, path: &str) -> Result<Option<Vec<u8>>, ZebFsError> {
match self {
Self::Local(s) => s.read_reserved(path),
Self::S3(s) => s.read_reserved(path),
}
}
pub fn write_reserved(&self, path: &str, bytes: &[u8]) -> Result<(), ZebFsError> {
match self {
Self::Local(s) => s.write_reserved(path, bytes),
Self::S3(s) => s.write_reserved(path, bytes),
}
}
}