summaryrefslogtreecommitdiffstats
path: root/src/pacman/add.c
diff options
context:
space:
mode:
authorDan McGee <dan@archlinux.org>2007-06-13 17:33:45 +0200
committerDan McGee <dan@archlinux.org>2007-06-17 19:20:17 +0200
commit2ab320a3885226ce28da0f2f2bc84b5f2d0f0539 (patch)
treedb6997d8dd14026554fbf981cabade0b2bcdd09c /src/pacman/add.c
parent520841ee8a82460e0abb2a9a44c857556604cf56 (diff)
downloadpacman-2ab320a3885226ce28da0f2f2bc84b5f2d0f0539.tar.gz
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/add.c')
-rw-r--r--src/pacman/add.c37
1 files changed, 22 insertions, 15 deletions
diff --git a/src/pacman/add.c b/src/pacman/add.c
index 39da624b..71578f63 100644
--- a/src/pacman/add.c
+++ b/src/pacman/add.c
@@ -36,6 +36,19 @@
extern config_t *config;
+/* Free the current transaction and print an error if unsuccessful */
+static int add_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 Upgrade a specified list of packages.
*
@@ -108,8 +121,8 @@ int pacman_add(alpm_list_t *targets)
if(alpm_trans_addtarget(targ) == -1) {
fprintf(stderr, _("error: failed to add target '%s' (%s)"), targ,
alpm_strerror(pm_errno));
- retval = 1;
- goto cleanup;
+ add_cleanup();
+ return(1);
}
}
printf(_("done.\n"));
@@ -174,26 +187,20 @@ int pacman_add(alpm_list_t *targets)
default:
break;
}
- retval=1;
- goto cleanup;
+ add_cleanup();
+ alpm_list_free(data);
+ return(1);
}
+ alpm_list_free(data);
/* Step 3: perform the installation */
if(alpm_trans_commit(NULL) == -1) {
fprintf(stderr, _("error: failed to commit transaction (%s)\n"), alpm_strerror(pm_errno));
- retval=1;
- goto cleanup;
- }
-
-cleanup:
- if(data) {
- alpm_list_free(data);
- }
- if(alpm_trans_release() == -1) {
- fprintf(stderr, _("error: failed to release transaction (%s)\n"), alpm_strerror(pm_errno));
- retval=1;
+ add_cleanup();
+ return(1);
}
+ retval = add_cleanup();
return(retval);
}