From: Paul Hänsch Date: Mon, 21 Mar 2022 14:02:08 +0000 (+0100) Subject: use file size function from tools.sh X-Git-Url: https://git.plutz.net/?a=commitdiff_plain;h=f4203dafaaeb85c9db2bc374af04531f4334ca91;p=shellwiki use file size function from tools.sh --- diff --git a/macros/attachments b/macros/attachments index 7acc806..428e770 100755 --- a/macros/attachments +++ b/macros/attachments @@ -1,6 +1,7 @@ #!/bin/sh . "$_EXEC/cgilite/cgilite.sh" +. "$_EXEC/tools.sh" page="$1" @@ -16,25 +17,9 @@ for file in "$_EXEC/pages/$page/#attachments"/* "$_DATA/pages/$page/#attachments stat="$(stat -c '%s %Y' -- "$file" 2>&-)" || continue size="${stat% *}" date="${stat#* }" - if [ $size -gt $((1024 * 1024 * 1024)) ]; then - size=$((size / 1024 / 1024 / 1024 * 10 + size / 1024 / 1024 % 1024 / 100)) - size="$((size / 10)).$((size % 10)) GB" - - elif [ $size -gt $((1024 * 1024)) ]; then - size=$((size / 1024 / 1024 * 10 + size / 1024 % 1024 / 100)) - size="$((size / 10)).$((size % 10)) MB" - - elif [ $size -gt $((1024)) ]; then - size=$((size / 1024 * 10 + size % 1024 / 100)) - size="$((size / 10)).$((size % 10)) KB" - - else - size="${size} B" - fi - printf '
  • %s %s%s
  • ' \ - "$(HTML "${file##*/}")" "$size" "$(date -d @"$date" +"%F %T")" + "$(HTML "${file##*/}")" "$(size_human "$size")" "$(date -d @"$date" +"%F %T")" done printf %s\\n ''