Eliminate use of ambiguous logical operators in script conditionals

Prefer '[] && []' to '[ -a ]' and '[] || []' to '[ -o ]' in tests.
-a and -o to mean AND and OR in a [ .. ] test expression is not well
defined, and can cause incorrect results when arguments start with
dashes or contain !. Moreover binary -a and -o are inherently
ambiguous. test(1) man page recommends to use
'test EXPR1 && test EXPR2' or 'test EXPR1 || test EXPR2' instead.

It corrects warnings [SC2166] spotted by covscan.
This commit is contained in:
Pavlina Moravcova Varekova 2019-08-09 16:30:43 +02:00 committed by Gordon Messmer
commit 4ddd2ea298

View file

@ -14,7 +14,7 @@ fi
compileall_flags="$4"
# If using normal root, avoid changing anything.
if [ -z "$RPM_BUILD_ROOT" -o "$RPM_BUILD_ROOT" = "/" ]; then
if [ -z "$RPM_BUILD_ROOT" ] || [ "$RPM_BUILD_ROOT" = "/" ]; then
exit 0
fi
@ -137,12 +137,12 @@ do
# Generate normal (.pyc) byte-compiled files.
python_clamp_source_mtime "" "$python_binary" "" "$python_libdir" ""
if [ $? -ne 0 -a 0$errors_terminate -ne 0 ]; then
if [ $? -ne 0 ] && [ 0$errors_terminate -ne 0 ]; then
# One or more of the files had inaccessible mtime
exit 1
fi
python_bytecompile "" "$python_binary" "" "$python_libdir" "$compileall_flags"
if [ $? -ne 0 -a 0$errors_terminate -ne 0 ]; then
if [ $? -ne 0 ] && [ 0$errors_terminate -ne 0 ]; then
# One or more of the files had a syntax error
exit 1
fi
@ -150,7 +150,7 @@ do
# Generate optimized (.pyo) byte-compiled files.
# N.B. For Python 3.4+, this call does nothing
python_bytecompile "-O" "$python_binary" "" "$python_libdir" "$compileall_flags"
if [ $? -ne 0 -a 0$errors_terminate -ne 0 ]; then
if [ $? -ne 0 ] && [ 0$errors_terminate -ne 0 ]; then
# One or more of the files had a syntax error
exit 1
fi