summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Gomizelj <simongmzlj@gmail.com>2013-03-07 01:32:41 -0500
committerAllan McRae <allan@archlinux.org>2013-03-10 09:01:56 +1000
commitce9fd69eba44d997a660c982a8149fae7acb6a29 (patch)
treedf011f59761e8a9352e323c184ed14be23b612ff
parent9876d9783979ec031d673e9a6df845e52fd2febb (diff)
downloadpacman-ce9fd69eba44d997a660c982a8149fae7acb6a29.tar.xz
make status/log messages reflect version change
Currently pacman either prints 'adding' or 'upgrading' when installing a package. This make pacman print and log the other possible actions: 'downgrade' and 'reinstall' Signed-off-by: Simon Gomizelj <simongmzlj@gmail.com> Signed-off-by: Allan McRae <allan@archlinux.org>
-rw-r--r--lib/libalpm/add.c61
-rw-r--r--lib/libalpm/alpm.h20
-rw-r--r--src/pacman/callback.c30
3 files changed, 78 insertions, 33 deletions
diff --git a/lib/libalpm/add.c b/lib/libalpm/add.c
index f70e2cb1..1d9db602 100644
--- a/lib/libalpm/add.c
+++ b/lib/libalpm/add.c
@@ -464,10 +464,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 done = ALPM_EVENT_ADD_DONE, start = ALPM_EVENT_ADD_START;
+ const char *log_msg = "adding";
const char *pkgfile;
ASSERT(trans != NULL, return -1);
@@ -475,6 +478,23 @@ 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) {
+ log_msg = "downgrading";
+ event = ALPM_PROGRESS_DOWNGRADE_START;
+ start = ALPM_EVENT_DOWNGRADE_START;
+ done = ALPM_EVENT_DOWNGRADE_DONE;
+ } else if(cmp == 0) {
+ log_msg = "reinstalling";
+ event = ALPM_PROGRESS_REINSTALL_START;
+ start = ALPM_EVENT_REINSTALL_START;
+ done = ALPM_EVENT_REINSTALL_DONE;
+ } else {
+ log_msg = "upgrading";
+ event = ALPM_PROGRESS_UPGRADE_START;
+ start = ALPM_EVENT_UPGRADE_START;
+ done = ALPM_EVENT_UPGRADE_DONE;
+ }
is_upgrade = 1;
/* we'll need to save some record for backup checks later */
@@ -485,17 +505,14 @@ 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, local);
+
pkgfile = newpkg->origin_data.file;
_alpm_log(handle, ALPM_LOG_DEBUG, "%s package %s-%s\n",
- is_upgrade ? "upgrading" : "adding", newpkg->name, newpkg->version);
+ log_msg, newpkg->name, newpkg->version);
/* pre_install/pre_upgrade scriptlet */
if(alpm_pkg_has_scriptlet(newpkg) &&
!(trans->flags & ALPM_TRANS_FLAG_NOSCRIPTLET)) {
@@ -564,13 +581,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;
@@ -588,13 +599,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);
@@ -651,13 +656,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)
@@ -670,11 +669,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, done, newpkg, oldpkg);
cleanup:
_alpm_pkg_free(oldpkg);
diff --git a/lib/libalpm/alpm.h b/lib/libalpm/alpm.h
index afa5cd7d..ccbdd1c6 100644
--- a/lib/libalpm/alpm.h
+++ b/lib/libalpm/alpm.h
@@ -321,6 +321,24 @@ 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,
+ /** Package will be reinstalled.
+ * A pointer to the reinstalled package is passed to the callback.
+ */
+ ALPM_EVENT_REINSTALL_START,
+ /** Package was reinstalled.
+ * A pointer to the new package, and a pointer to the old package is passed
+ * to the callback, respectively.
+ */
+ ALPM_EVENT_REINSTALL_DONE,
/** Target package's integrity will be checked. */
ALPM_EVENT_INTEGRITY_START,
/** Target package's integrity was checked. */
@@ -400,6 +418,8 @@ typedef void (*alpm_cb_question)(alpm_question_t, void *, void *, void *, int *)
typedef enum _alpm_progress_t {
ALPM_PROGRESS_ADD_START,
ALPM_PROGRESS_UPGRADE_START,
+ ALPM_PROGRESS_DOWNGRADE_START,
+ ALPM_PROGRESS_REINSTALL_START,
ALPM_PROGRESS_REMOVE_START,
ALPM_PROGRESS_CONFLICTS_START,
ALPM_PROGRESS_DISKSPACE_START,
diff --git a/src/pacman/callback.c b/src/pacman/callback.c
index d0887cb7..71d9d04d 100644
--- a/src/pacman/callback.c
+++ b/src/pacman/callback.c
@@ -207,6 +207,30 @@ 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, PACMAN_CALLER_PREFIX,
+ "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_REINSTALL_START:
+ if(config->noprogressbar) {
+ printf(_("reinstalling %s...\n"), alpm_pkg_get_name(data1));
+ }
+ break;
+ case ALPM_EVENT_REINSTALL_DONE:
+ alpm_logaction(config->handle, PACMAN_CALLER_PREFIX,
+ "reinstalled %s (%s)\n",
+ alpm_pkg_get_name(data1),
+ alpm_pkg_get_version(data1));
+ break;
case ALPM_EVENT_INTEGRITY_START:
if(config->noprogressbar) {
printf(_("checking package integrity...\n"));
@@ -444,6 +468,12 @@ void cb_progress(alpm_progress_t event, const char *pkgname, int percent,
case ALPM_PROGRESS_UPGRADE_START:
opr = _("upgrading");
break;
+ case ALPM_PROGRESS_DOWNGRADE_START:
+ opr = _("downgrading");
+ break;
+ case ALPM_PROGRESS_REINSTALL_START:
+ opr = _("reinstalling");
+ break;
case ALPM_PROGRESS_REMOVE_START:
opr = _("removing");
break;