correct use of tomb's internal temp file mechanism for sphinx

This commit is contained in:
Jaromil 2019-05-05 10:21:38 +02:00
parent 5ce9960207
commit a6d252c949

11
tomb
View File

@ -527,15 +527,14 @@ sphinx_get_password() {
{ option_is_set --sphx-user && option_is_set --sphx-host } && { { option_is_set --sphx-user && option_is_set --sphx-host } && {
# value error in sphinx doesn't set exit code # value error in sphinx doesn't set exit code
# using tempfile as a workaround to notice the error # using tempfile as a workaround to notice the error
errorfile=$(mktemp /tmp/tomb_error.XXXXXXXXX) _tmp_create
errorfile=$TOMBTMP
password=$(echo "$1" | sphinx get $(option_value --sphx-user) $(option_value --sphx-host) 2>$errorfile) password=$(echo "$1" | sphinx get $(option_value --sphx-user) $(option_value --sphx-host) 2>$errorfile)
if ! grep -q "ValueError: fail" $errorfile ; then if ! grep -q "ValueError: fail" $errorfile ; then
echo "$password" echo "$password"
rm $errorfile
return 0 return 0
else else
_warning "sphinx returns error: ::1 error::" $(cat $errorfile) _warning "sphinx returns error: ::1 error::" $(cat $errorfile)
rm $errorfile
_failure "Failed to retrieve actual password with sphinx." _failure "Failed to retrieve actual password with sphinx."
fi fi
} || { } || {
@ -552,24 +551,22 @@ sphinx_set_password() {
{ option_is_set --sphx-user && option_is_set --sphx-host } && { { option_is_set --sphx-user && option_is_set --sphx-host } && {
# value error in sphinx doesn't set exit code # value error in sphinx doesn't set exit code
# using tempfile as a workaround to notice the error # using tempfile as a workaround to notice the error
errorfile=$(mktemp /tmp/tomb_error.XXXXXXXXX) _tmp_create
errorfile=$TOMBTMP
# check first if this host/user combination exists in store # check first if this host/user combination exists in store
# if yes, there is no need to make a call to create # if yes, there is no need to make a call to create
password=$(echo "$1" | sphinx get $(option_value --sphx-user) $(option_value --sphx-host) 2>$errorfile) password=$(echo "$1" | sphinx get $(option_value --sphx-user) $(option_value --sphx-host) 2>$errorfile)
if ! grep -q "ValueError: fail" $errorfile ; then if ! grep -q "ValueError: fail" $errorfile ; then
echo "$password" echo "$password"
rm $errorfile
return 0 return 0
fi fi
# no such host/user combination in store, create one # no such host/user combination in store, create one
password=$(echo "$1" | sphinx create $(option_value --sphx-user) $(option_value --sphx-host) ulsd 0 2>$errorfile) password=$(echo "$1" | sphinx create $(option_value --sphx-user) $(option_value --sphx-host) ulsd 0 2>$errorfile)
if ! grep -q "ValueError: fail" $errorfile ; then if ! grep -q "ValueError: fail" $errorfile ; then
echo "$password" echo "$password"
rm $errorfile
return 0 return 0
else else
_warning "sphinx returns error: ::1 error::" $(cat $errorfile) _warning "sphinx returns error: ::1 error::" $(cat $errorfile)
rm $errorfile
_failure "Failed to create password with sphinx" _failure "Failed to create password with sphinx"
fi fi
} || { } || {