Merge branch 'fix/explorer/memory/gt-2g' into 'master'

explorer/memory: fix conversion of large numbers (>= 2GiB)

See merge request ungleich-public/cdist!1015
This commit is contained in:
poljakowski 2021-08-05 10:23:20 +02:00
commit 49a9bcdf93

View file

@ -27,19 +27,18 @@
str2bytes() { str2bytes() {
awk -F' ' ' awk -F' ' '
$2 == "B" || !$2 { print $1 } $2 == "B" || !$2 { print $1 }
$2 == "kB" { print $1 * 1000 } $2 == "kB" { printf "%.f\n", ($1 * 1000) }
$2 == "MB" { print $1 * 1000 * 1000 } $2 == "MB" { printf "%.f\n", ($1 * 1000 * 1000) }
$2 == "GB" { print $1 * 1000 * 1000 * 1000 } $2 == "GB" { printf "%.f\n", ($1 * 1000 * 1000 * 1000) }
$2 == "TB" { print $1 * 1000 * 1000 * 1000 * 1000 } $2 == "TB" { printf "%.f\n", ($1 * 1000 * 1000 * 1000 * 1000) }
$2 == "kiB" { print $1 * 1024 } $2 == "kiB" { printf "%.f\n", ($1 * 1024) }
$2 == "MiB" { print $1 * 1024 * 1024 } $2 == "MiB" { printf "%.f\n", ($1 * 1024 * 1024) }
$2 == "GiB" { print $1 * 1024 * 1024 * 1024 } $2 == "GiB" { printf "%.f\n", ($1 * 1024 * 1024 * 1024) }
$2 == "TiB" { print $1 * 1024 * 1024 * 1024 * 1024 }' $2 == "TiB" { printf "%.f\n", ($1 * 1024 * 1024 * 1024 * 1024) }'
} }
bytes2kib() { bytes2kib() {
set -- "$(cat)" awk '$0 > 0 { printf "%.f\n", ($0 / 1024) }'
test "$1" -gt 0 && echo $(($1 / 1024))
} }