Refactor libimagrt+libimagstore to pass whole configuration object

Before we extracted the store configuration from the configuration
toml::Value object and passed it to the store.

This is unecessary overhead.

Now we pass the whole configuration object and let the store extract the
required values.
This commit is contained in:
Matthias Beyer 2017-12-22 11:24:04 +01:00
parent 174d8d76e9
commit 0ed636bb06
10 changed files with 24 additions and 33 deletions

View file

@ -24,7 +24,6 @@ use std::process::exit;
pub use clap::App;
use toml::Value;
use toml_query::read::TomlValueReadExt;
use clap::{Arg, ArgMatches};
use log;
@ -138,22 +137,12 @@ impl<'a> Runtime<'a> {
debug!("RTP path = {:?}", rtp);
debug!("Store path = {:?}", storepath);
let store_config = match config {
Some(ref c) => c.read("store").chain_err(|| RuntimeErrorKind::Instantiate)?.cloned(),
None => None,
};
if matches.is_present(Runtime::arg_debugging_name()) {
debug!("Config: {:?}\n", config);
debug!("Store-config: {:?}\n", store_config);
}
let store_result = if cli_app.use_inmemory_fs() {
Store::new_with_backend(storepath,
store_config,
&config,
Box::new(InMemoryFileAbstraction::new()))
} else {
Store::new(storepath, store_config)
Store::new(storepath, &config)
};
store_result.map(|store| {

View file

@ -27,10 +27,10 @@ use toml_query::read::TomlValueReadExt;
/// Checks whether the store configuration has a key "implicit-create" which maps to a boolean
/// value. If that key is present, the boolean is returned, otherwise false is returned.
pub fn config_implicit_store_create_allowed(config: Option<&Value>) -> Result<bool> {
let key = "implicit-create";
pub fn config_implicit_store_create_allowed(config: &Option<Value>) -> Result<bool> {
let key = "store.implicit-create";
if let Some(t) = config {
if let Some(ref t) = *config {
t.read(key)?
.ok_or(SE::from_kind(SEK::ConfigKeyMissingError(key)))?
.as_bool()
@ -47,31 +47,33 @@ mod tests {
#[test]
fn test_implicit_store_create_allowed_no_toml() {
assert!(!config_implicit_store_create_allowed(None));
assert!(!config_implicit_store_create_allowed(&None).unwrap());
}
#[test]
fn test_implicit_store_create_allowed_toml_empty() {
let config = toml_from_str("").unwrap();
assert!(!config_implicit_store_create_allowed(Some(config).as_ref()));
assert!(config_implicit_store_create_allowed(&Some(config)).is_err());
}
#[test]
fn test_implicit_store_create_allowed_toml_false() {
let config = toml_from_str(r#"
[store]
implicit-create = false
"#).unwrap();
assert!(!config_implicit_store_create_allowed(Some(config).as_ref()));
assert!(!config_implicit_store_create_allowed(&Some(config)).unwrap());
}
#[test]
fn test_implicit_store_create_allowed_toml_true() {
let config = toml_from_str(r#"
[store]
implicit-create = true
"#).unwrap();
assert!(config_implicit_store_create_allowed(Some(config).as_ref()));
assert!(config_implicit_store_create_allowed(&Some(config)).unwrap());
}
}

View file

@ -236,7 +236,7 @@ impl Store {
///
/// - On success: Store object
///
pub fn new(location: PathBuf, store_config: Option<&Value>) -> Result<Store> {
pub fn new(location: PathBuf, store_config: &Option<Value>) -> Result<Store> {
let backend = Box::new(FSFileAbstraction::new());
Store::new_with_backend(location, store_config, backend)
}
@ -246,7 +246,7 @@ impl Store {
///
/// Do not use directly, only for testing purposes.
pub fn new_with_backend(location: PathBuf,
store_config: Option<&Value>,
store_config: &Option<Value>,
backend: Box<FileAbstraction>) -> Result<Store> {
use configuration::*;
@ -1293,7 +1293,7 @@ mod store_tests {
pub fn get_store() -> Store {
let backend = Box::new(InMemoryFileAbstraction::new());
Store::new_with_backend(PathBuf::from("/"), None, backend).unwrap()
Store::new_with_backend(PathBuf::from("/"), &None, backend).unwrap()
}
#[test]
@ -1346,7 +1346,7 @@ mod store_tests {
let backend = StdIoFileAbstraction::new(&mut input, output.clone(), mapper).unwrap();
let backend = Box::new(backend);
Store::new_with_backend(PathBuf::from("/"), None, backend).unwrap()
Store::new_with_backend(PathBuf::from("/"), &None, backend).unwrap()
};
for n in 1..100 {
@ -1619,7 +1619,7 @@ mod store_tests {
let backend = InMemoryFileAbstraction::new();
let backend = Box::new(backend);
Store::new_with_backend(PathBuf::from("/"), None, backend).unwrap()
Store::new_with_backend(PathBuf::from("/"), &None, backend).unwrap()
};
for n in 1..100 {
@ -1694,7 +1694,7 @@ mod store_tests {
let backend = StdIoFileAbstraction::new(&mut input, output, mapper).unwrap();
let backend = Box::new(backend);
Store::new_with_backend(PathBuf::from("/"), None, backend).unwrap()
Store::new_with_backend(PathBuf::from("/"), &None, backend).unwrap()
};
// Replacing the backend

View file

@ -38,7 +38,7 @@ mod test {
use libimagstore::file_abstraction::InMemoryFileAbstraction;
let backend = Box::new(InMemoryFileAbstraction::new());
Store::new_with_backend(PathBuf::from("/"), None, backend).unwrap()
Store::new_with_backend(PathBuf::from("/"), &None, backend).unwrap()
}
#[test]

View file

@ -130,7 +130,7 @@ mod tests {
pub fn get_store() -> Store {
use libimagstore::store::InMemoryFileAbstraction;
let backend = Box::new(InMemoryFileAbstraction::new());
Store::new_with_backend(PathBuf::from("/"), None, backend).unwrap()
Store::new_with_backend(PathBuf::from("/"), &None, backend).unwrap()
}
#[test]

View file

@ -225,7 +225,7 @@ mod tests {
pub fn get_store() -> Store {
use libimagstore::store::InMemoryFileAbstraction;
let backend = Box::new(InMemoryFileAbstraction::new());
Store::new_with_backend(PathBuf::from("/"), None, backend).unwrap()
Store::new_with_backend(PathBuf::from("/"), &None, backend).unwrap()
}
#[test]

View file

@ -116,7 +116,7 @@ mod tests {
fn get_store() -> Store {
use libimagstore::file_abstraction::InMemoryFileAbstraction;
let backend = Box::new(InMemoryFileAbstraction::new());
Store::new_with_backend(PathBuf::from("/"), None, backend).unwrap()
Store::new_with_backend(PathBuf::from("/"), &None, backend).unwrap()
}
#[test]

View file

@ -421,7 +421,7 @@ mod tests {
pub fn get_store() -> Store {
use libimagstore::file_abstraction::InMemoryFileAbstraction;
let backend = Box::new(InMemoryFileAbstraction::new());
Store::new_with_backend(PathBuf::from("/"), None, backend).unwrap()
Store::new_with_backend(PathBuf::from("/"), &None, backend).unwrap()
}

View file

@ -778,7 +778,7 @@ mod test {
pub fn get_store() -> Store {
use libimagstore::file_abstraction::InMemoryFileAbstraction;
let backend = Box::new(InMemoryFileAbstraction::new());
Store::new_with_backend(PathBuf::from("/"), None, backend).unwrap()
Store::new_with_backend(PathBuf::from("/"), &None, backend).unwrap()
}
#[test]

View file

@ -225,7 +225,7 @@ mod tests {
pub fn get_store() -> Store {
use libimagstore::file_abstraction::InMemoryFileAbstraction;
let fs = InMemoryFileAbstraction::new();
Store::new_with_backend(PathBuf::from("/"), None, Box::new(fs)).unwrap()
Store::new_with_backend(PathBuf::from("/"), &None, Box::new(fs)).unwrap()
}
#[test]