summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChantry Xavier <shiningxc@gmail.com>2008-02-19 20:32:48 +0100
committerDan McGee <dan@archlinux.org>2008-02-20 05:07:44 +0100
commit6f3949e3da4325f61ac53d7c8b86a18ff6acb64e (patch)
treef310557e5a21d43189da69783e72fd4140cf0d31
parent2b3a85dc4a1d8855449ae979713fda0b8cbc7580 (diff)
downloadpacman-6f3949e3da4325f61ac53d7c8b86a18ff6acb64e.tar.gz
pacman-6f3949e3da4325f61ac53d7c8b86a18ff6acb64e.tar.xz
Add new sync_trans_init and sync_trans_release.
Factorize these two functions to avoid code duplication, especially since they could be used for locking the database during -Sc and -Sy operation too. Signed-off-by: Chantry Xavier <shiningxc@gmail.com>
-rw-r--r--src/pacman/sync.c50
1 files changed, 28 insertions, 22 deletions
diff --git a/src/pacman/sync.c b/src/pacman/sync.c
index 244fedce..5f83c753 100644
--- a/src/pacman/sync.c
+++ b/src/pacman/sync.c
@@ -205,6 +205,28 @@ static int sync_cleancache(int level)
return(0);
}
+static int sync_trans_init(pmtransflag_t flags) {
+ if(alpm_trans_init(PM_TRANS_TYPE_SYNC, 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) {
+ printf(_(" 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);
+}
+
+static int sync_trans_release() {
+ if(alpm_trans_release() == -1) {
+ fprintf(stderr, _("error: failed to release transaction (%s)\n"),
+ alpm_strerrorlast());
+ return(-1);
+ }
+ return(0);
+}
static int sync_synctree(int level, alpm_list_t *syncs)
{
alpm_list_t *i;
@@ -484,14 +506,7 @@ static int sync_trans(alpm_list_t *targets, int sync_only)
alpm_list_t *sync_dbs = alpm_option_get_syncdbs();
/* Step 1: create a new transaction... */
- if(alpm_trans_init(PM_TRANS_TYPE_SYNC, config->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) {
- printf(_(" if you're sure a package manager is not already\n"
- " running, you can remove %s.\n"), alpm_option_get_lockfile());
- }
+ if(sync_trans_init(config->flags) == -1) {
return(1);
}
@@ -537,22 +552,15 @@ static int sync_trans(alpm_list_t *targets, int sync_only)
printf(_(":: pacman has detected a newer version of itself.\n"));
if(yesno(_(":: Do you want to cancel the current operation\n"
":: and install the new pacman version now? [Y/n] "))) {
- if(alpm_trans_release() == -1) {
- fprintf(stderr, _("error: failed to release transaction (%s)\n"),
- alpm_strerrorlast());
- retval = 1;
- goto cleanup;
+ if(sync_trans_release() == -1) {
+ return(1);
}
- if(alpm_trans_init(PM_TRANS_TYPE_SYNC, config->flags,
- cb_trans_evt, cb_trans_conv, cb_trans_progress) == -1) {
- fprintf(stderr, _("error: failed to init transaction (%s)\n"),
- alpm_strerrorlast());
+ if(sync_trans_init(0) == -1) {
return(1);
}
if(alpm_trans_addtarget("pacman") == -1) {
fprintf(stderr, _("error: pacman: %s\n"), alpm_strerrorlast());
- retval = 1;
- goto cleanup;
+ return(1);
}
break;
}
@@ -752,9 +760,7 @@ cleanup:
if(data) {
FREELIST(data);
}
- if(alpm_trans_release() == -1) {
- fprintf(stderr, _("error: failed to release transaction (%s)\n"),
- alpm_strerrorlast());
+ if(sync_trans_release() == -1) {
retval = 1;
}