summaryrefslogtreecommitdiffstats
path: root/src/pacman/util.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 18:15:09 +0200
commitff9744aa1f9d3da380e722fd44a07b8c8a68d101 (patch)
treeb8d65bf6d02688e9a49e712e9a4ffde206502f11 /src/pacman/util.c
parent1b5a851851cce4ae53e82fdec128ff6d6f73393b (diff)
downloadpacman-ff9744aa1f9d3da380e722fd44a07b8c8a68d101.tar.gz
pacman-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/util.c')
-rw-r--r--src/pacman/util.c27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/pacman/util.c b/src/pacman/util.c
index ed7669a3..d932b441 100644
--- a/src/pacman/util.c
+++ b/src/pacman/util.c
@@ -42,6 +42,33 @@
/* pacman */
#include "util.h"
#include "conf.h"
+#include "callback.h"
+
+
+int trans_init(pmtranstype_t type, pmtransflag_t flags)
+{
+ if(alpm_trans_init(type, flags, cb_trans_evt,
+ cb_trans_conv, cb_trans_progress) == -1) {
+ fprintf(stderr, _("error: failed to init transaction (%s)\n"),
+ alpm_strerrorlast());
+ if(pm_errno == PM_ERR_HANDLE_LOCK) {
+ fprintf(stderr, _(" if you're sure a package manager is not already\n"
+ " running, you can remove %s\n"), alpm_option_get_lockfile());
+ }
+ return(-1);
+ }
+ return(0);
+}
+
+int trans_release()
+{
+ if(alpm_trans_release() == -1) {
+ fprintf(stderr, _("error: failed to release transaction (%s)\n"),
+ alpm_strerrorlast());
+ return(-1);
+ }
+ return(0);
+}
int needs_transaction()
{