FAQ Search Today's Posts Mark Forums Read
» Video Reviews

» Linux Archive

Linux-archive is a website aiming to archive linux email lists and to make them easily accessible for linux users/developers.


» Sponsor

» Partners

» Sponsor

Go Back   Linux Archive > ArchLinux > ArchLinux Pacman Development

 
 
LinkBack Thread Tools
 
Old 06-02-2008, 09:57 AM
Xavier
 
Default Cleanup of _alpm_pkg_compare_versions.

>From d8d35bb85e5f3eb89a1f68e528e25cafe2719790 Mon Sep 17 00:00:00 2001
From: Xavier Chantry <shiningxc@gmail.com>
Date: Sat, 31 May 2008 15:06:30 +0200
Subject: [PATCH] Cleanup of _alpm_pkg_compare_versions.

* Change the return values to be more informative.
It was previously boolean, only indicating if the sync pkg was newer than
local pkg or not.
Now it is a cmp function : -1 if sync pkg is older, 0 if same version, 1 if
newer.

* Add a new alpm_pkg_has_force function to access the pkg->force field like
any other package fields.

* Remove the not so useful and confusing "skipping" and "reinstalling"
messages, which were also cluttering the -Sp and -Sw output.

* Clarify the description of the --needed option.

Signed-off-by: Xavier Chantry <shiningxc@gmail.com>
---
doc/pacman.8.txt | 2 +-
lib/libalpm/alpm.h | 1 +
lib/libalpm/package.c | 25 ++++++++++++++++---------
lib/libalpm/sync.c | 19 ++++++-------------
src/pacman/pacman.c | 2 +-
5 files changed, 25 insertions(+), 24 deletions(-)

diff --git a/doc/pacman.8.txt b/doc/pacman.8.txt
index a6bc3d9..ccdabe6 100644
--- a/doc/pacman.8.txt
+++ b/doc/pacman.8.txt
@@ -291,7 +291,7 @@ linkmanacman.conf[5].
to date.

*--needed*::
- Only install the targets that are not already installed and up-to-date.
+ Don't reinstall the targets that are already up-to-date.

*--ignore* <'package'>::
Directs pacman to ignore upgrades of package even if there is one
diff --git a/lib/libalpm/alpm.h b/lib/libalpm/alpm.h
index 62a517b..9c08033 100644
--- a/lib/libalpm/alpm.h
+++ b/lib/libalpm/alpm.h
@@ -220,6 +220,7 @@ size_t alpm_pkg_changelog_read(void *ptr, size_t size,
/*int alpm_pkg_changelog_feof(const pmpkg_t *pkg, void *fp);*/
int alpm_pkg_changelog_close(const pmpkg_t *pkg, void *fp);
unsigned short alpm_pkg_has_scriptlet(pmpkg_t *pkg);
+unsigned short alpm_pkg_has_force(pmpkg_t *pkg);

unsigned long alpm_pkg_download_size(pmpkg_t *newpkg);

diff --git a/lib/libalpm/package.c b/lib/libalpm/package.c
index 07b5fa3..4d6da01 100644
--- a/lib/libalpm/package.c
+++ b/lib/libalpm/package.c
@@ -295,6 +295,20 @@ alpm_list_t SYMEXPORT *alpm_pkg_get_groups(pmpkg_t *pkg)
return pkg->groups;
}

+unsigned short SYMEXPORT alpm_pkg_has_force(pmpkg_t *pkg)
+{
+ ALPM_LOG_FUNC;
+
+ /* Sanity checks */
+ ASSERT(handle != NULL, return(-1));
+ ASSERT(pkg != NULL, return(-1));
+
+ if(pkg->origin == PKG_FROM_CACHE && !(pkg->infolevel & INFRQ_DESC)) {
+ _alpm_db_read(pkg->origin_data.db, pkg, INFRQ_DESC);
+ }
+ return pkg->force;
+}
+
alpm_list_t SYMEXPORT *alpm_pkg_get_depends(pmpkg_t *pkg)
{
ALPM_LOG_FUNC;
@@ -817,22 +831,16 @@ void _alpm_pkg_free(pmpkg_t *pkg)
FREE(pkg);
}

-/* Is pkgB an upgrade for pkgA ? */
+/* Compare the versions of two packages, handling the force flag */
int _alpm_pkg_compare_versions(pmpkg_t *local_pkg, pmpkg_t *pkg)
{
int cmp = 0;

ALPM_LOG_FUNC;

- if(pkg->origin == PKG_FROM_CACHE) {
- /* ensure we have the /desc file, which contains the 'force' option */
- _alpm_db_read(pkg->origin_data.db, pkg, INFRQ_DESC);
- }
-
- /* compare versions and see if we need to upgrade */
cmp = alpm_pkg_vercmp(alpm_pkg_get_version(pkg),
alpm_pkg_get_version(local_pkg));

- if(cmp != 0 && pkg->force) {
+ if(cmp < 0 && alpm_pkg_has_force(pkg)) {
cmp = 1;
_alpm_log(PM_LOG_WARNING, _("%s: forcing upgrade to version %s
"),
alpm_pkg_get_name(pkg), alpm_pkg_get_version(pkg));
@@ -842,7 +850,6 @@ int _alpm_pkg_compare_versions(pmpkg_t *local_pkg,
pmpkg_t *pkg)
_alpm_log(PM_LOG_WARNING, _("%s: local (%s) is newer than %s (%s)
"),
alpm_pkg_get_name(local_pkg), alpm_pkg_get_version(local_pkg),
alpm_db_get_name(db), alpm_pkg_get_version(pkg));
- cmp = 0;
}

return(cmp);
diff --git a/lib/libalpm/sync.c b/lib/libalpm/sync.c
index 0d6a6ee..d44f445 100644
--- a/lib/libalpm/sync.c
+++ b/lib/libalpm/sync.c
@@ -179,7 +179,7 @@ pmpkg_t SYMEXPORT *alpm_sync_newversion(pmpkg_t
*pkg, alpm_list_t *dbs_sync)
}

/* compare versions and see if spkg is an upgrade */
- if(_alpm_pkg_compare_versions(pkg, spkg)) {
+ if(_alpm_pkg_compare_versions(pkg, spkg) > 0) {
_alpm_log(PM_LOG_DEBUG, "new version of '%s' found (%s => %s)
",
alpm_pkg_get_name(pkg), alpm_pkg_get_version(pkg),
alpm_pkg_get_version(spkg));
@@ -322,6 +322,7 @@ int _alpm_sync_addtarget(pmtrans_t *trans, pmdb_t
*db_local, alpm_list_t *dbs_sy
RET_ERR(PM_ERR_TRANS_DUP_TARGET, -1);
}

+ /* this is especially useful when installing a group */
if(_alpm_pkg_should_ignore(spkg)) {
int resp;
QUESTION(trans, PM_TRANS_CONV_INSTALL_IGNOREPKG, spkg, NULL, NULL, &resp);
@@ -332,18 +333,10 @@ int _alpm_sync_addtarget(pmtrans_t *trans,
pmdb_t *db_local, alpm_list_t *dbs_sy

local = _alpm_db_get_pkgfromcache(db_local, alpm_pkg_get_name(spkg));
if(local) {
- if(_alpm_pkg_compare_versions(local, spkg) == 0) {
- /* spkg is NOT an upgrade */
- if(trans->flags & PM_TRANS_FLAG_NEEDED) {
- _alpm_log(PM_LOG_WARNING, _("%s-%s is up to date -- skipping
"),
- alpm_pkg_get_name(local), alpm_pkg_get_version(local));
- return(0);
- } else {
- if(!(trans->flags & PM_TRANS_FLAG_DOWNLOADONLY)) {
- _alpm_log(PM_LOG_WARNING, _("%s-%s is up to date -- reinstalling
"),
- alpm_pkg_get_name(local), alpm_pkg_get_version(local));
- }
- }
+ int cmp = _alpm_pkg_compare_versions(local, spkg);
+ if(cmp == 0 && trans->flags & PM_TRANS_FLAG_NEEDED) {
+ /* with the NEEDED flag, packages up to date are not reinstalled */
+ return(0);
}
}

diff --git a/src/pacman/pacman.c b/src/pacman/pacman.c
index 66fafa1..8e8f058 100644
--- a/src/pacman/pacman.c
+++ b/src/pacman/pacman.c
@@ -123,7 +123,7 @@ static void usage(int op, const char * const myname)
printf(_(" -u, --sysupgrade upgrade all packages that are out
of date
"));
printf(_(" -w, --downloadonly download packages but do not
install/upgrade anything
"));
printf(_(" -y, --refresh download fresh package databases
from the server
"));
- printf(_(" --needed only upgrade outdated or not yet
installed packages
"));
+ printf(_(" --needed don't reinstall up to date packages
"));
printf(_(" --ignore <pkg> ignore a package upgrade (can be
used more than once)
"));
printf(_(" --ignoregroup <grp>
"
" ignore a group upgrade (can be
used more than once)
"));
--
1.5.5.1

_______________________________________________
pacman-dev mailing list
pacman-dev@archlinux.org
http://archlinux.org/mailman/listinfo/pacman-dev
 
Old 08-22-2008, 09:02 PM
Xavier Chantry
 
Default Cleanup of _alpm_pkg_compare_versions.

* Change the return values to be more informative.

It was previously boolean, only indicating if a sync package was newer than
a local package.

Now it is a simple wrapper to vercmp, handling the force flag.

* Remove the verbose output from _alpm_pkg_compare_versions.

The "force" message is not so useful.
The "package : local (v1) is newer than repo (v2)" message can be moved to
-Su operation.
For the -S operation, it is better to have something like :
"downgrading package from v1 to v2"

* Don't display the "up to date -- skipping" and "up to date -- reinstalling"
messages, when the local version is newer than the sync one.

* Fix the behavior of --needed option to not skip a target when the local
version is newer, and clarify its description.

* Add a new alpm_pkg_has_force function

This allows us to access the pkg->force field like any other package fields.

Signed-off-by: Xavier Chantry <shiningxc@gmail.com>
---
doc/pacman.8.txt | 2 +-
lib/libalpm/alpm.h | 1 +
lib/libalpm/package.c | 38 +++++++++++++++++++-------------------
lib/libalpm/sync.c | 30 +++++++++++++++++++++---------
src/pacman/pacman.c | 2 +-
5 files changed, 43 insertions(+), 30 deletions(-)

diff --git a/doc/pacman.8.txt b/doc/pacman.8.txt
index 0a632ea..6f071ba 100644
--- a/doc/pacman.8.txt
+++ b/doc/pacman.8.txt
@@ -308,7 +308,7 @@ linkmanacman.conf[5].
to date.

*--needed*::
- Only install the targets that are not already installed and up-to-date.
+ Don't reinstall the targets that are already up-to-date.

*--ignore* <'package'>::
Directs pacman to ignore upgrades of package even if there is one
diff --git a/lib/libalpm/alpm.h b/lib/libalpm/alpm.h
index fbef057..16b48a0 100644
--- a/lib/libalpm/alpm.h
+++ b/lib/libalpm/alpm.h
@@ -224,6 +224,7 @@ size_t alpm_pkg_changelog_read(void *ptr, size_t size,
/*int alpm_pkg_changelog_feof(const pmpkg_t *pkg, void *fp);*/
int alpm_pkg_changelog_close(const pmpkg_t *pkg, void *fp);
unsigned short alpm_pkg_has_scriptlet(pmpkg_t *pkg);
+unsigned short alpm_pkg_has_force(pmpkg_t *pkg);

off_t alpm_pkg_download_size(pmpkg_t *newpkg);

diff --git a/lib/libalpm/package.c b/lib/libalpm/package.c
index 49238ea..eaef688 100644
--- a/lib/libalpm/package.c
+++ b/lib/libalpm/package.c
@@ -295,6 +295,20 @@ alpm_list_t SYMEXPORT *alpm_pkg_get_groups(pmpkg_t *pkg)
return pkg->groups;
}

+unsigned short SYMEXPORT alpm_pkg_has_force(pmpkg_t *pkg)
+{
+ ALPM_LOG_FUNC;
+
+ /* Sanity checks */
+ ASSERT(handle != NULL, return(-1));
+ ASSERT(pkg != NULL, return(-1));
+
+ if(pkg->origin == PKG_FROM_CACHE && !(pkg->infolevel & INFRQ_DESC)) {
+ _alpm_db_read(pkg->origin_data.db, pkg, INFRQ_DESC);
+ }
+ return pkg->force;
+}
+
alpm_list_t SYMEXPORT *alpm_pkg_get_depends(pmpkg_t *pkg)
{
ALPM_LOG_FUNC;
@@ -827,32 +841,18 @@ void _alpm_pkg_free(pmpkg_t *pkg)
FREE(pkg);
}

-/* Is pkgB an upgrade for pkgA ? */
-int _alpm_pkg_compare_versions(pmpkg_t *local_pkg, pmpkg_t *pkg)
+/* Is spkg an upgrade for locapkg? */
+int _alpm_pkg_compare_versions(pmpkg_t *spkg, pmpkg_t *localpkg)
{
int cmp = 0;

ALPM_LOG_FUNC;

- if(pkg->origin == PKG_FROM_CACHE) {
- /* ensure we have the /desc file, which contains the 'force' option */
- _alpm_db_read(pkg->origin_data.db, pkg, INFRQ_DESC);
- }
-
- /* compare versions and see if we need to upgrade */
- cmp = alpm_pkg_vercmp(alpm_pkg_get_version(pkg), alpm_pkg_get_version(local_pkg));
+ cmp = alpm_pkg_vercmp(alpm_pkg_get_version(spkg),
+ alpm_pkg_get_version(localpkg));

- if(cmp != 0 && pkg->force) {
+ if(cmp < 0 && alpm_pkg_has_force(spkg)) {
cmp = 1;
- _alpm_log(PM_LOG_WARNING, _("%s: forcing upgrade to version %s
"),
- alpm_pkg_get_name(pkg), alpm_pkg_get_version(pkg));
- } else if(cmp < 0) {
- /* local version is newer */
- pmdb_t *db = pkg->origin_data.db;
- _alpm_log(PM_LOG_WARNING, _("%s: local (%s) is newer than %s (%s)
"),
- alpm_pkg_get_name(local_pkg), alpm_pkg_get_version(local_pkg),
- alpm_db_get_name(db), alpm_pkg_get_version(pkg));
- cmp = 0;
}

return(cmp);
diff --git a/lib/libalpm/sync.c b/lib/libalpm/sync.c
index 7a577a1..4a705b5 100644
--- a/lib/libalpm/sync.c
+++ b/lib/libalpm/sync.c
@@ -170,6 +170,7 @@ pmpkg_t SYMEXPORT *alpm_sync_newversion(pmpkg_t *pkg, alpm_list_t *dbs_sync)
{
alpm_list_t *i;
pmpkg_t *spkg = NULL;
+ int cmp;

for(i = dbs_sync; !spkg && i; i = i->next) {
spkg = _alpm_db_get_pkgfromcache(i->data, alpm_pkg_get_name(pkg));
@@ -182,14 +183,20 @@ pmpkg_t SYMEXPORT *alpm_sync_newversion(pmpkg_t *pkg, alpm_list_t *dbs_sync)
}

/* compare versions and see if spkg is an upgrade */
- if(_alpm_pkg_compare_versions(pkg, spkg)) {
+ cmp = _alpm_pkg_compare_versions(spkg, pkg);
+ if(cmp > 0) {
_alpm_log(PM_LOG_DEBUG, "new version of '%s' found (%s => %s)
",
alpm_pkg_get_name(pkg), alpm_pkg_get_version(pkg),
alpm_pkg_get_version(spkg));
return(spkg);
- } else {
- return(NULL);
}
+ if (cmp < 0) {
+ pmdb_t *db = spkg->origin_data.db;
+ _alpm_log(PM_LOG_WARNING, _("%s: local (%s) is newer than %s (%s)
"),
+ alpm_pkg_get_name(pkg), alpm_pkg_get_version(pkg),
+ alpm_db_get_name(db), alpm_pkg_get_version(spkg));
+ }
+ return(NULL);
}

/** Get a list of upgradable packages on the current system
@@ -326,18 +333,23 @@ int _alpm_sync_addtarget(pmtrans_t *trans, pmdb_t *db_local, alpm_list_t *dbs_sy

local = _alpm_db_get_pkgfromcache(db_local, alpm_pkg_get_name(spkg));
if(local) {
- if(_alpm_pkg_compare_versions(local, spkg) == 0) {
- /* spkg is NOT an upgrade */
+ int cmp = _alpm_pkg_compare_versions(spkg, local);
+ if(cmp == 0) {
if(trans->flags & PM_TRANS_FLAG_NEEDED) {
+ /* with the NEEDED flag, packages up to date are not reinstalled */
_alpm_log(PM_LOG_WARNING, _("%s-%s is up to date -- skipping
"),
alpm_pkg_get_name(local), alpm_pkg_get_version(local));
return(0);
} else {
- if(!(trans->flags & PM_TRANS_FLAG_DOWNLOADONLY)) {
- _alpm_log(PM_LOG_WARNING, _("%s-%s is up to date -- reinstalling
"),
- alpm_pkg_get_name(local), alpm_pkg_get_version(local));
- }
+ _alpm_log(PM_LOG_WARNING, _("%s-%s is up to date -- reinstalling
"),
+ alpm_pkg_get_name(local), alpm_pkg_get_version(local));
+
}
+ } else if(cmp < 0) {
+ /* local version is newer */
+ _alpm_log(PM_LOG_WARNING, _("downgrading package %s (%s => %s)
"),
+ alpm_pkg_get_name(local), alpm_pkg_get_version(local),
+ alpm_pkg_get_version(spkg));
}
}

diff --git a/src/pacman/pacman.c b/src/pacman/pacman.c
index 33df4e1..04b5e49 100644
--- a/src/pacman/pacman.c
+++ b/src/pacman/pacman.c
@@ -130,7 +130,7 @@ static void usage(int op, const char * const myname)
printf(_(" -u, --sysupgrade upgrade all packages that are out of date
"));
printf(_(" -w, --downloadonly download packages but do not install/upgrade anything
"));
printf(_(" -y, --refresh download fresh package databases from the server
"));
- printf(_(" --needed only upgrade outdated or not yet installed packages
"));
+ printf(_(" --needed don't reinstall up to date packages
"));
printf(_(" --ignore <pkg> ignore a package upgrade (can be used more than once)
"));
printf(_(" --ignoregroup <grp>
"
" ignore a group upgrade (can be used more than once)
"));
--
1.6.0

_______________________________________________
pacman-dev mailing list
pacman-dev@archlinux.org
http://archlinux.org/mailman/listinfo/pacman-dev
 

Thread Tools




All times are GMT. The time now is 12:23 PM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright 2007 - 2008, www.linux-archive.org