From e9fa1f32ce4157cae77f96f06483508d0c368dfb Mon Sep 17 00:00:00 2001 From: "J. Eric Ivancich" Date: Tue, 7 Jul 2020 13:16:02 -0400 Subject: [PATCH] rgw: rgw-orphan-list -- fix interaction, quoting, and percentage calc The interactive mode wasn't working due to prompts going to stdout instead of stderr. If a space should appear in temporary file, it will generate a shell error, so quoting was added. Furthermore if there are no objects found in a pool, a divide by zero error will be generated. This commit addresses these issues. Signed-off-by: J. Eric Ivancich (cherry picked from commit 6d9d548096d2b5b27a2868562112d90486ab2c78) --- src/rgw/rgw-orphan-list | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/rgw/rgw-orphan-list b/src/rgw/rgw-orphan-list index 9219486a71bf0..bdb0a43ac1181 100755 --- a/src/rgw/rgw-orphan-list +++ b/src/rgw/rgw-orphan-list @@ -28,13 +28,14 @@ error_out() { } prompt_pool() { - echo "Available pools:" + # note: all prompts go to stderr so stdout contains just the result + >&2 echo "Available pools:" rados lspools >"$temp_file" 2>"$lspools_err" if [ "$?" -ne 0 ] ;then error_out "rados lspools" "$lspools_err" fi - sed 's/^/ /' $temp_file # list pools and indent - printf "Which pool do you want to search for orphans? " + >&2 sed 's/^/ /' "$temp_file" # list pools and indent + >&2 printf "Which pool do you want to search for orphans? " local mypool read mypool echo $mypool @@ -76,9 +77,12 @@ if [ "${PIPESTATUS[0]}" -gt 1 ] ;then error_out "ceph-diff-sorted" fi -found="$(wc -l < $delta_out)" -possible="$(wc -l < $rados_out)" -percentage=$(expr 100 \* $found / $possible) +found=$(wc -l < "$delta_out") +possible=$(wc -l < "$rados_out") +percentage=0 +if [ $possible -ne 0 ] ;then + percentage=$(expr 100 \* $found / $possible) +fi echo "$found potential orphans found out of a possible $possible (${percentage}%)." echo "The results can be found in ${delta_out}." -- 2.39.5