index : builder | |
Archlinux32 build system | gitolite user |
summaryrefslogtreecommitdiff |
-rwxr-xr-x | lib/common-functions | 138 |
diff --git a/lib/common-functions b/lib/common-functions index 15d14d0..77f2417 100755 --- a/lib/common-functions +++ b/lib/common-functions @@ -112,11 +112,9 @@ ls_master_mirror() { } -# TODO: enable operation on multiple packages simultanously +# remove_old_package_versions $binary_package_in_repository_id_1 $binary_package_in_repository_id_2 ... -# remove_old_package_versions $binary_package_in_repository_id - -# removes all older versions of the given package from all repositories +# removes all older versions of the given packages from all repositories # less[1] stable than the current repository, as well as any different # version of the same package from equally[2] stable repositories @@ -129,71 +127,77 @@ remove_old_package_versions() { tmp_dir=$(mktemp -d 'tmp.common-functions.remove_old_package_versions.XXXXXXXXXX' --tmpdir) trap 'rm -rf --one-file-system "${tmp_dir}"' EXIT - bpir_id="$1" + for bpir_id in "$@"; do - # shellcheck disable=SC2016 - { - printf 'SELECT ' - printf '`d_bpir`.`id`,' - printf 'IF(`d_r`.`stability`=`o_r`.`stability` AND `d_bpir`.`id`!=`o_bpir`.`id`,1,0),' - printf 'CONCAT(' - printf 'IF(`d_bp`.`epoch`=0,"",CONCAT(`d_bp`.`epoch`,":")),' - printf '`d_bp`.`pkgver`,"-",' - printf '`d_bp`.`pkgrel`,' - printf 'IF(`d_bp`.`sub_pkgrel_omitted`,"",CONCAT(".",`d_bp`.`sub_pkgrel`))' - printf '),' - printf 'IF(`d_r`.`id`=`o_r`.`id`,1,0),' - printf '`d_ra`.`name`,' - printf '`d_r`.`name`,' - printf '`d_bp`.`pkgname`,' - printf 'CONCAT(`d_ra`.`name`,"/",' - printf '`d_r`.`name`,"/",' - mysql_package_name_query 'd_bp' 'd_bpa' - printf ')' - printf ' FROM `binary_packages_in_repositories` AS `d_bpir`' - mysql_join_binary_packages_in_repositories_binary_packages 'd_bpir' 'd_bp' - mysql_join_binary_packages_in_repositories_repositories 'd_bpir' 'd_r' - printf ' AND `d_r`.`is_on_master_mirror`' - mysql_join_repositories_architectures 'd_r' 'd_ra' - mysql_join_binary_packages_architectures 'd_bp' 'd_bpa' - printf ' JOIN `binary_packages` AS `o_bp` ON `d_bp`.`pkgname`=`o_bp`.`pkgname`' - mysql_join_binary_packages_binary_packages_in_repositories 'o_bp' 'o_bpir' - mysql_join_binary_packages_in_repositories_repositories 'o_bpir' 'o_r' - printf ' AND `o_r`.`is_on_master_mirror`' - printf ' AND `o_r`.`architecture`=`d_r`.`architecture`' - printf ' JOIN `repository_stability_relations`' - printf ' ON `repository_stability_relations`.`less_stable`=`d_r`.`stability`' - printf ' AND `repository_stability_relations`.`more_stable`=`o_r`.`stability`' - printf ' WHERE `o_bpir`.`id`=from_base64("%s")' \ - "$( - printf '%s' "${bpir_id}" | \ - base64 -w0 - )" - printf ';\n' - } | \ - mysql_run_query | \ - tr '\t' ' ' | \ - expand_version 3 | \ - sort -k3V,3 -k2r,2 | \ - shrink_version 3 | \ - sed -n ' - /^'"${bpir_id}"' /q - s/^\([0-9]\+ \)\(\S\+ \)\{2\}/\1/ - h - /^[0-9]\+ 0 / { - s/^\(\S\+ \)\{2\}// - s/ \S\+$// - w'"${tmp_dir}"'/repo-removes + # shellcheck disable=SC2016 + { + printf 'SELECT ' + printf '`d_bpir`.`id`,' + printf 'IF(`d_r`.`stability`=`o_r`.`stability` AND `d_bpir`.`id`!=`o_bpir`.`id`,1,0),' + printf 'CONCAT(' + printf 'IF(`d_bp`.`epoch`=0,"",CONCAT(`d_bp`.`epoch`,":")),' + printf '`d_bp`.`pkgver`,"-",' + printf '`d_bp`.`pkgrel`,' + printf 'IF(`d_bp`.`sub_pkgrel_omitted`,"",CONCAT(".",`d_bp`.`sub_pkgrel`))' + printf '),' + printf 'IF(`d_r`.`id`=`o_r`.`id`,1,0),' + printf '`d_ra`.`name`,' + printf '`d_r`.`name`,' + printf '`d_bp`.`pkgname`,' + printf 'CONCAT(`d_ra`.`name`,"/",' + printf '`d_r`.`name`,"/",' + mysql_package_name_query 'd_bp' 'd_bpa' + printf ')' + printf ' FROM `binary_packages_in_repositories` AS `d_bpir`' + mysql_join_binary_packages_in_repositories_binary_packages 'd_bpir' 'd_bp' + mysql_join_binary_packages_in_repositories_repositories 'd_bpir' 'd_r' + printf ' AND `d_r`.`is_on_master_mirror`' + mysql_join_repositories_architectures 'd_r' 'd_ra' + mysql_join_binary_packages_architectures 'd_bp' 'd_bpa' + printf ' JOIN `binary_packages` AS `o_bp` ON `d_bp`.`pkgname`=`o_bp`.`pkgname`' + mysql_join_binary_packages_binary_packages_in_repositories 'o_bp' 'o_bpir' + mysql_join_binary_packages_in_repositories_repositories 'o_bpir' 'o_r' + printf ' AND `o_r`.`is_on_master_mirror`' + printf ' AND `o_r`.`architecture`=`d_r`.`architecture`' + printf ' JOIN `repository_stability_relations`' + printf ' ON `repository_stability_relations`.`less_stable`=`d_r`.`stability`' + printf ' AND `repository_stability_relations`.`more_stable`=`o_r`.`stability`' + printf ' WHERE `o_bpir`.`id`=from_base64("%s")' \ + "$( + printf '%s' "${bpir_id}" | \ + base64 -w0 + )" + printf ';\n' + } | \ + mysql_run_query | \ + tr '\t' ' ' | \ + expand_version 3 | \ + sort -k3V,3 -k2r,2 | \ + shrink_version 3 | \ + sed -n ' + /^'"${bpir_id}"' /q + s/^\([0-9]\+ \)\(\S\+ \)\{2\}/\1/ + h + /^[0-9]\+ 0 / { + s/^\(\S\+ \)\{2\}// + s/ \S\+$// + w'"${tmp_dir}"'/repo-removes + g + } + s/^\(\S\+ \)\{5\}// + w'"${tmp_dir}"'/sftp-removes + s/$/.sig/ + w'"${tmp_dir}"'/sftp-removes g - } - s/^\(\S\+ \)\{5\}// - w'"${tmp_dir}"'/sftp-removes - s/$/.sig/ - w'"${tmp_dir}"'/sftp-removes - g - s/ .*$// - w'"${tmp_dir}"'/db-removes - ' + s/ .*$// + w'"${tmp_dir}"'/db-removes + ' + done + + for file in 'repo-removes' 'sftp-remove' 'db-removes'; do + sort -u "${tmp_dir}/${file}" | \ + sponge "${tmp_dir}/${file}" + done # repo-remove packages while read -r arch repo pkgname; do |