[pacman-dev] [PATCH 1/5] Add epoch support to pacman/libalpm

Allan McRae allan at archlinux.org
Fri Oct 8 23:31:07 EDT 2010


On 09/10/10 01:02, Dan McGee wrote:
<snip>

> -/* Is spkg an upgrade for locapkg? */
> +/* Is spkg an upgrade for localpkg? */
>   int _alpm_pkg_compare_versions(pmpkg_t *spkg, pmpkg_t *localpkg)
>   {
> -	int cmp = 0;
> +	int spkg_epoch, localpkg_epoch;
>
>   	ALPM_LOG_FUNC;
>
> -	cmp = alpm_pkg_vercmp(alpm_pkg_get_version(spkg),
> -			alpm_pkg_get_version(localpkg));
> +	spkg_epoch = alpm_pkg_get_epoch(spkg);
> +	localpkg_epoch = alpm_pkg_get_epoch(localpkg);
>
> -	if(cmp<  0&&  alpm_pkg_has_force(spkg)) {
> -		cmp = 1;
> +	if(spkg_epoch>  localpkg_epoch) {
> +		return(1);
> +	} else if(spkg_epoch<  localpkg_epoch) {
> +		return(-1);
>   	}
>
> -	return(cmp);
> +	/* equal epoch values, move on to version comparison */
> +	return alpm_pkg_vercmp(alpm_pkg_get_version(spkg),
> +			alpm_pkg_get_version(localpkg));
>   }


How about:

/* Is spkg an upgrade for localpkg? */
int _alpm_pkg_compare_versions(pmpkg_t *spkg, pmpkg_t *localpkg)
{
	int cmp, spkg_epoch, localpkg_epoch;

    	ALPM_LOG_FUNC;

	cmp = alpm_pkg_vercmp(alpm_pkg_get_version(spkg),
			alpm_pkg_get_version(localpkg));

	spkg_epoch = alpm_pkg_get_epoch(spkg);
	localpkg_epoch = alpm_pkg_get_epoch(localpkg);

	if(spkg_epoch > localpkg_epoch && cmp != 0) {
		return(1);
	} else if(spkg_epoch < localpkg_epoch) {
		return(-1);
  	}

	return(cmp);
}


So, when 'force' option is in effect, spkg_epoch = INT_MAX, 
localpkg_epoch = 0, but the versions are the same so we ignore it.

Allan


More information about the pacman-dev mailing list