iniset: fix handling of keys with spaces
Ceph for example uses them. Creation already worked, but not updates of existing keys. Closes-Bug: 1774956 Change-Id: I20cb61c08079b9cd9ad56ac875525abf1442bff6
This commit is contained in:
parent
0d1bee1768
commit
c7c67658c1
@ -200,7 +200,7 @@ $option = $value
|
|||||||
local sep
|
local sep
|
||||||
sep=$(echo -ne "\x01")
|
sep=$(echo -ne "\x01")
|
||||||
# Replace it
|
# Replace it
|
||||||
$sudo sed -i -e '/^\['${section}'\]/,/^\[.*\]/ s'${sep}'^\('${option}'[ \t]*=[ \t]*\).*$'${sep}'\1'"${value}"${sep} "$file"
|
$sudo sed -i -e '/^\['${section}'\]/,/^\[.*\]/ s'${sep}'^\('"${option}"'[ \t]*=[ \t]*\).*$'${sep}'\1'"${value}"${sep} "$file"
|
||||||
fi
|
fi
|
||||||
$xtrace
|
$xtrace
|
||||||
}
|
}
|
||||||
|
@ -44,6 +44,9 @@ empty =
|
|||||||
multi = foo1
|
multi = foo1
|
||||||
multi = foo2
|
multi = foo2
|
||||||
|
|
||||||
|
[key_with_spaces]
|
||||||
|
rgw special key = something
|
||||||
|
|
||||||
# inidelete(a)
|
# inidelete(a)
|
||||||
[del_separate_options]
|
[del_separate_options]
|
||||||
a=b
|
a=b
|
||||||
@ -82,8 +85,9 @@ fi
|
|||||||
|
|
||||||
# test iniget_sections
|
# test iniget_sections
|
||||||
VAL=$(iniget_sections "${TEST_INI}")
|
VAL=$(iniget_sections "${TEST_INI}")
|
||||||
assert_equal "$VAL" "default aaa bbb ccc ddd eee del_separate_options \
|
assert_equal "$VAL" "default aaa bbb ccc ddd eee key_with_spaces \
|
||||||
del_same_option del_missing_option del_missing_option_multi del_no_options"
|
del_separate_options del_same_option del_missing_option \
|
||||||
|
del_missing_option_multi del_no_options"
|
||||||
|
|
||||||
# Test with missing arguments
|
# Test with missing arguments
|
||||||
BEFORE=$(cat ${TEST_INI})
|
BEFORE=$(cat ${TEST_INI})
|
||||||
@ -209,6 +213,20 @@ iniset $SUDO_ARG ${INI_TMP_ETC_DIR}/test.new.ini test foo bar
|
|||||||
VAL=$(iniget ${INI_TMP_ETC_DIR}/test.new.ini test foo)
|
VAL=$(iniget ${INI_TMP_ETC_DIR}/test.new.ini test foo)
|
||||||
assert_equal "$VAL" "bar" "iniset created file"
|
assert_equal "$VAL" "bar" "iniset created file"
|
||||||
|
|
||||||
|
# test creation of keys with spaces
|
||||||
|
iniset ${SUDO_ARG} ${TEST_INI} key_with_spaces "rgw another key" somethingelse
|
||||||
|
VAL=$(iniget ${TEST_INI} key_with_spaces "rgw another key")
|
||||||
|
assert_equal "$VAL" "somethingelse" "iniset created a key with spaces"
|
||||||
|
|
||||||
|
# test update of keys with spaces
|
||||||
|
iniset ${SUDO_ARG} ${TEST_INI} key_with_spaces "rgw special key" newvalue
|
||||||
|
VAL=$(iniget ${TEST_INI} key_with_spaces "rgw special key")
|
||||||
|
assert_equal "$VAL" "newvalue" "iniset updated a key with spaces"
|
||||||
|
|
||||||
|
inidelete ${SUDO_ARG} ${TEST_INI} key_with_spaces "rgw another key"
|
||||||
|
VAL=$(iniget ${TEST_INI} key_with_spaces "rgw another key")
|
||||||
|
assert_empty VAL "inidelete removed a key with spaces"
|
||||||
|
|
||||||
$SUDO rm -rf ${INI_TMP_DIR}
|
$SUDO rm -rf ${INI_TMP_DIR}
|
||||||
|
|
||||||
report_results
|
report_results
|
||||||
|
Loading…
Reference in New Issue
Block a user