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/remove.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/remove.c')
-rw-r--r-- | src/pacman/remove.c | 35 |
1 files changed, 8 insertions, 27 deletions
diff --git a/src/pacman/remove.c b/src/pacman/remove.c index 2fb69d35..a2209ac6 100644 --- a/src/pacman/remove.c +++ b/src/pacman/remove.c @@ -29,24 +29,10 @@ /* pacman */ #include "pacman.h" #include "util.h" -#include "callback.h" #include "conf.h" extern pmdb_t *db_local; -/* Free the current transaction and print an error if unsuccessful */ -static int remove_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 Remove a specified list of packages. * @@ -90,14 +76,7 @@ int pacman_remove(alpm_list_t *targets) } /* Step 1: create a new transaction */ - if(alpm_trans_init(PM_TRANS_TYPE_REMOVE, 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(trans_init(PM_TRANS_TYPE_REMOVE, config->flags) == -1) { FREELIST(finaltargs); return(1); } @@ -109,7 +88,7 @@ int pacman_remove(alpm_list_t *targets) if(alpm_trans_addtarget(targ) == -1) { fprintf(stderr, _("error: '%s': %s\n"), targ, alpm_strerrorlast()); - remove_cleanup(); + trans_release(); FREELIST(finaltargs); return(1); } @@ -134,7 +113,7 @@ int pacman_remove(alpm_list_t *targets) default: break; } - remove_cleanup(); + trans_release(); FREELIST(finaltargs); return(1); } @@ -154,7 +133,7 @@ int pacman_remove(alpm_list_t *targets) FREELIST(lst); /* get confirmation */ if(yesno(1, _("\nDo you want to remove these packages?")) == 0) { - remove_cleanup(); + trans_release(); FREELIST(finaltargs); return(1); } @@ -165,13 +144,15 @@ int pacman_remove(alpm_list_t *targets) if(alpm_trans_commit(NULL) == -1) { fprintf(stderr, _("error: failed to commit transaction (%s)\n"), alpm_strerrorlast()); - remove_cleanup(); + trans_release(); FREELIST(finaltargs); return(1); } /* Step 4: release transaction resources */ - retval = remove_cleanup(); + if(trans_release() == -1) { + retval = 1; + } FREELIST(finaltargs); return(retval); } |