diff options
author | Dan McGee <dan@archlinux.org> | 2007-06-13 11:33:45 -0400 |
---|---|---|
committer | Dan McGee <dan@archlinux.org> | 2007-06-17 13:20:17 -0400 |
commit | 2ab320a3885226ce28da0f2f2bc84b5f2d0f0539 (patch) | |
tree | db6997d8dd14026554fbf981cabade0b2bcdd09c /src/pacman/remove.c | |
parent | 520841ee8a82460e0abb2a9a44c857556604cf56 (diff) | |
download | pacman-2ab320a3885226ce28da0f2f2bc84b5f2d0f0539.tar.xz |
Remove some use of goto in the pacman frontend
Refactor the goto cleanup; statements out of add.c and remove.c, and move
what the cleanup: label did into a function.
Signed-off-by: Dan McGee <dan@archlinux.org>
Diffstat (limited to 'src/pacman/remove.c')
-rw-r--r-- | src/pacman/remove.c | 41 |
1 files changed, 26 insertions, 15 deletions
diff --git a/src/pacman/remove.c b/src/pacman/remove.c index aa9ae5da..0b6b4ce2 100644 --- a/src/pacman/remove.c +++ b/src/pacman/remove.c @@ -38,6 +38,19 @@ extern config_t *config; 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_strerror(pm_errno)); + ret = 1; + } + + return(ret); +} + /** * @brief Remove a specified list of packages. * @@ -101,8 +114,9 @@ int pacman_remove(alpm_list_t *targets) printf("failed.\n"); fprintf(stderr, _("error: failed to add target '%s' (%s)\n"), targ, alpm_strerror(pm_errno)); - retval = 1; - goto cleanup; + remove_cleanup(); + FREELIST(finaltargs); + return(1); } } @@ -122,8 +136,9 @@ int pacman_remove(alpm_list_t *targets) default: break; } - retval = 1; - goto cleanup; + remove_cleanup(); + FREELIST(finaltargs); + return(1); } /* Warn user in case of dangerous operation */ @@ -141,8 +156,9 @@ int pacman_remove(alpm_list_t *targets) FREELIST(lst); /* get confirmation */ if(yesno(_("\nDo you want to remove these packages? [Y/n] ")) == 0) { - retval = 1; - goto cleanup; + remove_cleanup(); + FREELIST(finaltargs); + return(1); } printf("\n"); } @@ -151,19 +167,14 @@ int pacman_remove(alpm_list_t *targets) if(alpm_trans_commit(NULL) == -1) { fprintf(stderr, _("error: failed to commit transaction (%s)\n"), alpm_strerror(pm_errno)); - retval = 1; - goto cleanup; + remove_cleanup(); + FREELIST(finaltargs); + return(1); } /* Step 4: release transaction resources */ -cleanup: + retval = remove_cleanup(); FREELIST(finaltargs); - if(alpm_trans_release() == -1) { - fprintf(stderr, _("error: failed to release transaction (%s)\n"), - alpm_strerror(pm_errno)); - retval = 1; - } - return(retval); } |