mirror of
https://github.com/vdsm/virtual-dsm.git
synced 2026-01-02 11:40:59 +08:00
feat: Show directory size (#1083)
This commit is contained in:
@@ -1,6 +1,8 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
set -Eeuo pipefail
|
set -Eeuo pipefail
|
||||||
|
|
||||||
|
info="/run/shm/msg.html"
|
||||||
|
|
||||||
escape () {
|
escape () {
|
||||||
local s
|
local s
|
||||||
s=${1//&/\&}
|
s=${1//&/\&}
|
||||||
@@ -14,16 +16,20 @@ escape () {
|
|||||||
file="$1"
|
file="$1"
|
||||||
total="$2"
|
total="$2"
|
||||||
body=$(escape "$3")
|
body=$(escape "$3")
|
||||||
info="/run/shm/msg.html"
|
|
||||||
|
|
||||||
if [[ "$body" == *"..." ]]; then
|
if [[ "$body" == *"..." ]]; then
|
||||||
body="<p class=\"loading\">${body/.../}</p>"
|
body="<p class=\"loading\">${body::-3}</p>"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
while true
|
while true
|
||||||
do
|
do
|
||||||
if [ -s "$file" ]; then
|
|
||||||
|
if [ ! -s "$file" ] && [ ! -d "$file" ]; then
|
||||||
|
bytes="0"
|
||||||
|
else
|
||||||
bytes=$(du -sb "$file" | cut -f1)
|
bytes=$(du -sb "$file" | cut -f1)
|
||||||
|
fi
|
||||||
|
|
||||||
if (( bytes > 1000 )); then
|
if (( bytes > 1000 )); then
|
||||||
if [ -z "$total" ] || [[ "$total" == "0" ]] || [ "$bytes" -gt "$total" ]; then
|
if [ -z "$total" ] || [[ "$total" == "0" ]] || [ "$bytes" -gt "$total" ]; then
|
||||||
size=$(numfmt --to=iec --suffix=B "$bytes" | sed -r 's/([A-Z])/ \1/')
|
size=$(numfmt --to=iec --suffix=B "$bytes" | sed -r 's/([A-Z])/ \1/')
|
||||||
@@ -33,6 +39,7 @@ do
|
|||||||
fi
|
fi
|
||||||
echo "${body//(\[P\])/($size)}"> "$info"
|
echo "${body//(\[P\])/($size)}"> "$info"
|
||||||
fi
|
fi
|
||||||
fi
|
|
||||||
sleep 1 & wait $!
|
sleep 1 & wait $!
|
||||||
|
|
||||||
done
|
done
|
||||||
|
|||||||
Reference in New Issue
Block a user