feat(script): Limit length of package name list (#1)
This commit is contained in:
parent
7747e9bdc3
commit
e7c913c4db
@ -166,6 +166,31 @@ function find_max_dataset_name_length () {
|
||||
fi
|
||||
}
|
||||
|
||||
function trim_pkg_list_oneline () {
|
||||
local available_pkg_list_length
|
||||
available_pkg_list_length="$((${max_zfs_snapshot_name_length} - ${max_dataset_name_length}))"
|
||||
if [[ "${available_pkg_list_length}" -lt "{pkgs_list_max_length}" ]]; then
|
||||
# If we have fewer characters available than the user wants limit
|
||||
# package list length
|
||||
pkgs_list_max_length="${available_pkg_list_length}"
|
||||
fi
|
||||
|
||||
local shorter_pkg_list
|
||||
shorter_pkg_list="${pkg_list_oneline}"
|
||||
while [[ "${#shorter_pkg_list}" -gt "${pkgs_list_max_length}" ]]; do
|
||||
shorter_pkg_list="${shorter_pkg_list%,*}"
|
||||
if ! grep -Piq ',' <<<"${shorter_pkg_list}"; then
|
||||
# Only one package remains in package list, no need to continue
|
||||
break
|
||||
fi
|
||||
done
|
||||
if [[ "${#shorter_pkg_list}" -gt "${pkgs_list_max_length}" ]]; do
|
||||
# If this is still too long we empty the package list
|
||||
shorter_pkg_list=''
|
||||
done
|
||||
trimmed_pkg_list_oneline="${shorter_pkg_list}"
|
||||
}
|
||||
|
||||
function main () {
|
||||
local pkgs_in_transaction
|
||||
pkgs_in_transaction=("${@}")
|
||||
@ -191,12 +216,12 @@ function main () {
|
||||
local pkg_list_oneline
|
||||
write_pkg_list_oneline
|
||||
|
||||
local max_dataset_name_length
|
||||
local max_zfs_snapshot_name_length max_dataset_name_length
|
||||
max_zfs_snapshot_name_length='255'
|
||||
find_max_dataset_name_length
|
||||
|
||||
#for pkg in "${!important_pkgs_in_transaction[@]}"; do
|
||||
# printf -- 'Array item '"'"'%s'"'"' equals '"'"'%s'"'"'\n' "${pkg}" "${important_pkgs_in_transaction[${pkg}]}"
|
||||
#done
|
||||
local trimmed_pkg_list_oneline
|
||||
trim_pkg_list_oneline
|
||||
}
|
||||
|
||||
main "${pkgs[@]}"
|
||||
|
Loading…
x
Reference in New Issue
Block a user