Skip to content

Commit

Permalink
BAI-1570 make json return a number rather than a string when just ret…
Browse files Browse the repository at this point in the history
…urning the unformatted byte count
  • Loading branch information
PE39806 committed Jan 8, 2025
1 parent 6bd9e1d commit cb60d15
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions backend/src/scripts/getTotalStorageUsed.sh
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ Options:
-b, --bytes Display the storage usage in bytes. If unset, values are formatted for human readability.
-o, --output <filename> Write the results to the specified file. If unset, results are printed to the terminal.
-r, --reporting-format <format>
Set the output format to one of ((c|console)|(j|json)). Defaults to console.
Set the output format to one of ((c|console)|(j|json)). Defaults to console. When set as json, if <-b|--bytes> is passed then the values are numbers otherwise the values are strings.
HEREDOC
}

Expand Down Expand Up @@ -137,7 +137,11 @@ _get_storage() {
# Format the result string
if [ $_NORMALISED_REPORTING_FORMAT -eq 1 ]; then
# Use jq to safely (escape key characters etc) create a JSON string
result_string=$(jq -n --arg eb "${existing_bytes}" --arg db "${deleted_bytes}" --arg tb "${total_bytes}" '{existing: $eb, deleted: $db, total: $tb}')
if ((_FORMAT_BYTES)); then
result_string=$(jq -n --arg eb "${existing_bytes}" --arg db "${deleted_bytes}" --arg tb "${total_bytes}" '{existing: $eb, deleted: $db, total: $tb}')
else
result_string=$(jq -n --arg eb "${existing_bytes}" --arg db "${deleted_bytes}" --arg tb "${total_bytes}" '{existing: ($eb)|tonumber, deleted: ($db)|tonumber, total: ($tb)|tonumber}')
fi
elif [ $_NORMALISED_REPORTING_FORMAT -eq 0 ]; then
result_string="existing: ${existing_bytes}\\ndeleted: ${deleted_bytes}\\ntotal: ${total_bytes}"
else
Expand Down

0 comments on commit cb60d15

Please sign in to comment.