Clear multi-line sections before adding lines
With multiline support for local.conf, the first line is created with iniset, which will set *all* previous lines to the same thing, and then subsequent lines will be added. Modify the multiline support to first clear existing lines from the section. This causes fatal errors with neutron.conf, which defines drivers with a bunch of service_provider= options, and the current code ends up with the first driver defined in local.conf being present twice. Change-Id: If132a94e53545d9134859aa508da7b9819ede2f8
This commit is contained in:
parent
bfdddebc28
commit
1f65fd64ce
@ -148,6 +148,21 @@ $option = $value
|
|||||||
$xtrace
|
$xtrace
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function inidelete {
|
||||||
|
local xtrace=$(set +o | grep xtrace)
|
||||||
|
set +o xtrace
|
||||||
|
local file=$1
|
||||||
|
local section=$2
|
||||||
|
local option=$3
|
||||||
|
|
||||||
|
[[ -z $section || -z $option ]] && return
|
||||||
|
|
||||||
|
# Remove old values
|
||||||
|
sed -i -e "/^\[$section\]/,/^\[.*\]/ { /^$option[ \t]*=/ d; }" "$file"
|
||||||
|
|
||||||
|
$xtrace
|
||||||
|
}
|
||||||
|
|
||||||
# Set an option in an INI file
|
# Set an option in an INI file
|
||||||
# iniset config-file section option value
|
# iniset config-file section option value
|
||||||
function iniset {
|
function iniset {
|
||||||
|
@ -144,6 +144,7 @@ function merge_config_file {
|
|||||||
else {
|
else {
|
||||||
# For multiline, invoke the ini routines in the reverse order
|
# For multiline, invoke the ini routines in the reverse order
|
||||||
count = cfg_attr_count[section, attr]
|
count = cfg_attr_count[section, attr]
|
||||||
|
print "inidelete " configfile " " section " " attr
|
||||||
print "iniset " configfile " " section " " attr " \"" cfg_attr[section, attr, count - 1] "\""
|
print "iniset " configfile " " section " " attr " \"" cfg_attr[section, attr, count - 1] "\""
|
||||||
for (l = count -2; l >= 0; l--)
|
for (l = count -2; l >= 0; l--)
|
||||||
print "iniadd_literal " configfile " " section " " attr " \"" cfg_attr[section, attr, l] "\""
|
print "iniadd_literal " configfile " " section " " attr " \"" cfg_attr[section, attr, l] "\""
|
||||||
|
@ -34,6 +34,32 @@ empty =
|
|||||||
[eee]
|
[eee]
|
||||||
multi = foo1
|
multi = foo1
|
||||||
multi = foo2
|
multi = foo2
|
||||||
|
|
||||||
|
# inidelete(a)
|
||||||
|
[del_separate_options]
|
||||||
|
a=b
|
||||||
|
b=c
|
||||||
|
|
||||||
|
# inidelete(a)
|
||||||
|
[del_same_option]
|
||||||
|
a=b
|
||||||
|
a=c
|
||||||
|
|
||||||
|
# inidelete(a)
|
||||||
|
[del_missing_option]
|
||||||
|
b=c
|
||||||
|
|
||||||
|
# inidelete(a)
|
||||||
|
[del_missing_option_multi]
|
||||||
|
b=c
|
||||||
|
b=d
|
||||||
|
|
||||||
|
# inidelete(a)
|
||||||
|
[del_no_options]
|
||||||
|
|
||||||
|
# inidelete(a)
|
||||||
|
# no section - del_no_section
|
||||||
|
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
# Test with missing arguments
|
# Test with missing arguments
|
||||||
@ -237,4 +263,33 @@ else
|
|||||||
echo "iniadd with non-exsting failed: $VAL"
|
echo "iniadd with non-exsting failed: $VAL"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Test inidelete
|
||||||
|
del_cases="
|
||||||
|
del_separate_options
|
||||||
|
del_same_option
|
||||||
|
del_missing_option
|
||||||
|
del_missing_option_multi
|
||||||
|
del_no_options
|
||||||
|
del_no_section"
|
||||||
|
|
||||||
|
for x in $del_cases; do
|
||||||
|
inidelete test.ini $x a
|
||||||
|
VAL=$(iniget_multiline test.ini $x a)
|
||||||
|
if [ -z "$VAL" ]; then
|
||||||
|
echo "OK: inidelete $x"
|
||||||
|
else
|
||||||
|
echo "inidelete $x failed: $VAL"
|
||||||
|
fi
|
||||||
|
if [ "$x" = "del_separate_options" -o \
|
||||||
|
"$x" = "del_missing_option" -o \
|
||||||
|
"$x" = "del_missing_option_multi" ]; then
|
||||||
|
VAL=$(iniget_multiline test.ini $x b)
|
||||||
|
if [ "$VAL" = "c" -o "$VAL" = "c d" ]; then
|
||||||
|
echo "OK: inidelete other_options $x"
|
||||||
|
else
|
||||||
|
echo "inidelete other_option $x failed: $VAL"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
rm test.ini
|
rm test.ini
|
||||||
|
Loading…
Reference in New Issue
Block a user