summaryrefslogtreecommitdiff
path: root/src/pacman/upgrade.c
diff options
context:
space:
mode:
authorChantry Xavier <shiningxc@gmail.com>2008-04-26 11:30:49 +0200
committerDan McGee <dan@archlinux.org>2008-04-26 11:15:09 -0500
commitff9744aa1f9d3da380e722fd44a07b8c8a68d101 (patch)
treeb8d65bf6d02688e9a49e712e9a4ffde206502f11 /src/pacman/upgrade.c
parent1b5a851851cce4ae53e82fdec128ff6d6f73393b (diff)
downloadpacman-ff9744aa1f9d3da380e722fd44a07b8c8a68d101.tar.xz
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 <shiningxc@gmail.com> Signed-off-by: Dan McGee <dan@archlinux.org>
Diffstat (limited to 'src/pacman/upgrade.c')
-rw-r--r--src/pacman/upgrade.c34
1 files changed, 7 insertions, 27 deletions
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);
}