diff options
author | Chantry Xavier <shiningxc@gmail.com> | 2008-04-26 11:30:49 +0200 |
---|---|---|
committer | Dan McGee <dan@archlinux.org> | 2008-04-26 18:15:09 +0200 |
commit | ff9744aa1f9d3da380e722fd44a07b8c8a68d101 (patch) | |
tree | b8d65bf6d02688e9a49e712e9a4ffde206502f11 /src/pacman/sync.c | |
parent | 1b5a851851cce4ae53e82fdec128ff6d6f73393b (diff) | |
download | pacman-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/sync.c')
-rw-r--r-- | src/pacman/sync.c | 39 |
1 files changed, 8 insertions, 31 deletions
diff --git a/src/pacman/sync.c b/src/pacman/sync.c index c074746f..77b66da5 100644 --- a/src/pacman/sync.c +++ b/src/pacman/sync.c @@ -34,7 +34,6 @@ #include "pacman.h" #include "util.h" #include "package.h" -#include "callback.h" #include "conf.h" extern pmdb_t *db_local; @@ -235,34 +234,12 @@ 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; int success = 0, ret; - if(sync_trans_init(0) == -1) { + if(trans_init(PM_TRANS_TYPE_SYNC, 0) == -1) { return(0); } @@ -281,7 +258,7 @@ static int sync_synctree(int level, alpm_list_t *syncs) } } - if(sync_trans_release() == -1) { + if(trans_release() == -1) { return(0); } /* We should always succeed if at least one DB was upgraded - we may possibly @@ -552,7 +529,7 @@ static int sync_trans(alpm_list_t *targets) alpm_list_t *sync_dbs = alpm_option_get_syncdbs(); /* Step 1: create a new transaction... */ - if(sync_trans_init(config->flags) == -1) { + if(trans_init(PM_TRANS_TYPE_SYNC, config->flags) == -1) { return(1); } @@ -583,10 +560,10 @@ static int sync_trans(alpm_list_t *targets) printf(_(":: pacman has detected a newer version of itself.\n")); if(yesno(1, _(":: Do you want to cancel the current operation\n" ":: and install the new pacman version now?"))) { - if(sync_trans_release() == -1) { + if(trans_release() == -1) { return(1); } - if(sync_trans_init(0) == -1) { + if(trans_init(PM_TRANS_TYPE_SYNC, 0) == -1) { return(1); } if(alpm_trans_addtarget("pacman") == -1) { @@ -788,7 +765,7 @@ cleanup: if(data) { FREELIST(data); } - if(sync_trans_release() == -1) { + if(trans_release() == -1) { retval = 1; } @@ -803,14 +780,14 @@ int pacman_sync(alpm_list_t *targets) if(config->op_s_clean) { int ret = 0; - if(sync_trans_init(0) == -1) { + if(trans_init(PM_TRANS_TYPE_SYNC, 0) == -1) { return(1); } ret += sync_cleancache(config->op_s_clean); ret += sync_cleandb_all(); - if(sync_trans_release() == -1) { + if(trans_release() == -1) { ret++; } |