[pacman-dev] [PATCH] Make pacman say its downgrading packages
Simon Gomizelj
simongmzlj at gmail.com
Tue Dec 11 08:03:48 EST 2012
When the package being installed has a lower version than the local one,
print that its 'downgrading' instead of 'upgrading' on screen and in the
log.
Fixes FS#30392
Signed-off-by: Simon Gomizelj <simongmzlj at gmail.com>
---
lib/libalpm/add.c | 59 ++++++++++++++++++++++-----------------------------
lib/libalpm/alpm.h | 10 +++++++++
src/pacman/callback.c | 15 +++++++++++++
3 files changed, 50 insertions(+), 34 deletions(-)
diff --git a/lib/libalpm/add.c b/lib/libalpm/add.c
index edddc31..357fc0e 100644
--- a/lib/libalpm/add.c
+++ b/lib/libalpm/add.c
@@ -453,10 +453,13 @@ static int commit_single_pkg(alpm_handle_t *handle, alpm_pkg_t *newpkg,
size_t pkg_current, size_t pkg_count)
{
int i, ret = 0, errors = 0;
- int is_upgrade;
+ int is_upgrade = 0;
alpm_pkg_t *oldpkg = NULL;
alpm_db_t *db = handle->db_local;
alpm_trans_t *trans = handle->trans;
+ alpm_progress_t event = ALPM_PROGRESS_ADD_START;
+ alpm_event_t end = ALPM_EVENT_ADD_DONE, start = ALPM_EVENT_ADD_START;
+ const char *msg = "adding";
const char *pkgfile;
ASSERT(trans != NULL, return -1);
@@ -464,6 +467,18 @@ static int commit_single_pkg(alpm_handle_t *handle, alpm_pkg_t *newpkg,
/* see if this is an upgrade. if so, remove the old package first */
alpm_pkg_t *local = _alpm_db_get_pkgfromcache(db, newpkg->name);
if(local) {
+ int cmp = _alpm_pkg_compare_versions(newpkg, local);
+ if(cmp < 0) {
+ msg = "downgrading";
+ event = ALPM_PROGRESS_DOWNGRADE_START;
+ start = ALPM_EVENT_DOWNGRADE_START;
+ end = ALPM_EVENT_DOWNGRADE_DONE;
+ } else {
+ msg = "upgrading";
+ event = ALPM_PROGRESS_UPGRADE_START;
+ start = ALPM_EVENT_UPGRADE_START;
+ end = ALPM_EVENT_UPGRADE_DONE;
+ }
is_upgrade = 1;
/* we'll need to save some record for backup checks later */
@@ -474,17 +489,15 @@ static int commit_single_pkg(alpm_handle_t *handle, alpm_pkg_t *newpkg,
/* copy over the install reason */
newpkg->reason = alpm_pkg_get_reason(local);
-
- EVENT(handle, ALPM_EVENT_UPGRADE_START, newpkg, local);
- } else {
- is_upgrade = 0;
- EVENT(handle, ALPM_EVENT_ADD_START, newpkg, NULL);
}
+ EVENT(handle, start, newpkg, NULL);
+
pkgfile = newpkg->origin_data.file;
- _alpm_log(handle, ALPM_LOG_DEBUG, "%s package %s-%s\n",
- is_upgrade ? "upgrading" : "adding", newpkg->name, newpkg->version);
+ _alpm_log(handle, ALPM_LOG_DEBUG, "%s package %s-%s\n", msg,
+ newpkg->name, newpkg->version);
+
/* pre_install/pre_upgrade scriptlet */
if(alpm_pkg_has_scriptlet(newpkg) &&
!(trans->flags & ALPM_TRANS_FLAG_NOSCRIPTLET)) {
@@ -552,13 +565,7 @@ static int commit_single_pkg(alpm_handle_t *handle, alpm_pkg_t *newpkg,
}
/* call PROGRESS once with 0 percent, as we sort-of skip that here */
- if(is_upgrade) {
- PROGRESS(handle, ALPM_PROGRESS_UPGRADE_START,
- newpkg->name, 0, pkg_count, pkg_current);
- } else {
- PROGRESS(handle, ALPM_PROGRESS_ADD_START,
- newpkg->name, 0, pkg_count, pkg_current);
- }
+ PROGRESS(handle, event, newpkg->name, 0, pkg_count, pkg_current);
for(i = 0; archive_read_next_header(archive, &entry) == ARCHIVE_OK; i++) {
int percent;
@@ -576,13 +583,7 @@ static int commit_single_pkg(alpm_handle_t *handle, alpm_pkg_t *newpkg,
percent = 0;
}
- if(is_upgrade) {
- PROGRESS(handle, ALPM_PROGRESS_UPGRADE_START,
- newpkg->name, percent, pkg_count, pkg_current);
- } else {
- PROGRESS(handle, ALPM_PROGRESS_ADD_START,
- newpkg->name, percent, pkg_count, pkg_current);
- }
+ PROGRESS(handle, event, newpkg->name, percent, pkg_count, pkg_current);
/* extract the next file from the archive */
errors += extract_single_file(handle, archive, entry, newpkg, oldpkg);
@@ -636,13 +637,7 @@ static int commit_single_pkg(alpm_handle_t *handle, alpm_pkg_t *newpkg,
newpkg->name);
}
- if(is_upgrade) {
- PROGRESS(handle, ALPM_PROGRESS_UPGRADE_START,
- newpkg->name, 100, pkg_count, pkg_current);
- } else {
- PROGRESS(handle, ALPM_PROGRESS_ADD_START,
- newpkg->name, 100, pkg_count, pkg_current);
- }
+ PROGRESS(handle, event, newpkg->name, 100, pkg_count, pkg_current);
/* run the post-install script if it exists */
if(alpm_pkg_has_scriptlet(newpkg)
@@ -655,11 +650,7 @@ static int commit_single_pkg(alpm_handle_t *handle, alpm_pkg_t *newpkg,
free(scriptlet);
}
- if(is_upgrade) {
- EVENT(handle, ALPM_EVENT_UPGRADE_DONE, newpkg, oldpkg);
- } else {
- EVENT(handle, ALPM_EVENT_ADD_DONE, newpkg, oldpkg);
- }
+ EVENT(handle, end, newpkg, oldpkg);
cleanup:
_alpm_pkg_free(oldpkg);
diff --git a/lib/libalpm/alpm.h b/lib/libalpm/alpm.h
index 1d6a8c6..bc067e0 100644
--- a/lib/libalpm/alpm.h
+++ b/lib/libalpm/alpm.h
@@ -311,6 +311,15 @@ typedef enum _alpm_event_t {
* to the callback, respectively.
*/
ALPM_EVENT_UPGRADE_DONE,
+ /** Package will be downgraded.
+ * A pointer to the downgraded package is passed to the callback.
+ */
+ ALPM_EVENT_DOWNGRADE_START,
+ /** Package was downgraded.
+ * A pointer to the new package, and a pointer to the old package is passed
+ * to the callback, respectively.
+ */
+ ALPM_EVENT_DOWNGRADE_DONE,
/** Target package's integrity will be checked. */
ALPM_EVENT_INTEGRITY_START,
/** Target package's integrity was checked. */
@@ -378,6 +387,7 @@ typedef enum _alpm_progress_t {
ALPM_PROGRESS_ADD_START,
ALPM_PROGRESS_UPGRADE_START,
ALPM_PROGRESS_REMOVE_START,
+ ALPM_PROGRESS_DOWNGRADE_START,
ALPM_PROGRESS_CONFLICTS_START,
ALPM_PROGRESS_DISKSPACE_START,
ALPM_PROGRESS_INTEGRITY_START,
diff --git a/src/pacman/callback.c b/src/pacman/callback.c
index 01c6b61..5ebe957 100644
--- a/src/pacman/callback.c
+++ b/src/pacman/callback.c
@@ -203,6 +203,18 @@ void cb_event(alpm_event_t event, void *data1, void *data2)
alpm_pkg_get_version(data1));
display_new_optdepends(data2,data1);
break;
+ case ALPM_EVENT_DOWNGRADE_START:
+ if(config->noprogressbar) {
+ printf(_("downgrading %s...\n"), alpm_pkg_get_name(data1));
+ }
+ break;
+ case ALPM_EVENT_DOWNGRADE_DONE:
+ alpm_logaction(config->handle, "downgraded %s (%s -> %s)\n",
+ alpm_pkg_get_name(data1),
+ alpm_pkg_get_version(data2),
+ alpm_pkg_get_version(data1));
+ display_new_optdepends(data2,data1);
+ break;
case ALPM_EVENT_INTEGRITY_START:
if(config->noprogressbar) {
printf(_("checking package integrity...\n"));
@@ -423,6 +435,9 @@ void cb_progress(alpm_progress_t event, const char *pkgname, int percent,
case ALPM_PROGRESS_REMOVE_START:
opr = _("removing");
break;
+ case ALPM_PROGRESS_DOWNGRADE_START:
+ opr = _("downgrading");
+ break;
case ALPM_PROGRESS_CONFLICTS_START:
opr = _("checking for file conflicts");
break;
--
1.8.0.1
More information about the pacman-dev
mailing list