From 449d53df4a41f3856a5dba967e2eb186aa64914a Mon Sep 17 00:00:00 2001 From: Nagy Gabor <ngaba@bibl.u-szeged.hu> Date: Thu, 14 May 2009 18:25:16 +0200 Subject: [PATCH] Introduce -Suu
If the user switches from unstable repo to a stable one, it is quite hard to sync its system with the new repo (the user will see many "Local is newer than stable" messages, nothing more). That's why I introduced -Suu, which treats a sync package like an upgrade, iff the package version doesn't match with the local one's. I added a new pactest (sync104.py) to test this, and I updated the documentation of -Su. Signed-off-by: Nagy Gabor <ngaba@bibl.u-szeged.hu> --- doc/pacman.8.txt | 5 ++++- lib/libalpm/alpm.h | 2 +- lib/libalpm/sync.c | 18 +++++++++++++++--- lib/libalpm/sync.h | 2 +- lib/libalpm/trans.c | 4 ++-- pactest/tests/sync104.py | 12 ++++++++++++ src/pacman/pacman.c | 3 ++- src/pacman/sync.c | 2 +- 8 files changed, 38 insertions(+), 10 deletions(-) create mode 100644 pactest/tests/sync104.py diff --git a/doc/pacman.8.txt b/doc/pacman.8.txt index 4582be5..e914ab4 100644 --- a/doc/pacman.8.txt +++ b/doc/pacman.8.txt @@ -310,7 +310,10 @@ linkman:pacman.conf[5]. report of all packages to upgrade will be presented and the operation will not proceed without user confirmation. Dependencies are automatically resolved at this level and will be installed/upgraded if - necessary. + necessary. Pass this option twice to enable package downgrade; in this + case pacman will select sync packages whose version does not match with + the local ones'. For example, this can be useful when the user + switches from a testing repo to a stable one. *-w, \--downloadonly*:: Retrieve all packages from the server, but do not install/upgrade diff --git a/lib/libalpm/alpm.h b/lib/libalpm/alpm.h index 57ea880..2a6c2e0 100644 --- a/lib/libalpm/alpm.h +++ b/lib/libalpm/alpm.h @@ -395,7 +395,7 @@ alpm_list_t * alpm_trans_get_pkgs(); int alpm_trans_init(pmtranstype_t type, pmtransflag_t flags, alpm_trans_cb_event cb_event, alpm_trans_cb_conv conv, alpm_trans_cb_progress cb_progress); -int alpm_trans_sysupgrade(void); +int alpm_trans_sysupgrade(int enable_downgrade); int alpm_trans_addtarget(char *target); int alpm_trans_prepare(alpm_list_t **data); int alpm_trans_commit(alpm_list_t **data); diff --git a/lib/libalpm/sync.c b/lib/libalpm/sync.c index abda147..ccd6424 100644 --- a/lib/libalpm/sync.c +++ b/lib/libalpm/sync.c @@ -79,7 +79,7 @@ pmpkg_t SYMEXPORT *alpm_sync_newversion(pmpkg_t *pkg, alpm_list_t *dbs_sync) return(NULL); } -int _alpm_sync_sysupgrade(pmtrans_t *trans, pmdb_t *db_local, alpm_list_t *dbs_sync) +int _alpm_sync_sysupgrade(pmtrans_t *trans, pmdb_t *db_local, alpm_list_t *dbs_sync, int enable_downgrade) { alpm_list_t *i, *j, *k; @@ -115,8 +115,20 @@ int _alpm_sync_sysupgrade(pmtrans_t *trans, pmdb_t *db_local, alpm_list_t *dbs_s trans->packages = alpm_list_add(trans->packages, spkg); } } else if(cmp < 0) { - _alpm_log(PM_LOG_WARNING, _("%s: local (%s) is newer than %s (%s)\n"), - lpkg->name, lpkg->version, sdb->treename, spkg->version); + if(enable_downgrade) { + /* check IgnorePkg/IgnoreGroup */ + if(_alpm_pkg_should_ignore(spkg) || _alpm_pkg_should_ignore(lpkg)) { + _alpm_log(PM_LOG_WARNING, _("%s: ignoring package downgrade (%s => %s)\n"), + lpkg->name, lpkg->version, spkg->version); + } else { + _alpm_log(PM_LOG_WARNING, _("%s: downgrading from version %s to version %s\n"), + lpkg->name, lpkg->version, spkg->version); + trans->packages = alpm_list_add(trans->packages, spkg); + } + } else { + _alpm_log(PM_LOG_WARNING, _("%s: local (%s) is newer than %s (%s)\n"), + lpkg->name, lpkg->version, sdb->treename, spkg->version); + } } break; /* jump to next local package */ } else { /* 2. search for replacers in sdb */ diff --git a/lib/libalpm/sync.h b/lib/libalpm/sync.h index 00985b6..8171e36 100644 --- a/lib/libalpm/sync.h +++ b/lib/libalpm/sync.h @@ -23,7 +23,7 @@ #include "alpm.h" -int _alpm_sync_sysupgrade(pmtrans_t *trans, pmdb_t *db_local, alpm_list_t *dbs_sync); +int _alpm_sync_sysupgrade(pmtrans_t *trans, pmdb_t *db_local, alpm_list_t *dbs_sync, int enable_downgrade); int _alpm_sync_addtarget(pmtrans_t *trans, pmdb_t *db_local, alpm_list_t *dbs_sync, char *name); int _alpm_sync_prepare(pmtrans_t *trans, pmdb_t *db_local, alpm_list_t *dbs_sync, alpm_list_t **data); diff --git a/lib/libalpm/trans.c b/lib/libalpm/trans.c index ef56841..b144b2a 100644 --- a/lib/libalpm/trans.c +++ b/lib/libalpm/trans.c @@ -87,7 +87,7 @@ int SYMEXPORT alpm_trans_init(pmtranstype_t type, pmtransflag_t flags, /** Search for packages to upgrade and add them to the transaction. * @return 0 on success, -1 on error (pm_errno is set accordingly) */ -int SYMEXPORT alpm_trans_sysupgrade() +int SYMEXPORT alpm_trans_sysupgrade(int enable_downgrade) { pmtrans_t *trans; @@ -100,7 +100,7 @@ int SYMEXPORT alpm_trans_sysupgrade() ASSERT(trans->state == STATE_INITIALIZED, RET_ERR(PM_ERR_TRANS_NOT_INITIALIZED, -1)); ASSERT(trans->type == PM_TRANS_TYPE_SYNC, RET_ERR(PM_ERR_TRANS_TYPE, -1)); - return(_alpm_sync_sysupgrade(trans, handle->db_local, handle->dbs_sync)); + return(_alpm_sync_sysupgrade(trans, handle->db_local, handle->dbs_sync, enable_downgrade)); } /** Add a target to the transaction. diff --git a/pactest/tests/sync104.py b/pactest/tests/sync104.py new file mode 100644 index 0000000..6d51b85 --- /dev/null +++ b/pactest/tests/sync104.py @@ -0,0 +1,12 @@ +self.description = "-Suu" + +sp = pmpkg("dummy", "0.9-1") +lp = pmpkg("dummy", "1.0-1") + +self.addpkg2db("sync", sp) +self.addpkg2db("local", lp) + +self.args = "-Suu" + +self.addrule("PACMAN_RETCODE=0") +self.addrule("PKG_VERSION=dummy|0.9-1") diff --git a/src/pacman/pacman.c b/src/pacman/pacman.c index 72a72ba..6e2d96c 100644 --- a/src/pacman/pacman.c +++ b/src/pacman/pacman.c @@ -129,6 +129,7 @@ static void usage(int op, const char * const myname) printf(_(" -p, --print-uris print out URIs for given packages and their dependencies\n")); printf(_(" -s, --search <regex> search remote repositories for matching strings\n")); printf(_(" -u, --sysupgrade upgrade all packages that are out of date\n")); + printf(_(" (-uu enables package downgrade)\n")); printf(_(" -w, --downloadonly download packages but do not install/upgrade anything\n")); printf(_(" -y, --refresh download fresh package databases from the server\n")); printf(_(" --needed don't reinstall up to date packages\n")); @@ -501,7 +502,7 @@ static int parseargs(int argc, char *argv[]) config->op_q_unrequired = 1; break; case 'u': - config->op_s_upgrade = 1; + (config->op_s_upgrade)++; config->op_q_upgrade = 1; config->flags |= PM_TRANS_FLAG_UNNEEDED; break; diff --git a/src/pacman/sync.c b/src/pacman/sync.c index 68fb81a..3a03b42 100644 --- a/src/pacman/sync.c +++ b/src/pacman/sync.c @@ -561,7 +561,7 @@ static int sync_trans(alpm_list_t *targets) if(config->op_s_upgrade) { printf(_(":: Starting full system upgrade...\n")); alpm_logaction("starting full system upgrade\n"); - if(alpm_trans_sysupgrade() == -1) { + if(alpm_trans_sysupgrade(config->op_s_upgrade >= 2) == -1) { pm_fprintf(stderr, PM_LOG_ERROR, "%s\n", alpm_strerrorlast()); retval = 1; goto cleanup; -- 1.6.0.3