Fix unsubstituted filename creation

Since merge_config_file() tries to create an unsubstituted config file,
stack.sh fails due to permission denied in the file creation when you
use '[[post-config|/$Q_PLUGIN_CONF_FILE]]' and the file does not exist.

This patch deletes unnecessary 'touch' command, because the file will
be made by 'iniset' function in the next command line with evaled
string from 'configfile'.

This patch also fixes merge_config_group() to use evaled 'configfile'
when it checks the directory of the config file exists.

Change-Id: I608847a34143b5c6a1708c180186dd88a32dd44b
Closes-bug: #1294213
This commit is contained in:
Ryota MIBU 2014-04-04 02:00:31 +09:00
parent 4fbb8137af
commit 410f5c0016
2 changed files with 36 additions and 4 deletions

View File

@ -82,8 +82,6 @@ function merge_config_file {
local matchgroup=$2
local configfile=$3
[[ -r $configfile ]] || touch $configfile
get_meta_section $file $matchgroup $configfile | \
$CONFIG_AWK_CMD -v configfile=$configfile '
BEGIN { section = "" }
@ -114,7 +112,7 @@ function merge_config_group {
for group in $matchgroups; do
for configfile in $(get_meta_section_files $localfile $group); do
if [[ -d $(dirname $configfile) ]]; then
if [[ -d $(dirname $(eval "echo $configfile")) ]]; then
merge_config_file $localfile $group $configfile
fi
done

View File

@ -42,6 +42,17 @@ type=original
EOF
}
function setup_test4 {
mkdir -p test-etc
cat >test-etc/test4.conf <<EOF
[fff]
# original comment
type=original
EOF
TEST4_DIR="test-etc"
TEST4_FILE="test4.conf"
}
cat >test.conf <<EOF
[[test1|test1a.conf]]
[default]
@ -76,8 +87,11 @@ $TEST_1C_ADD
attribute=value
# the above line has a single space
EOF
[[test4|\$TEST4_DIR/\$TEST4_FILE]]
[fff]
type=new
EOF
echo -n "get_meta_section_files: test0 doesn't exist: "
VAL=$(get_meta_section_files test.conf test0)
@ -192,4 +206,24 @@ EXPECT_VAL="
attribute = value"
check_result "$VAL" "$EXPECT_VAL"
echo -n "merge_config_group test4 variable filename: "
setup_test4
merge_config_group test.conf test4
VAL=$(cat test-etc/test4.conf)
EXPECT_VAL="[fff]
# original comment
type=new"
check_result "$VAL" "$EXPECT_VAL"
echo -n "merge_config_group test4 variable filename (not exist): "
setup_test4
rm test-etc/test4.conf
merge_config_group test.conf test4
VAL=$(cat test-etc/test4.conf)
EXPECT_VAL="
[fff]
type = new"
check_result "$VAL" "$EXPECT_VAL"
rm -f test.conf test1c.conf test2a.conf test-space.conf
rm -rf test-etc