2015-11-10 18:27:54 +00:00
|
|
|
use std::error::Error;
|
|
|
|
use std::fmt::Display;
|
2015-11-10 18:51:43 +00:00
|
|
|
use std::fmt::Formatter;
|
|
|
|
use std::fmt::Result as FMTResult;
|
2015-11-10 18:27:54 +00:00
|
|
|
|
|
|
|
use super::file::FileID;
|
|
|
|
use super::file::File;
|
|
|
|
use module::Module;
|
|
|
|
|
|
|
|
type BackendOperationResult = Result<(), StorageBackendError>;
|
|
|
|
|
|
|
|
pub struct StorageBackend<'a> {
|
|
|
|
basepath: String,
|
|
|
|
module: &'a Module,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'a> StorageBackend<'a> {
|
|
|
|
|
2015-11-10 19:53:35 +00:00
|
|
|
fn new(bashpath: String, module: &'a Module) -> StorageBackend<'a> {
|
|
|
|
StorageBackend {
|
|
|
|
basepath: basepath,
|
|
|
|
module: module,
|
|
|
|
}
|
2015-11-10 18:27:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fn getFileList() -> Vec<(String, FileID)> {
|
|
|
|
}
|
|
|
|
|
|
|
|
fn createEmpty() -> FileID {
|
|
|
|
}
|
|
|
|
|
|
|
|
fn createFile() -> File {
|
|
|
|
}
|
|
|
|
|
|
|
|
fn writeFile(f: File) -> BackendOperationResult {
|
|
|
|
}
|
|
|
|
|
|
|
|
fn createFileWithContent(content: String) -> BackendOperationResult {
|
|
|
|
}
|
|
|
|
|
|
|
|
fn readFile(id: FileID) -> String {
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: Meta files are not covered yet
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug)]
|
2015-11-10 18:51:43 +00:00
|
|
|
pub struct StorageBackendError {
|
|
|
|
pub action: String, // The file system action in words
|
|
|
|
pub desc: String, // A short description
|
|
|
|
pub explanation: String, // A long, user friendly description
|
|
|
|
pub dataDump: Option<String> // Data dump, if any
|
|
|
|
}
|
2015-11-10 18:27:54 +00:00
|
|
|
|
|
|
|
impl StorageBackendError {
|
2015-11-10 18:51:43 +00:00
|
|
|
fn new(action: &'static str,
|
|
|
|
desc : &'static str,
|
|
|
|
explan: &'static str,
|
|
|
|
data : Option<String>) -> StorageBackendError
|
|
|
|
{
|
|
|
|
StorageBackendError {
|
|
|
|
action: String::from(action),
|
|
|
|
desc: String::from(desc),
|
|
|
|
explanation: String::from(explan),
|
|
|
|
dataDump: data,
|
|
|
|
}
|
|
|
|
}
|
2015-11-10 18:27:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Error for StorageBackendError {
|
2015-11-10 18:51:43 +00:00
|
|
|
|
|
|
|
fn description(&self) -> &str {
|
|
|
|
&self.desc[..]
|
|
|
|
}
|
|
|
|
|
|
|
|
fn cause(&self) -> Option<&Error> {
|
|
|
|
None
|
|
|
|
}
|
|
|
|
|
2015-11-10 18:27:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Display for StorageBackendError {
|
2015-11-10 18:51:43 +00:00
|
|
|
fn fmt(&self, f: &mut Formatter) -> FMTResult {
|
|
|
|
write!(f, "StorageBackendError[{}]: {}\n\n{}",
|
|
|
|
self.action, self.desc, self.explanation)
|
|
|
|
}
|
2015-11-10 18:27:54 +00:00
|
|
|
}
|
|
|
|
|