From d017f227575b7c82c864651e8710ba9f12095d09 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Sat, 16 Jul 2016 22:36:06 +0200 Subject: [PATCH 1/6] Add setting in imagrc, to allow implictely creating the store path --- imagrc.toml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/imagrc.toml b/imagrc.toml index f11659e1..82a2dae3 100644 --- a/imagrc.toml +++ b/imagrc.toml @@ -3,6 +3,10 @@ [store] +# Set to false if you do not want imag to create the directory where the store +# lives implicitely +implicit-create = false + # Hooks which get executed right before the Store is closed. # They get the store path as StoreId passed, so they can alter the complete # store, so these hooks should be chosen carefully. From 442b1537be359d646ba192900c7b090b4b1aa3fd Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Sat, 16 Jul 2016 22:36:36 +0200 Subject: [PATCH 2/6] Add helper to check config for implicit-create --- libimagstore/src/configuration.rs | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/libimagstore/src/configuration.rs b/libimagstore/src/configuration.rs index 33e2dd6f..ff94a1a3 100644 --- a/libimagstore/src/configuration.rs +++ b/libimagstore/src/configuration.rs @@ -148,6 +148,32 @@ pub fn config_is_valid(config: &Option) -> bool { } } +/// 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>) -> bool { + config.map(|t| { + match *t { + Value::Table(ref t) => { + match t.get("implicit-create") { + Some(&Value::Boolean(b)) => b, + Some(_) => { + warn!("Key 'implicit-create' does not contain a Boolean value"); + false + } + None => { + warn!("Key 'implicit-create' in store configuration missing"); + false + }, + } + } + _ => { + warn!("Store configuration seems to be no Table"); + false + }, + } + }).unwrap_or(false) +} + pub fn get_store_unload_aspect_names(value: &Option) -> Vec { get_aspect_names_for_aspect_position("store-unload-hook-aspects", value) } From 4d650a63f797f1cec97b6cf28ca7484c17674458 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Sat, 16 Jul 2016 22:36:53 +0200 Subject: [PATCH 3/6] Add error kind for implicit create denied --- libimagstore/src/error.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/libimagstore/src/error.rs b/libimagstore/src/error.rs index d9a7fd99..30a00ab4 100644 --- a/libimagstore/src/error.rs +++ b/libimagstore/src/error.rs @@ -6,6 +6,7 @@ pub struct CustomErrorData {} generate_custom_error_types!(StoreError, StoreErrorKind, CustomErrorData, ConfigurationError => "Store Configuration Error", + CreateStoreDirDenied => "Creating store directory implicitely denied", FileError => "File Error", IoError => "IO Error", IdLocked => "ID locked", From 0ba67f78736ed8f0c642816c735fcad2701a50dc Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Sat, 16 Jul 2016 22:37:07 +0200 Subject: [PATCH 4/6] Check whether implictely creating the store path is allowed --- libimagstore/src/store.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/libimagstore/src/store.rs b/libimagstore/src/store.rs index be05710e..8e63329f 100644 --- a/libimagstore/src/store.rs +++ b/libimagstore/src/store.rs @@ -212,6 +212,15 @@ impl Store { debug!("Building new Store object"); if !location.exists() { + if !config_implicit_store_create_allowed(store_config.as_ref()) { + warn!("Implicitely creating store directory is denied"); + warn!(" -> Either because configuration does not allow it"); + warn!(" -> or because there is no configuration"); + return Err(SEK::CreateStoreDirDenied.into_error()) + .map_err_into(SEK::FileError) + .map_err_into(SEK::IoError); + } + debug!("Creating store path"); let c = create_dir_all(location.clone()); if c.is_err() { From bcab7f807d2ea44668ac948bc0e270c66dc3865d Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Mon, 25 Jul 2016 17:05:14 +0200 Subject: [PATCH 5/6] tests: Call imag binaries with config override for implicit store creation --- tests/utils.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/utils.sh b/tests/utils.sh index 6fc23ad8..61aa5b87 100644 --- a/tests/utils.sh +++ b/tests/utils.sh @@ -37,7 +37,7 @@ imag-call-binary() { local binary=$1; shift [[ -d $searchdir ]] || { err "FATAL: No directory $searchdir"; exit 1; } local bin=$(find $searchdir -iname $binary -type f -executable) - local flags="--debug --rtp $RUNTIME" + local flags="--override-config store.implicit-create=true --debug --rtp $RUNTIME" out "Calling '$bin $flags $*'" $bin $flags $* } From f999c912836ad2e1667143a6187a1e32bcd196f5 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Mon, 25 Jul 2016 18:23:16 +0200 Subject: [PATCH 6/6] tests: Add --config setting --- tests/utils.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/utils.sh b/tests/utils.sh index 61aa5b87..e0153bdd 100644 --- a/tests/utils.sh +++ b/tests/utils.sh @@ -37,7 +37,7 @@ imag-call-binary() { local binary=$1; shift [[ -d $searchdir ]] || { err "FATAL: No directory $searchdir"; exit 1; } local bin=$(find $searchdir -iname $binary -type f -executable) - local flags="--override-config store.implicit-create=true --debug --rtp $RUNTIME" + local flags="--config ./imagrc.toml --override-config store.implicit-create=true --debug --rtp $RUNTIME" out "Calling '$bin $flags $*'" $bin $flags $* }