Rename: StorageBackend -> Storage
This commit is contained in:
parent
da2b482bda
commit
7d40b68407
4 changed files with 30 additions and 30 deletions
|
@ -19,7 +19,7 @@ use module::Module;
|
||||||
use module::ModuleError;
|
use module::ModuleError;
|
||||||
use module::CommandEnv;
|
use module::CommandEnv;
|
||||||
use module::bm::BMModule;
|
use module::bm::BMModule;
|
||||||
use storage::StorageBackend;
|
use storage::Storage;
|
||||||
|
|
||||||
mod cli;
|
mod cli;
|
||||||
mod configuration;
|
mod configuration;
|
||||||
|
@ -44,7 +44,7 @@ fn main() {
|
||||||
|
|
||||||
debug!("Runtime : {:?}", &rt);
|
debug!("Runtime : {:?}", &rt);
|
||||||
|
|
||||||
let backend = StorageBackend::new(&rt).unwrap_or_else(|e| {
|
let backend = Storage::new(&rt).unwrap_or_else(|e| {
|
||||||
error!("Error: {}", e);
|
error!("Error: {}", e);
|
||||||
exit(1);
|
exit(1);
|
||||||
});
|
});
|
||||||
|
|
|
@ -6,7 +6,7 @@ use regex::Regex;
|
||||||
use module::{CommandEnv, CommandResult, Module, ModuleError};
|
use module::{CommandEnv, CommandResult, Module, ModuleError};
|
||||||
use module::bm::header::{build_header, get_tags_from_header};
|
use module::bm::header::{build_header, get_tags_from_header};
|
||||||
use runtime::Runtime;
|
use runtime::Runtime;
|
||||||
use storage::StorageBackendError;
|
use storage::StorageError;
|
||||||
use storage::file::File;
|
use storage::file::File;
|
||||||
use storage::json::parser::JsonHeaderParser;
|
use storage::json::parser::JsonHeaderParser;
|
||||||
use storage::parser::Parser;
|
use storage::parser::Parser;
|
||||||
|
@ -86,13 +86,13 @@ pub fn remove_command(module: &Module, env: CommandEnv) -> CommandResult {
|
||||||
warn!("Error occured in Filesystem operation: {}", err);
|
warn!("Error occured in Filesystem operation: {}", err);
|
||||||
err
|
err
|
||||||
})
|
})
|
||||||
.collect::<Vec<StorageBackendError>>();
|
.collect::<Vec<StorageError>>();
|
||||||
|
|
||||||
if errs.len() != 0 {
|
if errs.len() != 0 {
|
||||||
warn!("{} Errors occured while removing {} files", errs.len(), nfiles);
|
warn!("{} Errors occured while removing {} files", errs.len(), nfiles);
|
||||||
let moderr = ModuleError::new("File removal failed");
|
let moderr = ModuleError::new("File removal failed");
|
||||||
|
|
||||||
// TODO : Collect StorageBackendErrors
|
// TODO : Collect StorageErrors
|
||||||
|
|
||||||
Err(moderr)
|
Err(moderr)
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -7,7 +7,7 @@ use std::result::Result;
|
||||||
use clap::ArgMatches;
|
use clap::ArgMatches;
|
||||||
|
|
||||||
use runtime::Runtime;
|
use runtime::Runtime;
|
||||||
use storage::StorageBackend;
|
use storage::Storage;
|
||||||
|
|
||||||
pub mod bm;
|
pub mod bm;
|
||||||
pub mod helpers;
|
pub mod helpers;
|
||||||
|
@ -47,7 +47,7 @@ impl Display for ModuleError {
|
||||||
|
|
||||||
pub struct CommandEnv<'a> {
|
pub struct CommandEnv<'a> {
|
||||||
pub rt: &'a Runtime<'a>,
|
pub rt: &'a Runtime<'a>,
|
||||||
pub bk: &'a StorageBackend,
|
pub bk: &'a Storage,
|
||||||
pub matches: &'a ArgMatches<'a, 'a>,
|
pub matches: &'a ArgMatches<'a, 'a>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -22,23 +22,23 @@ use storage::file::File;
|
||||||
use storage::file_id::*;
|
use storage::file_id::*;
|
||||||
use storage::parser::{FileHeaderParser, Parser};
|
use storage::parser::{FileHeaderParser, Parser};
|
||||||
|
|
||||||
pub type BackendOperationResult<T = ()> = Result<T, StorageBackendError>;
|
pub type BackendOperationResult<T = ()> = Result<T, StorageError>;
|
||||||
|
|
||||||
pub struct StorageBackend {
|
pub struct Storage {
|
||||||
basepath: String,
|
basepath: String,
|
||||||
storepath: String,
|
storepath: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl StorageBackend {
|
impl Storage {
|
||||||
|
|
||||||
pub fn new(rt: &Runtime) -> BackendOperationResult<StorageBackend> {
|
pub fn new(rt: &Runtime) -> BackendOperationResult<Storage> {
|
||||||
use self::StorageBackendError as SBE;
|
use self::StorageError as SBE;
|
||||||
|
|
||||||
let storepath = rt.get_rtp() + "/store/";
|
let storepath = rt.get_rtp() + "/store/";
|
||||||
debug!("Trying to create {}", storepath);
|
debug!("Trying to create {}", storepath);
|
||||||
create_dir_all(&storepath).and_then(|_| {
|
create_dir_all(&storepath).and_then(|_| {
|
||||||
debug!("Creating succeeded, constructing backend instance");
|
debug!("Creating succeeded, constructing backend instance");
|
||||||
Ok(StorageBackend {
|
Ok(Storage {
|
||||||
basepath: rt.get_rtp(),
|
basepath: rt.get_rtp(),
|
||||||
storepath: storepath.clone(),
|
storepath: storepath.clone(),
|
||||||
})
|
})
|
||||||
|
@ -49,9 +49,9 @@ impl StorageBackend {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn iter_ids(&self, m: &Module) -> Result<IntoIter<FileID>, StorageBackendError>
|
pub fn iter_ids(&self, m: &Module) -> Result<IntoIter<FileID>, StorageError>
|
||||||
{
|
{
|
||||||
use self::StorageBackendError as SBE;
|
use self::StorageError as SBE;
|
||||||
|
|
||||||
let globstr = self.prefix_of_files_for_module(m) + "*.imag";
|
let globstr = self.prefix_of_files_for_module(m) + "*.imag";
|
||||||
debug!("Globstring = {}", globstr);
|
debug!("Globstring = {}", globstr);
|
||||||
|
@ -67,10 +67,10 @@ impl StorageBackend {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn iter_files<'a, HP>(&self, m: &'a Module, p: &Parser<HP>)
|
pub fn iter_files<'a, HP>(&self, m: &'a Module, p: &Parser<HP>)
|
||||||
-> Result<IntoIter<File<'a>>, StorageBackendError>
|
-> Result<IntoIter<File<'a>>, StorageError>
|
||||||
where HP: FileHeaderParser
|
where HP: FileHeaderParser
|
||||||
{
|
{
|
||||||
use self::StorageBackendError as SBE;
|
use self::StorageError as SBE;
|
||||||
|
|
||||||
self.iter_ids(m)
|
self.iter_ids(m)
|
||||||
.and_then(|ids| {
|
.and_then(|ids| {
|
||||||
|
@ -79,7 +79,7 @@ impl StorageBackend {
|
||||||
Ok(self.filter_map_ids_to_files(m, p, ids).into_iter())
|
Ok(self.filter_map_ids_to_files(m, p, ids).into_iter())
|
||||||
})
|
})
|
||||||
.map_err(|e| {
|
.map_err(|e| {
|
||||||
debug!("StorageBackend::iter_ids() returned error = {:?}", e);
|
debug!("Storage::iter_ids() returned error = {:?}", e);
|
||||||
SBE::new("iter_files()", "Cannot iter on files", None,
|
SBE::new("iter_files()", "Cannot iter on files", None,
|
||||||
Some(Box::new(e)))
|
Some(Box::new(e)))
|
||||||
})
|
})
|
||||||
|
@ -93,7 +93,7 @@ impl StorageBackend {
|
||||||
pub fn put_file<HP>(&self, f: File, p: &Parser<HP>) -> BackendOperationResult
|
pub fn put_file<HP>(&self, f: File, p: &Parser<HP>) -> BackendOperationResult
|
||||||
where HP: FileHeaderParser
|
where HP: FileHeaderParser
|
||||||
{
|
{
|
||||||
use self::StorageBackendError as SBE;
|
use self::StorageError as SBE;
|
||||||
|
|
||||||
let written = write_with_parser(&f, p);
|
let written = write_with_parser(&f, p);
|
||||||
if written.is_err() { return Err(written.err().unwrap()); }
|
if written.is_err() { return Err(written.err().unwrap()); }
|
||||||
|
@ -126,7 +126,7 @@ impl StorageBackend {
|
||||||
pub fn update_file<HP>(&self, f: File, p: &Parser<HP>) -> BackendOperationResult
|
pub fn update_file<HP>(&self, f: File, p: &Parser<HP>) -> BackendOperationResult
|
||||||
where HP: FileHeaderParser
|
where HP: FileHeaderParser
|
||||||
{
|
{
|
||||||
use self::StorageBackendError as SBE;
|
use self::StorageError as SBE;
|
||||||
|
|
||||||
let contents = write_with_parser(&f, p);
|
let contents = write_with_parser(&f, p);
|
||||||
if contents.is_err() { return Err(contents.err().unwrap()); }
|
if contents.is_err() { return Err(contents.err().unwrap()); }
|
||||||
|
@ -203,7 +203,7 @@ impl StorageBackend {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn remove_file(&self, m: &Module, file: File, checked: bool) -> BackendOperationResult {
|
pub fn remove_file(&self, m: &Module, file: File, checked: bool) -> BackendOperationResult {
|
||||||
use self::StorageBackendError as SBE;
|
use self::StorageError as SBE;
|
||||||
|
|
||||||
if checked {
|
if checked {
|
||||||
error!("Checked remove not implemented yet. I will crash now");
|
error!("Checked remove not implemented yet. I will crash now");
|
||||||
|
@ -259,23 +259,23 @@ impl StorageBackend {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct StorageBackendError {
|
pub struct StorageError {
|
||||||
pub action: String, // The file system action in words
|
pub action: String, // The file system action in words
|
||||||
pub desc: String, // A short description
|
pub desc: String, // A short description
|
||||||
pub data_dump: Option<String>, // Data dump, if any
|
pub data_dump: Option<String>, // Data dump, if any
|
||||||
pub caused_by: Option<Box<Error>>, // caused from this error
|
pub caused_by: Option<Box<Error>>, // caused from this error
|
||||||
}
|
}
|
||||||
|
|
||||||
impl StorageBackendError {
|
impl StorageError {
|
||||||
|
|
||||||
fn new<S>(action: S,
|
fn new<S>(action: S,
|
||||||
desc: S,
|
desc: S,
|
||||||
data: Option<String>,
|
data: Option<String>,
|
||||||
cause: Option<Box<Error>>)
|
cause: Option<Box<Error>>)
|
||||||
-> StorageBackendError
|
-> StorageError
|
||||||
where S: Into<String>
|
where S: Into<String>
|
||||||
{
|
{
|
||||||
StorageBackendError {
|
StorageError {
|
||||||
action: action.into(),
|
action: action.into(),
|
||||||
desc: desc.into(),
|
desc: desc.into(),
|
||||||
data_dump: data,
|
data_dump: data,
|
||||||
|
@ -285,7 +285,7 @@ impl StorageBackendError {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Error for StorageBackendError {
|
impl Error for StorageError {
|
||||||
|
|
||||||
fn description(&self) -> &str {
|
fn description(&self) -> &str {
|
||||||
&self.desc[..]
|
&self.desc[..]
|
||||||
|
@ -297,18 +297,18 @@ impl Error for StorageBackendError {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> Display for StorageBackendError {
|
impl<'a> Display for StorageError {
|
||||||
fn fmt(&self, f: &mut Formatter) -> FMTResult {
|
fn fmt(&self, f: &mut Formatter) -> FMTResult {
|
||||||
write!(f, "StorageBackendError[{}]: {}",
|
write!(f, "StorageError[{}]: {}",
|
||||||
self.action, self.desc)
|
self.action, self.desc)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
fn write_with_parser<'a, HP>(f: &File, p: &Parser<HP>) -> Result<String, StorageBackendError>
|
fn write_with_parser<'a, HP>(f: &File, p: &Parser<HP>) -> Result<String, StorageError>
|
||||||
where HP: FileHeaderParser
|
where HP: FileHeaderParser
|
||||||
{
|
{
|
||||||
use self::StorageBackendError as SBE;
|
use self::StorageError as SBE;
|
||||||
|
|
||||||
p.write(f.contents())
|
p.write(f.contents())
|
||||||
.or_else(|err| {
|
.or_else(|err| {
|
||||||
|
|
Loading…
Reference in a new issue