mirror of
https://github.com/moparisthebest/pacman
synced 2025-02-28 09:21:53 -05:00
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>
This commit is contained in:
parent
520841ee8a
commit
2ab320a388
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user