]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw: rgw-orphan-list -- fix interaction, quoting, and percentage calc
authorJ. Eric Ivancich <ivancich@redhat.com>
Tue, 7 Jul 2020 17:16:02 +0000 (13:16 -0400)
committerJ. Eric Ivancich <ivancich@redhat.com>
Wed, 15 Jul 2020 16:24:16 +0000 (12:24 -0400)
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 <ivancich@redhat.com>
(cherry picked from commit 6d9d548096d2b5b27a2868562112d90486ab2c78)

src/rgw/rgw-orphan-list

index 9219486a71bf0faf1f32b0ff118b5d8c1e0c7ba5..bdb0a43ac118117f2482c0b42b77039a0b252de2 100755 (executable)
@@ -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}."