use wildland_corex::dfs::interface::{DirEntry, NodeStat};
#[derive(thiserror::Error, Debug)]
pub enum StorageBackendError {
#[error("Operation is not supported by backend {backend_type}: {context}")]
NotSupported {
backend_type: String,
context: String,
},
#[error("Error in backend {backend_type}: {inner:?}")]
Generic {
backend_type: String,
inner: anyhow::Error,
},
#[error("File system version is unsupported: {inner:?}")]
FileSystemVersionUnsupported {
backend_type: String,
inner: anyhow::Error,
},
#[error("Not authorised to perform this operation: {inner:?}")]
Unauthorised {
backend_type: String,
inner: anyhow::Error,
},
#[error("Insufficient quota in {backend_type}. Cannot store {requested_size} bytes.")]
InsufficientQuota {
backend_type: String,
requested_size: usize,
},
}
impl StorageBackendError {
pub fn backend_type(&self) -> &str {
match self {
StorageBackendError::NotSupported { backend_type, .. }
| StorageBackendError::Generic { backend_type, .. }
| StorageBackendError::FileSystemVersionUnsupported { backend_type, .. }
| StorageBackendError::InsufficientQuota { backend_type, .. }
| StorageBackendError::Unauthorised { backend_type, .. } => backend_type,
}
}
pub fn context(&self) -> String {
match self {
StorageBackendError::NotSupported { context, .. } => context.clone(),
StorageBackendError::Generic { inner, .. }
| StorageBackendError::FileSystemVersionUnsupported { inner, .. }
| Self::Unauthorised { inner, .. } => inner.to_string(),
StorageBackendError::InsufficientQuota {
backend_type,
requested_size,
} => format!(
"Insufficient quota on {} to upload {} bytes",
backend_type, requested_size
),
}
}
pub fn with_context(self, ctx: impl ToString) -> Self {
match self {
StorageBackendError::NotSupported {
backend_type,
context,
} => StorageBackendError::NotSupported {
backend_type,
context: ctx.to_string() + ": " + &context,
},
StorageBackendError::Generic {
backend_type,
inner,
} => StorageBackendError::Generic {
backend_type,
inner: inner.context(ctx.to_string()),
},
StorageBackendError::FileSystemVersionUnsupported {
backend_type,
inner,
} => StorageBackendError::FileSystemVersionUnsupported {
backend_type,
inner: inner.context(ctx.to_string()),
},
StorageBackendError::InsufficientQuota {
backend_type,
requested_size,
} => StorageBackendError::InsufficientQuota {
backend_type,
requested_size,
},
StorageBackendError::Unauthorised {
backend_type,
inner,
} => StorageBackendError::Unauthorised {
backend_type,
inner: inner.context(ctx.to_string()),
},
}
}
}
#[derive(Debug, PartialEq, Eq)]
pub enum ReadDirResponse {
Entries(Vec<DirEntry>),
NoSuchPath,
NotADirectory,
}
#[derive(Debug, PartialEq, Eq)]
pub enum MetadataResponse {
Found(NodeStat),
NotFound,
}
#[derive(Debug, PartialEq, Eq)]
pub enum CreateDirResponse {
Created,
InvalidParent,
PathAlreadyExists,
}
#[derive(Debug, PartialEq, Eq)]
pub enum SetWildlandObjectIdResponse {
IdSet,
NotFound,
}
#[derive(Debug, PartialEq, Eq)]
pub enum RemoveDirResponse {
Removed,
DirNotEmpty,
NotFound,
NotADirectory,
RootRemovalNotAllowed,
}
#[derive(Debug, PartialEq, Eq)]
pub enum RemoveFileResponse {
Removed,
NotFound,
NotAFile,
}
#[derive(Debug, PartialEq, Eq)]
pub enum RenameResponse {
Renamed,
NotFound,
SourceIsParentOfTarget,
TargetPathAlreadyExists,
InvalidTargetParentPath,
}
#[derive(Debug, PartialEq, Eq)]
pub enum SetPermissionsResponse {
Set,
NotFound,
}
#[derive(Debug, PartialEq, Eq)]
pub enum DownloadResponse {
Success,
NotAFile,
NoSuchPath,
}
#[derive(Debug, PartialEq, Eq)]
pub enum UploadResponse {
NotPermitted,
Success,
InvalidParent,
PathTakenByDir,
}
#[derive(Debug, PartialEq, Eq)]
pub enum SetTimesResponse {
Success,
NoSuchPath,
}
#[derive(Debug, PartialEq, Eq)]
pub enum GetInfoResponse {
Found(std::path::PathBuf),
NotFound,
}