paccache: adopt size_to_human

Signed-off-by: Dave Reisner <dreisner@archlinux.org>
This commit is contained in:
Dave Reisner 2012-05-06 19:47:47 -04:00 committed by Dan McGee
parent a98fce0896
commit b1bb2eaa50
3 changed files with 4 additions and 21 deletions

View File

@ -93,7 +93,7 @@ uninstall-local:
bacman: $(srcdir)/bacman.sh.in
bash_completion: $(srcdir)/bash_completion.in
paccache: $(srcdir)/paccache.sh.in $(top_srcdir)/scripts/library/parseopts.sh
paccache: $(srcdir)/paccache.sh.in $(top_srcdir)/scripts/library/parseopts.sh $(top_srcdir)/scripts/library/size_to_human.sh
pacdiff: $(srcdir)/pacdiff.sh.in
paclist: $(srcdir)/paclist.sh.in
paclog-pkglist: $(srcdir)/paclog-pkglist.sh.in

View File

@ -108,26 +108,7 @@ pkgfilter() {
}' "${@:3}"
}
size_to_human() {
awk -v size="$1" '
BEGIN {
suffix[1] = "B"
suffix[2] = "KiB"
suffix[3] = "MiB"
suffix[4] = "GiB"
suffix[5] = "TiB"
count = 1
while (size > 1024) {
size /= 1024
count++
}
sizestr = sprintf("%.2f", size)
sub(/\.?0+$/, "", sizestr)
printf("%s %s", sizestr, suffix[count])
}'
}
m4_include(../scripts/library/size_to_human.sh)
runcmd() {
if (( needsroot && EUID != 0 )); then

View File

@ -6,6 +6,8 @@ size_to_human() {
suffix[3] = "MiB"
suffix[4] = "GiB"
suffix[5] = "TiB"
suffix[6] = "PiB"
suffix[7] = "EiB"
count = 1
while (size > 1024) {