Fix vconftool set command 72/162172/2
authorSemun Lee <semun.lee@samsung.com>
Wed, 29 Nov 2017 10:28:05 +0000 (19:28 +0900)
committerSemun Lee <semun.lee@samsung.com>
Wed, 29 Nov 2017 10:32:28 +0000 (19:32 +0900)
When the key cannot be retrieved while setting the value,
try to create it assuming the key doesn't exist.
Checking "No such file" log is not that robust way checking
if the key exist or not because it depends on "errno" which
can be changed by some libc apis.

Change-Id: I0231632a0df104030c90c9cd01af06d8a9d95552
Signed-off-by: Semun Lee <semun.lee@samsung.com>
vconf-compat/vconftool

index f178561cb4bc36708b0dcbed1e9c2254bd4ea15f..3ba8d33bfc7247bb6eda68dba6ea997af75dc897 100755 (executable)
@@ -132,11 +132,15 @@ do_set() {
        [ -z "${TYPE}" ] && echo "Type '${OPT_TYPE}': Invalid type" && usage
 
        RES=`${BUXTONTOOL} ${OPT_DIRECT} get ${LAYER} ${OPT_KEY} 2>&1`
-       if [ $? -eq 0 ]; then
+       if [ $? -eq 0 ]
+       then
                if [ ${OPT_FORCE} -eq 0 ]; then
                        echo "Key already exist. Use -f option to force update"
                        exit 1
                fi
+       else
+               do_create
+               exit $?
        fi
 
        dbg ${BUXTONTOOL} ${OPT_DIRECT} ${OPT_INIT} set-${TYPE} \
@@ -144,12 +148,6 @@ do_set() {
        RES=`${BUXTONTOOL} ${OPT_DIRECT} ${OPT_INIT} set-${TYPE} \
                ${LAYER} ${OPT_KEY} "${OPT_VAL}" 2>&1`
        if [ $? -ne 0 ]; then
-               echo "$RES" | grep -q "No such file"
-               if [ $? -eq 0 ]; then
-                       do_create
-                       exit $?
-               fi
-
                echo "Error: $RES"
                exit 1
        fi