From c8a0c1168d25dbe53419304f95f0b479cecfe9a4 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Mon, 28 Dec 2015 00:39:55 +0100 Subject: [PATCH] Initialize store in Runtime object, pass store path directly into Store object --- src/runtime.rs | 9 +++++++++ src/storage/mod.rs | 7 ++++--- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/runtime.rs b/src/runtime.rs index 92c38f6e..a2b1eed1 100644 --- a/src/runtime.rs +++ b/src/runtime.rs @@ -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 diff --git a/src/storage/mod.rs b/src/storage/mod.rs index 998bba95..4905440b 100644 --- a/src/storage/mod.rs +++ b/src/storage/mod.rs @@ -22,13 +22,15 @@ use storage::file::header::data::FileHeaderData; type Cache = HashMap>>; pub struct Store { + storepath: String, cache : RefCell, } 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(&self, - storepath: String, p: &Parser, f: Rc>) -> 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| {