[pacman-dev] [PATCH 1/6] repo-add: improve removing old packages

Allan McRae allan at archlinux.org
Fri Jan 23 07:36:19 UTC 2015


The -R/--remove option left the old package in place when delta packages
were to be generated.  It was also removed before we ensure the generation
of the entry for the new package was generated without error.

Remove the old package at the end of database entry and delta generation. Also
improve the help message to clarify it is the old package that is removed.

Signed-off-by: Allan McRae <allan at archlinux.org>
---
 scripts/repo-add.sh.in | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)

diff --git a/scripts/repo-add.sh.in b/scripts/repo-add.sh.in
index 5089f99..49b1c3e 100644
--- a/scripts/repo-add.sh.in
+++ b/scripts/repo-add.sh.in
@@ -59,7 +59,7 @@ Multiple packages to add can be specified on the command line.\n")"
 		printf -- "$(gettext "Options:\n")"
 		printf -- "$(gettext "  -d, --delta       generate and add delta for package update\n")"
 		printf -- "$(gettext "  -n, --new         only add packages that are not already in the database\n")"
-		printf -- "$(gettext "  -R, --remove      remove package file from disk when updating database entry\n")"
+		printf -- "$(gettext "  -R, --remove      remove old package file from disk after updating database\n")"
 		printf -- "$(gettext "  -f, --files       update database's file list\n")"
 	elif [[ $cmd == "repo-remove" ]] ; then
 		printf -- "$(gettext "Usage: repo-remove [options] <path-to-db> <packagename|delta> ...\n")"
@@ -306,14 +306,13 @@ db_write_entry() {
 				local oldfilename=$(grep -A1 FILENAME "$pkgentry/desc" | tail -n1)
 				local oldfile="$(dirname "$1")/$oldfilename"
 			fi
-		elif (( RMEXISTING )); then
-			# only remove existing package if we're not doing deltas
+		fi
+		if (( RMEXISTING )); then
+			# gather information needed to remove old file
 			pkgentry=$(find_pkgentry "$pkgname")
 			if [[ -n $pkgentry ]]; then
 				local oldfilename="$(sed -n '/^%FILENAME%$/ {n;p;q;}' "$pkgentry/desc")"
 				local oldfile="$(dirname "$1")/$oldfilename"
-				msg2 "$(gettext "Removing existing package '%s'")" "$oldfilename"
-				rm -f ${oldfile} ${oldfile}.sig
 			fi
 		fi
 	fi
@@ -412,6 +411,11 @@ db_write_entry() {
 		fi
 	fi
 
+	if (( RMEXISTING )); then
+		msg2 "$(gettext "Removing old package file '%s'")" "$oldfilename"
+		rm -f ${oldfile} ${oldfile}.sig
+	fi
+
 	return 0
 } # end db_write_entry
 
-- 
2.2.2


More information about the pacman-dev mailing list