[pacman-dev] [PATCH] makepkg: improve removal of installed dependencies
Allan McRae
allan at archlinux.org
Fri Oct 23 01:43:21 EDT 2009
Compare a list of packages on the system before and after dependency resolution
in order to get a complete list of packages to remove. This allows makepkg to
remove packages installed due to provides.
Bail in cases where packages that were on the system originally have been
removed as there is a risk of breaking the system when removing the new
packages
Fixes FS#15144
Signed-off-by: Allan McRae <allan at archlinux.org>
---
scripts/makepkg.sh.in | 39 +++++++++++++++++++++------------------
1 files changed, 21 insertions(+), 18 deletions(-)
diff --git a/scripts/makepkg.sh.in b/scripts/makepkg.sh.in
index 9862304..d47d57b 100644
--- a/scripts/makepkg.sh.in
+++ b/scripts/makepkg.sh.in
@@ -27,8 +27,8 @@
# makepkg uses quite a few external programs during its execution. You
# need to have at least the following installed for makepkg to function:
-# bsdtar (libarchive), bzip2, coreutils, fakeroot, find (findutils),
-# getopt (util-linux), gettext, grep, gzip, openssl, sed
+# bsdtar (libarchive), bzip2, coreutils, diff (diffutils), fakeroot,
+# find (findutils), getopt (util-linux), gettext, grep, gzip, openssl, sed
# gettext initialization
export TEXTDOMAIN='pacman'
@@ -402,7 +402,6 @@ handle_deps() {
}
resolve_deps() {
- # $pkgdeps is a GLOBAL variable, used by remove_deps()
local R_DEPS_SATISFIED=0
local R_DEPS_MISSING=1
@@ -412,7 +411,6 @@ resolve_deps() {
fi
if handle_deps $deplist; then
- pkgdeps="$pkgdeps $deplist"
# check deps again to make sure they were resolved
deplist="$(check_deps $*)"
[ -z "$deplist" ] && return $R_DEPS_SATISFIED
@@ -429,28 +427,34 @@ resolve_deps() {
return $R_DEPS_MISSING
}
-# fix flyspray bug #5923
remove_deps() {
- # $pkgdeps is a GLOBAL variable, set by resolve_deps()
[ "$RMDEPS" -eq 0 ] && return
- [ -z "$pkgdeps" ] && return
- local dep depstrip deplist
- deplist=""
- for dep in $pkgdeps; do
- depstrip="${dep%%[<=>]*}"
- deplist="$deplist $depstrip"
- done
+ current_pkglist=($(pacman -Qq))
+
+ # check for packages removed during dependency install (e.g. due to conflicts)
+ # removing all installed packages is risky in this case
+ if [ $(diff <(printf "%s\n" "${original_pkglist[@]}") \
+ <(printf "%s\n" "${current_pkglist[@]}") | \
+ grep "<" | wc -l) -gt 0 ]; then
+ warning "$(gettext "Failed to remove installed dependencies.")"
+ return 0
+ fi
+
+ local deplist=($(diff <(printf "%s\n" "${original_pkglist[@]}") \
+ <(printf "%s\n" "${current_pkglist[@]}") | grep ">"))
+ deplist=(${deplist[@]#>})
+ [ ${#deplist[@]} -eq 0 ] && return
msg "Removing installed dependencies..."
local ret=0
if [ "$ASROOT" -eq 0 ]; then
- sudo pacman $PACMAN_OPTS -Rns $deplist || ret=$?
+ sudo pacman $PACMAN_OPTS -Rn ${deplist[@]} || ret=$?
else
- pacman $PACMAN_OPTS -Rns $deplist || ret=$?
+ pacman $PACMAN_OPTS -Rn ${deplist[@]} || ret=$?
fi
- # Fixes FS#10039 - exit cleanly as package has built successfully
+ # exit cleanly as package has built successfully
if [ $ret -ne 0 ]; then
warning "$(gettext "Failed to remove installed dependencies.")"
return 0
@@ -1856,14 +1860,13 @@ if [ "$SOURCEONLY" -ne 0 ]; then
exit 0
fi
-# fix flyspray bug #5973
if [ "$NODEPS" -eq 1 -o "$NOBUILD" -eq 1 -o "$REPKG" -eq 1 ]; then
# no warning message needed for nobuild, repkg
if [ "$NODEPS" -eq 1 ]; then
warning "$(gettext "Skipping dependency checks.")"
fi
elif [ $(type -p pacman) ]; then
- unset pkgdeps # Set by resolve_deps() and used by remove_deps()
+ original_pkglist=($(pacman -Qq)) # required by remove_deps
deperr=0
msg "$(gettext "Checking Runtime Dependencies...")"
--
1.6.5.1
More information about the pacman-dev
mailing list