summaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
authorekardnam <lucabertozzi.pub@gmail.com>2019-05-21 11:17:59 +0200
committerAllan McRae <allan@archlinux.org>2019-05-28 03:08:21 +0200
commitc8062d753c77a8de4a89fbd4a83e5c8602a883aa (patch)
treeb298e94c59b711900b231d98a0d0af46ecd79bcf /scripts
parent99c5809bbf01725829ce67458565b46bce32eaa9 (diff)
downloadpacman-c8062d753c77a8de4a89fbd4a83e5c8602a883aa.tar.gz
pacman-c8062d753c77a8de4a89fbd4a83e5c8602a883aa.tar.xz
repo-add: Add --prevent-downgrade option
Implements FS#17752 Signed-off-by: Luca Bertozzi <ekarndam@autistici.org>
Diffstat (limited to 'scripts')
-rw-r--r--scripts/repo-add.sh.in19
1 files changed, 16 insertions, 3 deletions
diff --git a/scripts/repo-add.sh.in b/scripts/repo-add.sh.in
index e23f47c9..6a889803 100644
--- a/scripts/repo-add.sh.in
+++ b/scripts/repo-add.sh.in
@@ -42,6 +42,7 @@ REPO_DB_SUFFIX=
LOCKFILE=
CLEAN_LOCK=0
USE_COLOR='y'
+PREVENT_DOWNGRADE=0
# Import libmakepkg
source "$LIBRARY"/util/message.sh
@@ -63,6 +64,7 @@ Multiple packages to add can be specified on the command line.\n")"
printf -- "$(gettext "Options:\n")"
printf -- "$(gettext " -n, --new only add packages that are not already in the database\n")"
printf -- "$(gettext " -R, --remove remove old package file from disk after updating database\n")"
+ printf -- "$(gettext " -p, --prevent-downgrade do not add package to database if a newer version is already present\n")"
elif [[ $cmd == "repo-remove" ]] ; then
printf -- "$(gettext "Usage: repo-remove [options] <path-to-db> <packagename> ...\n")"
printf -- "\n"
@@ -248,9 +250,17 @@ db_write_entry() {
return 0
fi
else
- if (( RMEXISTING )); then
- pkgentry=$(find_pkgentry "$pkgname")
- if [[ -n $pkgentry ]]; then
+ pkgentry=$(find_pkgentry "$pkgname")
+ if [[ -n $pkgentry ]]; then
+
+ local version=$(sed -n '/^%VERSION%$/ {n;p;q}' "$pkgentry/desc")
+ if (( $(vercmp "$version" "$pkgver") > 0 )); then
+ warning "$(gettext "A newer version for '%s' is already present in database")" "$pkgname"
+ if (( PREVENT_DOWNGRADE )); then
+ return 0
+ fi
+ fi
+ if (( RMEXISTING )); then
local oldfilename="$(sed -n '/^%FILENAME%$/ {n;p;q;}' "$pkgentry/desc")"
local oldfile="$(dirname "$1")/$oldfilename"
fi
@@ -618,6 +628,9 @@ while (( $# )); do
-v|--verify)
VERIFY=1
;;
+ -p|--prevent-downgrade)
+ PREVENT_DOWNGRADE=1
+ ;;
*)
args+=("$1")
;;