summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorErich Eckner <git@eckner.net>2018-06-11 16:24:05 +0200
committerErich Eckner <git@eckner.net>2018-06-11 16:24:05 +0200
commitfd3098241034ab4588cc045d971386bfd7d1264e (patch)
tree634e1726ddf4195a4d470085a968ae7fae9087df
parentdf5c6e2c3ca1f8c99087ba23aaa8425f102ddba9 (diff)
downloadbuilder-fd3098241034ab4588cc045d971386bfd7d1264e.tar.xz
lib/common-functions: remove_old_package_versions() can operate on multiple packages simultanously, now
-rwxr-xr-xlib/common-functions138
1 files changed, 71 insertions, 67 deletions
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