Merge pull request #557 from matthiasbeyer/libimagstore/no-implicit-create
Libimagstore/no implicit create
This commit is contained in:
commit
b2e50efd50
5 changed files with 41 additions and 1 deletions
|
@ -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.
|
||||
|
|
|
@ -148,6 +148,32 @@ pub fn config_is_valid(config: &Option<Value>) -> 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<Value>) -> Vec<String> {
|
||||
get_aspect_names_for_aspect_position("store-unload-hook-aspects", value)
|
||||
}
|
||||
|
|
|
@ -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",
|
||||
|
|
|
@ -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() {
|
||||
|
|
|
@ -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="--config ./imagrc.toml --override-config store.implicit-create=true --debug --rtp $RUNTIME"
|
||||
out "Calling '$bin $flags $*'"
|
||||
$bin $flags $*
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue