Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
path: root/bin/delete-packages
diff options
context:
space:
mode:
authorErich Eckner <git@eckner.net>2018-06-07 09:12:22 +0200
committerErich Eckner <git@eckner.net>2018-06-07 09:12:22 +0200
commit9333613ac6521af7859caaff42f0eb61c1f88f0f (patch)
treee5b5b30007a974fe9293933862e6beb9623eb943 /bin/delete-packages
parent06e26b5b0ca1128730a847a4b06a4489dce10ca6 (diff)
bin/delete-packages: operate on `binary_packages_in_repositories` instead of `binary_packages`
Diffstat (limited to 'bin/delete-packages')
-rwxr-xr-xbin/delete-packages138
1 files changed, 92 insertions, 46 deletions
diff --git a/bin/delete-packages b/bin/delete-packages
index a0e6596..554f9e4 100755
--- a/bin/delete-packages
+++ b/bin/delete-packages
@@ -108,21 +108,24 @@ trap 'rm -rf --one-file-system "${tmp_dir}"' EXIT
export TMPDIR="${tmp_dir}"
-# TODO: operate on `binary_packages_in_repositories` instead of `binary_packages`
-
# shellcheck disable=SC2016
{
- printf 'CREATE TEMPORARY TABLE `to_deletes` (`id` BIGINT, UNIQUE KEY (`id`));\n'
- printf 'INSERT IGNORE INTO `to_deletes`'
+ printf 'CREATE TEMPORARY TABLE `bpir_to_delete` (`id` BIGINT, UNIQUE KEY (`id`));\n'
+ printf 'INSERT IGNORE INTO `bpir_to_delete`'
if [ -n "${force_ids}" ]; then
printf ' VALUES '
# shellcheck disable=SC2086
- printf '(%s),' ${force_ids} | \
- sed 's/,$/;\n/'
+ printf '%s\n' ${force_ids} | \
+ base64_encode_each | \
+ sed '
+ s/^/(from_base64("/
+ s/$/")),/
+ $ s/,$/;/
+ '
else
- printf ' SELECT DISTINCT `binary_packages`.`id`'
- printf ' FROM `binary_packages`'
- mysql_join_binary_packages_binary_packages_in_repositories
+ printf ' SELECT DISTINCT `binary_packages_in_repositories`.`id`'
+ printf ' FROM `binary_packages_in_repositories`'
+ mysql_join_binary_packages_in_repositories_binary_packages
mysql_join_binary_packages_in_repositories_repositories
printf ' LEFT' # should not be necessary, but is formally more correct
mysql_join_binary_packages_install_target_providers
@@ -138,10 +141,13 @@ export TMPDIR="${tmp_dir}"
# deliberately break dependencies of deletion-list packages
printf ' AND NOT `d_bpir`.`is_to_be_deleted`'
mysql_join_binary_packages_in_repositories_repositories 'd_bpir' 'd_r'
- mysql_join_repositories_repository_stabilities 'd_r' 'd_rs'
# this is deliberately less restrict than `d_r`.`is_on_master_mirror`
- printf ' AND `d_rs`.`name` NOT IN ("forbidden","virtual")'
+ # shellcheck disable=SC2154
+ printf ' AND `d_r`.`stability` NOT IN (%s,%s)' \
+ "${repository_stability_ids__forbidden}" \
+ "${repository_stability_ids__virtual}"
printf ' WHERE `install_target_providers`.`install_target`=`dependencies`.`depending_on`'
+ printf ' AND `d_r`.`architecture`=`repositories`.`architecture`'
printf ' AND NOT EXISTS ('
printf 'SELECT 1 FROM `binary_packages` AS `s_bp`'
mysql_join_binary_packages_binary_packages_in_repositories 's_bp' 's_bpir'
@@ -152,37 +158,78 @@ export TMPDIR="${tmp_dir}"
printf ' JOIN `repository_stability_relations`'
printf ' ON `repository_stability_relations`.`more_stable`=`s_r`.`stability`'
printf ' WHERE `s_itp`.`install_target`=`install_target_providers`.`install_target`'
+ printf ' AND `s_r`.`architecture`=`repositories`.`architecture`'
printf ' AND `repository_stability_relations`.`less_stable`=`d_r`.`stability`'
printf ')'
printf ');\n'
fi
- printf 'SELECT DISTINCT "repo",`repositories`.`name`'
- printf ' FROM `to_deletes`'
- printf ' JOIN `binary_packages` ON `to_deletes`.`id`=`binary_packages`.`id`'
+ # first enter all potentially to-be-deleted binary_packages into the table
+ printf 'CREATE TEMPORARY TABLE `bp_to_delete` (`id` BIGINT, UNIQUE KEY (`id`));\n'
+ printf 'INSERT IGNORE INTO `bp_to_delete`'
+ printf ' SELECT `binary_packages_in_repositories`.`package`'
+ printf ' FROM `bpir_to_delete`'
+ printf ' JOIN `binary_packages_in_repositories` ON `bpir_to_delete`.`id`=`binary_packages_in_repositories`.`id`;\n'
+
+ # then remove all bp_to_delete which are actually still needed
+ printf 'DELETE `bp_to_delete` FROM `bp_to_delete`'
+ printf ' JOIN `binary_packages` ON `binary_packages`.`id`=`bp_to_delete`.`id`'
mysql_join_binary_packages_binary_packages_in_repositories
+ printf ' WHERE NOT EXISTS ('
+ printf 'SELECT 1'
+ printf ' FROM `bpir_to_delete`'
+ printf ' WHERE `bpir_to_delete`.`id`=`binary_packages_in_repositories`.`id`'
+ printf ');\n'
+
+ printf 'SELECT DISTINCT'
+ printf ' "repo",'
+ printf '`architectures`.`name`,'
+ printf '`repositories`.`name`'
+ printf ' FROM `bpir_to_delete`'
+ printf ' JOIN `binary_packages_in_repositories` ON `bpir_to_delete`.`id`=`binary_packages_in_repositories`.`id`'
+ mysql_join_binary_packages_in_repositories_binary_packages
mysql_join_binary_packages_in_repositories_repositories
+ mysql_join_repositories_architectures
printf ';\n'
- printf 'SELECT "package",`repositories`.`name`,`binary_packages`.`pkgname`'
- printf ' FROM `to_deletes`'
- printf ' JOIN `binary_packages` ON `to_deletes`.`id`=`binary_packages`.`id`'
- mysql_join_binary_packages_binary_packages_in_repositories
+ printf 'SELECT'
+ printf ' "package",'
+ printf '`architectures`.`name`,'
+ printf '`repositories`.`name`,'
+ printf '`binary_packages`.`pkgname`'
+ printf ' FROM `bpir_to_delete`'
+ printf ' JOIN `binary_packages_in_repositories` ON `bpir_to_delete`.`id`=`binary_packages_in_repositories`.`id`'
+ mysql_join_binary_packages_in_repositories_binary_packages
mysql_join_binary_packages_in_repositories_repositories
+ mysql_join_repositories_architectures
printf ';\n'
- printf 'SELECT "package-file",`repositories`.`name`,'
+ printf 'SELECT "package-file",CONCAT('
+ printf '`r_a`.`name`,"/",'
+ printf '`repositories`.`name`,"/",'
mysql_package_name_query
- printf ' FROM `to_deletes`'
- printf ' JOIN `binary_packages` ON `to_deletes`.`id`=`binary_packages`.`id`'
- mysql_join_binary_packages_binary_packages_in_repositories
+ printf ') FROM `bpir_to_delete`'
+ printf ' JOIN `binary_packages_in_repositories` ON `bpir_to_delete`.`id`=`binary_packages_in_repositories`.`id`'
+ mysql_join_binary_packages_in_repositories_binary_packages
mysql_join_binary_packages_in_repositories_repositories
mysql_join_binary_packages_architectures
+ mysql_join_repositories_architectures '' 'r_a'
+ printf ';\n'
+
+ printf 'SELECT "package-in-repository-id",`bpir_to_delete`.`id`'
+ printf ' FROM `bpir_to_delete`'
printf ';\n'
- printf 'SELECT "package-id",`to_deletes`.`id`'
- printf ' FROM `to_deletes`'
+ printf 'SELECT "package-file",CONCAT('
+ printf '"pool/",'
+ mysql_package_name_query
+ printf ') FROM `bp_to_delete`'
+ printf ' JOIN `binary_packages` ON `bp_to_delete`.`id`=`binary_packages`.`id`'
+ mysql_join_binary_packages_architectures
printf ';\n'
+
+ # we do not need the ids of the to-be-deleted binary_packages, because
+ # they stay in the database and are merely moved to the deletion-list
} | \
mysql_run_query | \
sed '
@@ -199,15 +246,14 @@ export TMPDIR="${tmp_dir}"
}
/^package-file /{
s/^\S\+ //
- s, ,/,
w '"${tmp_dir}"'/package-files
s/$/.sig/
w '"${tmp_dir}"'/package-files
d
}
- /^package-id /{
+ /^package-in-repository-id /{
s/^\S\+ //
- w '"${tmp_dir}"'/package-ids
+ w '"${tmp_dir}"'/package-in-repository-ids
d
}
'
@@ -219,13 +265,14 @@ fi
mkdir "${tmp_dir}/repos"
-while read -r repo; do
+while read -r arch repo; do
+ mkdir -p "${tmp_dir}/repos/${arch}"
${master_mirror_rsync_command} \
- "${master_mirror_rsync_directory}/i686/${repo}/${repo}.db.tar.gz" \
- "${master_mirror_rsync_directory}/i686/${repo}/${repo}.files.tar.gz" \
- "${tmp_dir}/repos/"
+ "${master_mirror_rsync_directory}/${arch}/${repo}/${repo}.db.tar.gz" \
+ "${master_mirror_rsync_directory}/${arch}/${repo}/${repo}.files.tar.gz" \
+ "${tmp_dir}/repos/${arch}"
- tar -Oxzf "${tmp_dir}/repos/${repo}.db.tar.gz" --wildcards '*/desc' | \
+ tar -Oxzf "${tmp_dir}/repos/${arch}/${repo}.db.tar.gz" --wildcards '*/desc' | \
sed -n '
/^%FILENAME%$/{
N
@@ -242,16 +289,16 @@ while read -r repo; do
"${tmp_dir}/sub_pkgrel-removal.sed"
# shellcheck disable=SC2046
- repo-remove "${tmp_dir}/repos/${repo}.db.tar.gz" \
+ repo-remove "${tmp_dir}/repos/${arch}/${repo}.db.tar.gz" \
$(
- grep "^$(str_to_regex "${repo}") " "${tmp_dir}/packages" | \
- cut -d' ' -f2
+ grep "^$(str_to_regex "${arch} ${repo}") " "${tmp_dir}/packages" | \
+ cut -d' ' -f3
)
if ! ${no_action}; then
${master_mirror_rsync_command} \
- "${tmp_dir}/repos/${repo}.db.tar.gz" \
- "${tmp_dir}/repos/${repo}.files.tar.gz" \
- "${master_mirror_rsync_directory}/i686/${repo}/"
+ "${tmp_dir}/repos/${arch}/${repo}.db.tar.gz" \
+ "${tmp_dir}/repos/${arch}/${repo}.files.tar.gz" \
+ "${master_mirror_rsync_directory}/${arch}/${repo}/"
fi
done < \
"${tmp_dir}/repositories"
@@ -270,13 +317,12 @@ fi
# shellcheck disable=SC2016
{
- printf 'CREATE TEMPORARY TABLE `to_deletes` (`id` BIGINT, UNIQUE KEY (`id`));\n'
- printf 'LOAD DATA LOCAL INFILE "%s" INTO TABLE `to_deletes`;\n' \
- "${tmp_dir}/package-ids"
+ printf 'CREATE TEMPORARY TABLE `bpir_to_delete` (`id` BIGINT, UNIQUE KEY (`id`));\n'
+ printf 'LOAD DATA LOCAL INFILE "%s" INTO TABLE `bpir_to_delete`;\n' \
+ "${tmp_dir}/package-in-repository-ids"
- printf 'UPDATE `binary_packages` '
- printf ' JOIN `to_deletes` ON `to_deletes`.`id`=`binary_packages`.`id`'
- mysql_join_binary_packages_binary_packages_in_repositories
+ printf 'UPDATE `binary_packages_in_repositories` '
+ printf ' JOIN `bpir_to_delete` ON `bpir_to_delete`.`id`=`binary_packages_in_repositories`.`id`'
# shellcheck disable=SC2154
printf ' SET `binary_packages_in_repositories`.`repository`=%s;\n' \
"${repository_ids__any_deletion_list}"
@@ -284,7 +330,7 @@ fi
mysql_run_query
sed '
- s,^,rm "i686/,
- s,$,",
+ s/^/rm "/
+ s/$/"/
' "${tmp_dir}/package-files" | \
${master_mirror_sftp_command}