| ... | ... |
@@ -92,7 +92,7 @@ function merge_config_file {
|
| 92 | 92 |
local real_configfile |
| 93 | 93 |
real_configfile=$(eval echo $configfile) |
| 94 | 94 |
if [ ! -f $real_configfile ]; then |
| 95 |
- touch $real_configfile |
|
| 95 |
+ touch $real_configfile || die $LINENO "could not create config file $real_configfile ($configfile)" |
|
| 96 | 96 |
fi |
| 97 | 97 |
|
| 98 | 98 |
get_meta_section $file $matchgroup $configfile | \ |
| ... | ... |
@@ -178,8 +178,18 @@ function merge_config_group {
|
| 178 | 178 |
local configfile group |
| 179 | 179 |
for group in $matchgroups; do |
| 180 | 180 |
for configfile in $(get_meta_section_files $localfile $group); do |
| 181 |
- if [[ -d $(dirname $(eval "echo $configfile")) ]]; then |
|
| 181 |
+ local realconfigfile |
|
| 182 |
+ local dir |
|
| 183 |
+ |
|
| 184 |
+ realconfigfile=$(eval "echo $configfile") |
|
| 185 |
+ if [[ -z $realconfigfile ]]; then |
|
| 186 |
+ die $LINENO "bogus config file specification: $configfile is undefined" |
|
| 187 |
+ fi |
|
| 188 |
+ dir=$(dirname $realconfigfile) |
|
| 189 |
+ if [[ -d $dir ]]; then |
|
| 182 | 190 |
merge_config_file $localfile $group $configfile |
| 191 |
+ else |
|
| 192 |
+ die $LINENO "bogus config file specification $configfile ($configfile=$realconfigfile, $dir is not a directory)" |
|
| 183 | 193 |
fi |
| 184 | 194 |
done |
| 185 | 195 |
done |
| ... | ... |
@@ -23,6 +23,12 @@ function check_result {
|
| 23 | 23 |
fi |
| 24 | 24 |
} |
| 25 | 25 |
|
| 26 |
+# mock function-common:die so that it does not |
|
| 27 |
+# interupt our test script |
|
| 28 |
+function die {
|
|
| 29 |
+ exit -1 |
|
| 30 |
+} |
|
| 31 |
+ |
|
| 26 | 32 |
TEST_1C_ADD="[eee] |
| 27 | 33 |
type=new |
| 28 | 34 |
multi = foo2" |
| ... | ... |
@@ -110,6 +116,15 @@ attr = strip_trailing_space |
| 110 | 110 |
[DEFAULT] |
| 111 | 111 |
servers=10.11.12.13:80 |
| 112 | 112 |
|
| 113 |
+[[test8|/permission-denied.conf]] |
|
| 114 |
+foo=bar |
|
| 115 |
+ |
|
| 116 |
+[[test9|\$UNDEF]] |
|
| 117 |
+foo=bar |
|
| 118 |
+ |
|
| 119 |
+[[test10|does-not-exist-dir/test.conf]] |
|
| 120 |
+foo=bar |
|
| 121 |
+ |
|
| 113 | 122 |
[[test-multi-sections|test-multi-sections.conf]] |
| 114 | 123 |
[sec-1] |
| 115 | 124 |
cfg_item1 = abcd |
| ... | ... |
@@ -340,6 +355,36 @@ EXPECT_VAL=" |
| 340 | 340 |
servers = 10.11.12.13:80" |
| 341 | 341 |
check_result "$VAL" "$EXPECT_VAL" |
| 342 | 342 |
|
| 343 |
+echo "merge_config_file test8 non-touchable conf file: " |
|
| 344 |
+set +e |
|
| 345 |
+# function is expected to fail and exit, running it |
|
| 346 |
+# in a subprocess to let this script proceed |
|
| 347 |
+(merge_config_file test.conf test8 /permission-denied.conf) |
|
| 348 |
+VAL=$? |
|
| 349 |
+EXPECT_VAL=255 |
|
| 350 |
+check_result "$VAL" "$EXPECT_VAL" |
|
| 351 |
+set -e |
|
| 352 |
+ |
|
| 353 |
+echo -n "merge_config_group test9 undefined conf file: " |
|
| 354 |
+set +e |
|
| 355 |
+# function is expected to fail and exit, running it |
|
| 356 |
+# in a subprocess to let this script proceed |
|
| 357 |
+(merge_config_group test.conf test9) |
|
| 358 |
+VAL=$? |
|
| 359 |
+EXPECT_VAL=255 |
|
| 360 |
+check_result "$VAL" "$EXPECT_VAL" |
|
| 361 |
+set -e |
|
| 362 |
+ |
|
| 363 |
+echo -n "merge_config_group test10 not directory: " |
|
| 364 |
+set +e |
|
| 365 |
+# function is expected to fail and exit, running it |
|
| 366 |
+# in a subprocess to let this script proceed |
|
| 367 |
+(merge_config_group test.conf test10) |
|
| 368 |
+VAL=$? |
|
| 369 |
+EXPECT_VAL=255 |
|
| 370 |
+check_result "$VAL" "$EXPECT_VAL" |
|
| 371 |
+set -e |
|
| 372 |
+ |
|
| 343 | 373 |
rm -f test.conf test1c.conf test2a.conf \ |
| 344 | 374 |
test-space.conf test-equals.conf test-strip.conf \ |
| 345 | 375 |
test-colon.conf test-env.conf test-multiline.conf \ |