Follow up for creating parent dir for config files
The commit Ia5fcfe6c63f5cc40b11f7e1f3be244d7897f26f6 wanted to enable config file creation even if its parent dir not exists. But missed that the caller of merge_config_file, merge_config_group already checks for hte missing directory. So creating the missing dir in merge_config_file is too late. This patch moves the dir creation to the caller. Change-Id: Ied0f321f31bf8888dce71cc18749f35dde303390 Signed-off-by: Balazs Gibizer <gibi@redhat.com>
This commit is contained in:
@@ -90,7 +90,6 @@ function merge_config_file {
|
||||
local real_configfile
|
||||
real_configfile=$(eval echo $configfile)
|
||||
if [ ! -f $real_configfile ]; then
|
||||
mkdir -p $(dirname $real_configfile) || die $LINENO "could not create the directory of $real_configfile ($configfile)"
|
||||
touch $real_configfile || die $LINENO "could not create config file $real_configfile ($configfile)"
|
||||
fi
|
||||
|
||||
@@ -186,11 +185,15 @@ function merge_config_group {
|
||||
break
|
||||
fi
|
||||
dir=$(dirname $realconfigfile)
|
||||
if [[ -d $dir ]]; then
|
||||
merge_config_file $localfile $group $configfile
|
||||
else
|
||||
die $LINENO "bogus config file specification $configfile ($configfile=$realconfigfile, $dir is not a directory)"
|
||||
|
||||
test -e $dir && ! test -d $dir && die $LINENO "bogus config file specification $configfile ($configfile=$realconfigfile, $dir exists but it is not a directory)"
|
||||
|
||||
if ! [[ -e $dir ]] ; then
|
||||
sudo mkdir -p $dir || die $LINENO "could not create the directory of $real_configfile ($configfile)"
|
||||
sudo chown ${STACK_USER} $dir
|
||||
fi
|
||||
|
||||
merge_config_file $localfile $group $configfile
|
||||
done
|
||||
done
|
||||
}
|
||||
|
||||
@@ -137,6 +137,9 @@ foo=bar
|
||||
[some]
|
||||
random=config
|
||||
|
||||
[[test12|run_tests.sh/test.conf]]
|
||||
foo=bar
|
||||
|
||||
[[test-multi-sections|test-multi-sections.conf]]
|
||||
[sec-1]
|
||||
cfg_item1 = abcd
|
||||
@@ -389,13 +392,12 @@ EXPECT_VAL=0
|
||||
check_result "$VAL" "$EXPECT_VAL"
|
||||
set -e
|
||||
|
||||
echo -n "merge_config_group test10 not directory: "
|
||||
echo -n "merge_config_group test10 create directory: "
|
||||
set +e
|
||||
# function is expected to fail and exit, running it
|
||||
# in a subprocess to let this script proceed
|
||||
(merge_config_group test.conf test10)
|
||||
STACK_USER=$(id -u -n)
|
||||
merge_config_group test.conf test10
|
||||
VAL=$?
|
||||
EXPECT_VAL=255
|
||||
EXPECT_VAL=0
|
||||
check_result "$VAL" "$EXPECT_VAL"
|
||||
set -e
|
||||
|
||||
@@ -414,9 +416,21 @@ random = config
|
||||
non = sense'
|
||||
check_result "$VAL" "$EXPECT_VAL"
|
||||
|
||||
echo -n "merge_config_group test12 directory as file: "
|
||||
set +e
|
||||
# function is expected to fail and exit, running it
|
||||
# in a subprocess to let this script proceed
|
||||
(merge_config_group test.conf test12)
|
||||
VAL=$?
|
||||
EXPECT_VAL=255
|
||||
check_result "$VAL" "$EXPECT_VAL"
|
||||
set -e
|
||||
|
||||
|
||||
rm -f test.conf test1c.conf test2a.conf \
|
||||
test-space.conf test-equals.conf test-strip.conf \
|
||||
test-colon.conf test-env.conf test-multiline.conf \
|
||||
test-multi-sections.conf test-same.conf
|
||||
rm -rf test-etc
|
||||
rm -rf does-not-exist-dir
|
||||
|
||||
|
||||
Reference in New Issue
Block a user