From ff9744aa1f9d3da380e722fd44a07b8c8a68d101 Mon Sep 17 00:00:00 2001 From: Chantry Xavier Date: Sat, 26 Apr 2008 11:30:49 +0200 Subject: Refactor the trans init and release code. The calls to alpm_trans_init and alpm_trans_release (+ error checking) were duplicated between remove.c, sync.c and upgrade.c This patch introduces trans_init and trans_release functions in util.c to have this code just once. So instead of having to do the same change 3 times for fixing FS#10273, I just had to do it once (so I did it too :)) Signed-off-by: Chantry Xavier Signed-off-by: Dan McGee --- src/pacman/upgrade.c | 34 +++++++--------------------------- 1 file changed, 7 insertions(+), 27 deletions(-) (limited to 'src/pacman/upgrade.c') diff --git a/src/pacman/upgrade.c b/src/pacman/upgrade.c index e5626516..589970ed 100644 --- a/src/pacman/upgrade.c +++ b/src/pacman/upgrade.c @@ -28,23 +28,9 @@ /* pacman */ #include "pacman.h" -#include "callback.h" #include "conf.h" #include "util.h" -/* Free the current transaction and print an error if unsuccessful */ -static int upgrade_cleanup(void) -{ - int ret = alpm_trans_release(); - if(ret != 0) { - pm_printf(PM_LOG_ERROR, _("failed to release transaction (%s)\n"), - alpm_strerrorlast()); - ret = 1; - } - - return(ret); -} - /** * @brief Upgrade a specified list of packages. * @@ -78,15 +64,7 @@ int pacman_upgrade(alpm_list_t *targets) } /* Step 1: create a new transaction */ - if(alpm_trans_init(transtype, config->flags, cb_trans_evt, - cb_trans_conv, cb_trans_progress) == -1) { - /* TODO: error messages should be in the front end, not the back */ - fprintf(stderr, _("error: %s\n"), alpm_strerrorlast()); - if(pm_errno == PM_ERR_HANDLE_LOCK) { - /* TODO this and the 2 other places should probably be on stderr */ - printf(_(" if you're sure a package manager is not already\n" - " running, you can remove %s.\n"), alpm_option_get_lockfile()); - } + if(trans_init(transtype, config->flags) == -1) { return(1); } @@ -97,7 +75,7 @@ int pacman_upgrade(alpm_list_t *targets) if(alpm_trans_addtarget(targ) == -1) { fprintf(stderr, _("error: '%s': %s\n"), targ, alpm_strerrorlast()); - upgrade_cleanup(); + trans_release(); return(1); } } @@ -151,7 +129,7 @@ int pacman_upgrade(alpm_list_t *targets) default: break; } - upgrade_cleanup(); + trans_release(); FREELIST(data); return(1); } @@ -160,11 +138,13 @@ int pacman_upgrade(alpm_list_t *targets) /* Step 3: perform the installation */ if(alpm_trans_commit(NULL) == -1) { fprintf(stderr, _("error: failed to commit transaction (%s)\n"), alpm_strerrorlast()); - upgrade_cleanup(); + trans_release(); return(1); } - retval = upgrade_cleanup(); + if(trans_release() == -1) { + retval = 1; + } return(retval); } -- cgit v1.2.3