Don't use volumes when filesize is smaller than volume size

This commit is contained in:
PedoDeveloper 2024-11-11 12:52:32 +00:00
parent b6f5334011
commit 755cd36fb6

View file

@ -47,7 +47,10 @@ check_input() {
# Calculates a "smart" volume size so that each volume (including the final part) will be approximately the same size
calc_smart_volumes() {
total_size=$(du -s -BM "${input_file}" | grep -oP '^\d+') || return
total_size=$(du -s -BM "${input_file}" | grep -oP '^\d+') || return 0
[[ $total_size -lt $size ]] && return 1
num_volumes=$(echo "($total_size + $size - 1) / $size" | bc)
size=$(echo "($total_size + $num_volumes - 1) / $num_volumes" | bc)
@ -55,10 +58,9 @@ calc_smart_volumes() {
}
set_volumes() {
[[ -z "$size" ]] && return
calc_smart_volumes
volumes="-v${size}m"
if [[ -n "$size" ]]; then
calc_smart_volumes && volumes="-v${size}m"
fi
echo "Volumes set to '$volumes'" >&2
}