Prettify and polish up partial-dl-test script
This commit is contained in:
parent
fa554058cc
commit
66512eb358
1 changed files with 23 additions and 7 deletions
|
@ -1,12 +1,28 @@
|
||||||
#!/usr/bin/env zsh
|
#!/usr/bin/env zsh
|
||||||
actualSize=$(wc -c < $1)
|
|
||||||
|
|
||||||
for (( size = 0; size < actualSize; size++ )); do
|
actualSize=$(wc -c < $1)
|
||||||
head -c$size $1 | env -i HOME=$HOME/test zsh 2>/dev/null
|
testDir=$TMPDIR/dots-partial-dl-test-$UID-$$
|
||||||
if [[ -d $HOME/test ]]; then
|
if [[ -d $testDir ]]; then
|
||||||
percent=$(( size * 100 / actualSize ))
|
echo "$testDir exists, is this test already running?" >&2
|
||||||
echo "dots still ran with only $size bytes available, " \
|
echo "Refusing to launch. Remove $testDir manually if necessary." >&2
|
||||||
"$percent% of its full $actualSize bytes!" 2>/dev/null
|
exit -1
|
||||||
|
fi
|
||||||
|
|
||||||
|
repeat-char() {
|
||||||
|
local char=$1
|
||||||
|
local -i count=$2
|
||||||
|
(( count )) && printf "$char%.0s" {1..$count}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (( size = 0; size < actualSize - 1; size++ )); do
|
||||||
|
percent=$(( size * 100 / actualSize ))
|
||||||
|
progress=$(( percent / 10 ))
|
||||||
|
printf " [%-10s] [%${#actualSize}d/%d]\r" "$(repeat-char = $progress)" $size $actualSize >&2
|
||||||
|
|
||||||
|
head -c$size $1 | env -i HOME=$testDir zsh 2>/dev/null
|
||||||
|
if [[ -d $testDir ]]; then
|
||||||
|
rm -rf $testDir
|
||||||
|
printf "\ndots still ran with only %d bytes available, %d%% of its full %d bytes!\n" $size $percent $actualSize >&2
|
||||||
exit $size
|
exit $size
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
Loading…
Reference in a new issue