Browse code

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
(cherry picked from commit 410f5c0016a9d3b1fbd42b95ce1402a1c614e3d3)

Ryota MIBU authored on 2014/04/04 02:00:31
Showing 2 changed files
... ...
@@ -82,8 +82,6 @@ function merge_config_file {
82 82
     local matchgroup=$2
83 83
     local configfile=$3
84 84
 
85
-    [[ -r $configfile ]] || touch $configfile
86
-
87 85
     get_meta_section $file $matchgroup $configfile | \
88 86
     $CONFIG_AWK_CMD -v configfile=$configfile '
89 87
         BEGIN { section = "" }
... ...
@@ -114,7 +112,7 @@ function merge_config_group {
114 114
 
115 115
     for group in $matchgroups; do
116 116
         for configfile in $(get_meta_section_files $localfile $group); do
117
-            if [[ -d $(dirname $configfile) ]]; then
117
+            if [[ -d $(dirname $(eval "echo $configfile")) ]]; then
118 118
                 merge_config_file $localfile $group $configfile
119 119
             fi
120 120
         done
... ...
@@ -42,6 +42,17 @@ type=original
42 42
 EOF
43 43
 }
44 44
 
45
+function setup_test4 {
46
+    mkdir -p test-etc
47
+    cat >test-etc/test4.conf <<EOF
48
+[fff]
49
+# original comment
50
+type=original
51
+EOF
52
+    TEST4_DIR="test-etc"
53
+    TEST4_FILE="test4.conf"
54
+}
55
+
45 56
 cat >test.conf <<EOF
46 57
 [[test1|test1a.conf]]
47 58
 [default]
... ...
@@ -76,8 +87,11 @@ $TEST_1C_ADD
76 76
 attribute=value
77 77
  
78 78
 # the above line has a single space
79
-EOF
80 79
 
80
+[[test4|\$TEST4_DIR/\$TEST4_FILE]]
81
+[fff]
82
+type=new
83
+EOF
81 84
 
82 85
 echo -n "get_meta_section_files: test0 doesn't exist: "
83 86
 VAL=$(get_meta_section_files test.conf test0)
... ...
@@ -192,4 +206,24 @@ EXPECT_VAL="
192 192
 attribute = value"
193 193
 check_result "$VAL" "$EXPECT_VAL"
194 194
 
195
+echo -n "merge_config_group test4 variable filename: "
196
+setup_test4
197
+merge_config_group test.conf test4
198
+VAL=$(cat test-etc/test4.conf)
199
+EXPECT_VAL="[fff]
200
+# original comment
201
+type=new"
202
+check_result "$VAL" "$EXPECT_VAL"
203
+
204
+echo -n "merge_config_group test4 variable filename (not exist): "
205
+setup_test4
206
+rm test-etc/test4.conf
207
+merge_config_group test.conf test4
208
+VAL=$(cat test-etc/test4.conf)
209
+EXPECT_VAL="
210
+[fff]
211
+type = new"
212
+check_result "$VAL" "$EXPECT_VAL"
213
+
195 214
 rm -f test.conf test1c.conf test2a.conf test-space.conf
215
+rm -rf test-etc