Initialize store in Runtime object, pass store path directly into Store object

This commit is contained in:
Matthias Beyer 2015-12-28 00:39:55 +01:00
parent 52787f5108
commit c8a0c1168d
2 changed files with 13 additions and 3 deletions

View File

@ -6,6 +6,8 @@ use log::{LogRecord, LogLevel, LogLevelFilter, LogMetadata, SetLoggerError};
pub use cli::CliConfig;
pub use configuration::Configuration as Cfg;
use storage::Store;
pub struct ImagLogger {
lvl: LogLevel,
}
@ -52,14 +54,17 @@ impl log::Log for ImagLogger {
pub struct Runtime<'a> {
pub config : CliConfig<'a>,
pub configuration : Cfg,
pub store : Store,
}
impl<'a> Runtime<'a> {
pub fn new(cfg: Cfg, config : CliConfig<'a>) -> Runtime<'a> {
let sp = config.store_path().unwrap_or(cfg.store_path());
Runtime {
config: config,
configuration: cfg,
store: Store::new(sp),
}
}
@ -75,6 +80,10 @@ impl<'a> Runtime<'a> {
self.config.store_path().unwrap_or(self.configuration.store_path())
}
pub fn store(&self) -> &Store {
&self.store
}
pub fn get_rtp(&self) -> String {
if let Some(rtp) = self.config.get_rtp() {
rtp

View File

@ -22,13 +22,15 @@ use storage::file::header::data::FileHeaderData;
type Cache = HashMap<FileID, Rc<RefCell<File>>>;
pub struct Store {
storepath: String,
cache : RefCell<Cache>,
}
impl Store {
pub fn new() -> Store {
pub fn new(storepath: String) -> Store {
Store {
storepath: storepath,
cache: RefCell::new(HashMap::new()),
}
}
@ -115,7 +117,6 @@ impl Store {
}
pub fn persist<HP>(&self,
storepath: String,
p: &Parser<HP>,
f: Rc<RefCell<File>>) -> bool
where HP: FileHeaderParser
@ -129,7 +130,7 @@ impl Store {
let path = {
let ids : String = file.id().clone().into();
format!("{}/{}-{}.imag", storepath, file.owning_module_name, ids)
format!("{}/{}-{}.imag", self.storepath, file.owning_module_name, ids)
};
FSFile::create(&path).map(|mut fsfile| {