Merge "Provide an error message on bogus config file spec"

This commit is contained in:
Jenkins 2015-11-04 15:39:03 +00:00 committed by Gerrit Code Review
commit 73de4a42d9
2 changed files with 57 additions and 2 deletions

View File

@ -92,7 +92,7 @@ function merge_config_file {
local real_configfile
real_configfile=$(eval echo $configfile)
if [ ! -f $real_configfile ]; then
touch $real_configfile
touch $real_configfile || die $LINENO "could not create config file $real_configfile ($configfile)"
fi
get_meta_section $file $matchgroup $configfile | \
@ -178,8 +178,18 @@ function merge_config_group {
local configfile group
for group in $matchgroups; do
for configfile in $(get_meta_section_files $localfile $group); do
if [[ -d $(dirname $(eval "echo $configfile")) ]]; then
local realconfigfile
local dir
realconfigfile=$(eval "echo $configfile")
if [[ -z $realconfigfile ]]; then
die $LINENO "bogus config file specification: $configfile is undefined"
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)"
fi
done
done

View File

@ -23,6 +23,12 @@ function check_result {
fi
}
# mock function-common:die so that it does not
# interupt our test script
function die {
exit -1
}
TEST_1C_ADD="[eee]
type=new
multi = foo2"
@ -110,6 +116,15 @@ attr = strip_trailing_space
[DEFAULT]
servers=10.11.12.13:80
[[test8|/permission-denied.conf]]
foo=bar
[[test9|\$UNDEF]]
foo=bar
[[test10|does-not-exist-dir/test.conf]]
foo=bar
[[test-multi-sections|test-multi-sections.conf]]
[sec-1]
cfg_item1 = abcd
@ -340,6 +355,36 @@ EXPECT_VAL="
servers = 10.11.12.13:80"
check_result "$VAL" "$EXPECT_VAL"
echo "merge_config_file test8 non-touchable conf file: "
set +e
# function is expected to fail and exit, running it
# in a subprocess to let this script proceed
(merge_config_file test.conf test8 /permission-denied.conf)
VAL=$?
EXPECT_VAL=255
check_result "$VAL" "$EXPECT_VAL"
set -e
echo -n "merge_config_group test9 undefined conf 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 test9)
VAL=$?
EXPECT_VAL=255
check_result "$VAL" "$EXPECT_VAL"
set -e
echo -n "merge_config_group test10 not 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)
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 \