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

View file

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