[pacman-dev] [PATCH] Added --dont-downgrade flag to repo-add

Eli Schwartz eschwartz at archlinux.org
Sun Apr 28 19:06:41 UTC 2019


On 4/28/19 2:07 PM, ekarndam at autistici.org wrote:
> From: ekardnam <lucabertozzi.pub at gmail.com>
> 

Fixes FS#17752

> Signed-off-by: Luca Bertozzi <ekarndam at autistici.org>
> ---
>  scripts/repo-add.sh.in | 19 ++++++++++++++++---
>  1 file changed, 16 insertions(+), 3 deletions(-)
> 
> diff --git a/scripts/repo-add.sh.in b/scripts/repo-add.sh.in
> index 57413df5..f8748f08 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'
> +DONT_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 "  --dont-downgrade  do not add package to database if a newer version is already present\n")"

I think I too prefer --no-downgrade.

>  	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
> +			

Trailing whitespace here, could be removed. Some editors can trim this
automatically, so can allan when applying. :D

> +			local version=$(sed -n '/^%VERSION%$/ {n;p;q}' "$pkgentry/desc")
> +			if (( "$(vercmp $version $pkgver)" > "0" )); then

Neither of these actually need to be quoted, although sure, quoting
doesn't hurt. But one of them is an integer literal, and vercmp is
guaranteed to produce another integer literal, so there is no word
splitting, globbing, or parameter expansion to worry about.

> +				warning "$(gettext "A newer version for '%s' is already present in database")" "$pkgname"
> +				if (( DONT_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
>  			;;
> +		--dont-downgrade)
> +			DONT_DOWNGRADE=1
> +			;;
>  		*)
>  			args+=("$1")
>  			;;

Thanks for the patch. Aside for these style nits and possible
bikeshedding over the name of the option, the patch looks good to me,
and works as expected.

-- 
Eli Schwartz
Bug Wrangler and Trusted User

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 1601 bytes
Desc: OpenPGP digital signature
URL: <https://lists.archlinux.org/pipermail/pacman-dev/attachments/20190428/a03e71a6/attachment.sig>


More information about the pacman-dev mailing list