mirror of
https://github.com/moparisthebest/pacman
synced 2024-12-23 08:18:51 -05:00
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>
This commit is contained in:
parent
1b5a851851
commit
ff9744aa1f
@ -29,24 +29,10 @@
|
|||||||
/* pacman */
|
/* pacman */
|
||||||
#include "pacman.h"
|
#include "pacman.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
#include "callback.h"
|
|
||||||
#include "conf.h"
|
#include "conf.h"
|
||||||
|
|
||||||
extern pmdb_t *db_local;
|
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.
|
* @brief Remove a specified list of packages.
|
||||||
*
|
*
|
||||||
@ -90,14 +76,7 @@ int pacman_remove(alpm_list_t *targets)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Step 1: create a new transaction */
|
/* Step 1: create a new transaction */
|
||||||
if(alpm_trans_init(PM_TRANS_TYPE_REMOVE, config->flags,
|
if(trans_init(PM_TRANS_TYPE_REMOVE, config->flags) == -1) {
|
||||||
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());
|
|
||||||
}
|
|
||||||
FREELIST(finaltargs);
|
FREELIST(finaltargs);
|
||||||
return(1);
|
return(1);
|
||||||
}
|
}
|
||||||
@ -109,7 +88,7 @@ int pacman_remove(alpm_list_t *targets)
|
|||||||
if(alpm_trans_addtarget(targ) == -1) {
|
if(alpm_trans_addtarget(targ) == -1) {
|
||||||
fprintf(stderr, _("error: '%s': %s\n"),
|
fprintf(stderr, _("error: '%s': %s\n"),
|
||||||
targ, alpm_strerrorlast());
|
targ, alpm_strerrorlast());
|
||||||
remove_cleanup();
|
trans_release();
|
||||||
FREELIST(finaltargs);
|
FREELIST(finaltargs);
|
||||||
return(1);
|
return(1);
|
||||||
}
|
}
|
||||||
@ -134,7 +113,7 @@ int pacman_remove(alpm_list_t *targets)
|
|||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
remove_cleanup();
|
trans_release();
|
||||||
FREELIST(finaltargs);
|
FREELIST(finaltargs);
|
||||||
return(1);
|
return(1);
|
||||||
}
|
}
|
||||||
@ -154,7 +133,7 @@ int pacman_remove(alpm_list_t *targets)
|
|||||||
FREELIST(lst);
|
FREELIST(lst);
|
||||||
/* get confirmation */
|
/* get confirmation */
|
||||||
if(yesno(1, _("\nDo you want to remove these packages?")) == 0) {
|
if(yesno(1, _("\nDo you want to remove these packages?")) == 0) {
|
||||||
remove_cleanup();
|
trans_release();
|
||||||
FREELIST(finaltargs);
|
FREELIST(finaltargs);
|
||||||
return(1);
|
return(1);
|
||||||
}
|
}
|
||||||
@ -165,13 +144,15 @@ int pacman_remove(alpm_list_t *targets)
|
|||||||
if(alpm_trans_commit(NULL) == -1) {
|
if(alpm_trans_commit(NULL) == -1) {
|
||||||
fprintf(stderr, _("error: failed to commit transaction (%s)\n"),
|
fprintf(stderr, _("error: failed to commit transaction (%s)\n"),
|
||||||
alpm_strerrorlast());
|
alpm_strerrorlast());
|
||||||
remove_cleanup();
|
trans_release();
|
||||||
FREELIST(finaltargs);
|
FREELIST(finaltargs);
|
||||||
return(1);
|
return(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Step 4: release transaction resources */
|
/* Step 4: release transaction resources */
|
||||||
retval = remove_cleanup();
|
if(trans_release() == -1) {
|
||||||
|
retval = 1;
|
||||||
|
}
|
||||||
FREELIST(finaltargs);
|
FREELIST(finaltargs);
|
||||||
return(retval);
|
return(retval);
|
||||||
}
|
}
|
||||||
|
@ -34,7 +34,6 @@
|
|||||||
#include "pacman.h"
|
#include "pacman.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
#include "package.h"
|
#include "package.h"
|
||||||
#include "callback.h"
|
|
||||||
#include "conf.h"
|
#include "conf.h"
|
||||||
|
|
||||||
extern pmdb_t *db_local;
|
extern pmdb_t *db_local;
|
||||||
@ -235,34 +234,12 @@ static int sync_cleancache(int level)
|
|||||||
return(0);
|
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)
|
static int sync_synctree(int level, alpm_list_t *syncs)
|
||||||
{
|
{
|
||||||
alpm_list_t *i;
|
alpm_list_t *i;
|
||||||
int success = 0, ret;
|
int success = 0, ret;
|
||||||
|
|
||||||
if(sync_trans_init(0) == -1) {
|
if(trans_init(PM_TRANS_TYPE_SYNC, 0) == -1) {
|
||||||
return(0);
|
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);
|
return(0);
|
||||||
}
|
}
|
||||||
/* We should always succeed if at least one DB was upgraded - we may possibly
|
/* 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();
|
alpm_list_t *sync_dbs = alpm_option_get_syncdbs();
|
||||||
|
|
||||||
/* Step 1: create a new transaction... */
|
/* 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);
|
return(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -583,10 +560,10 @@ static int sync_trans(alpm_list_t *targets)
|
|||||||
printf(_(":: pacman has detected a newer version of itself.\n"));
|
printf(_(":: pacman has detected a newer version of itself.\n"));
|
||||||
if(yesno(1, _(":: Do you want to cancel the current operation\n"
|
if(yesno(1, _(":: Do you want to cancel the current operation\n"
|
||||||
":: and install the new pacman version now?"))) {
|
":: and install the new pacman version now?"))) {
|
||||||
if(sync_trans_release() == -1) {
|
if(trans_release() == -1) {
|
||||||
return(1);
|
return(1);
|
||||||
}
|
}
|
||||||
if(sync_trans_init(0) == -1) {
|
if(trans_init(PM_TRANS_TYPE_SYNC, 0) == -1) {
|
||||||
return(1);
|
return(1);
|
||||||
}
|
}
|
||||||
if(alpm_trans_addtarget("pacman") == -1) {
|
if(alpm_trans_addtarget("pacman") == -1) {
|
||||||
@ -788,7 +765,7 @@ cleanup:
|
|||||||
if(data) {
|
if(data) {
|
||||||
FREELIST(data);
|
FREELIST(data);
|
||||||
}
|
}
|
||||||
if(sync_trans_release() == -1) {
|
if(trans_release() == -1) {
|
||||||
retval = 1;
|
retval = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -803,14 +780,14 @@ int pacman_sync(alpm_list_t *targets)
|
|||||||
if(config->op_s_clean) {
|
if(config->op_s_clean) {
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
|
|
||||||
if(sync_trans_init(0) == -1) {
|
if(trans_init(PM_TRANS_TYPE_SYNC, 0) == -1) {
|
||||||
return(1);
|
return(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
ret += sync_cleancache(config->op_s_clean);
|
ret += sync_cleancache(config->op_s_clean);
|
||||||
ret += sync_cleandb_all();
|
ret += sync_cleandb_all();
|
||||||
|
|
||||||
if(sync_trans_release() == -1) {
|
if(trans_release() == -1) {
|
||||||
ret++;
|
ret++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -28,23 +28,9 @@
|
|||||||
|
|
||||||
/* pacman */
|
/* pacman */
|
||||||
#include "pacman.h"
|
#include "pacman.h"
|
||||||
#include "callback.h"
|
|
||||||
#include "conf.h"
|
#include "conf.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
|
||||||
/* Free the current transaction and print an error if unsuccessful */
|
|
||||||
static int upgrade_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 Upgrade a specified list of packages.
|
* @brief Upgrade a specified list of packages.
|
||||||
*
|
*
|
||||||
@ -78,15 +64,7 @@ int pacman_upgrade(alpm_list_t *targets)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Step 1: create a new transaction */
|
/* Step 1: create a new transaction */
|
||||||
if(alpm_trans_init(transtype, config->flags, cb_trans_evt,
|
if(trans_init(transtype, config->flags) == -1) {
|
||||||
cb_trans_conv, cb_trans_progress) == -1) {
|
|
||||||
/* TODO: error messages should be in the front end, not the back */
|
|
||||||
fprintf(stderr, _("error: %s\n"), alpm_strerrorlast());
|
|
||||||
if(pm_errno == PM_ERR_HANDLE_LOCK) {
|
|
||||||
/* TODO this and the 2 other places should probably be on stderr */
|
|
||||||
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(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -97,7 +75,7 @@ int pacman_upgrade(alpm_list_t *targets)
|
|||||||
if(alpm_trans_addtarget(targ) == -1) {
|
if(alpm_trans_addtarget(targ) == -1) {
|
||||||
fprintf(stderr, _("error: '%s': %s\n"),
|
fprintf(stderr, _("error: '%s': %s\n"),
|
||||||
targ, alpm_strerrorlast());
|
targ, alpm_strerrorlast());
|
||||||
upgrade_cleanup();
|
trans_release();
|
||||||
return(1);
|
return(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -151,7 +129,7 @@ int pacman_upgrade(alpm_list_t *targets)
|
|||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
upgrade_cleanup();
|
trans_release();
|
||||||
FREELIST(data);
|
FREELIST(data);
|
||||||
return(1);
|
return(1);
|
||||||
}
|
}
|
||||||
@ -160,11 +138,13 @@ int pacman_upgrade(alpm_list_t *targets)
|
|||||||
/* Step 3: perform the installation */
|
/* Step 3: perform the installation */
|
||||||
if(alpm_trans_commit(NULL) == -1) {
|
if(alpm_trans_commit(NULL) == -1) {
|
||||||
fprintf(stderr, _("error: failed to commit transaction (%s)\n"), alpm_strerrorlast());
|
fprintf(stderr, _("error: failed to commit transaction (%s)\n"), alpm_strerrorlast());
|
||||||
upgrade_cleanup();
|
trans_release();
|
||||||
return(1);
|
return(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
retval = upgrade_cleanup();
|
if(trans_release() == -1) {
|
||||||
|
retval = 1;
|
||||||
|
}
|
||||||
return(retval);
|
return(retval);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -42,6 +42,33 @@
|
|||||||
/* pacman */
|
/* pacman */
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
#include "conf.h"
|
#include "conf.h"
|
||||||
|
#include "callback.h"
|
||||||
|
|
||||||
|
|
||||||
|
int trans_init(pmtranstype_t type, pmtransflag_t flags)
|
||||||
|
{
|
||||||
|
if(alpm_trans_init(type, 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) {
|
||||||
|
fprintf(stderr, _(" 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);
|
||||||
|
}
|
||||||
|
|
||||||
|
int trans_release()
|
||||||
|
{
|
||||||
|
if(alpm_trans_release() == -1) {
|
||||||
|
fprintf(stderr, _("error: failed to release transaction (%s)\n"),
|
||||||
|
alpm_strerrorlast());
|
||||||
|
return(-1);
|
||||||
|
}
|
||||||
|
return(0);
|
||||||
|
}
|
||||||
|
|
||||||
int needs_transaction()
|
int needs_transaction()
|
||||||
{
|
{
|
||||||
|
@ -36,6 +36,8 @@
|
|||||||
/* update speed for the fill_progress based functions */
|
/* update speed for the fill_progress based functions */
|
||||||
#define UPDATE_SPEED_SEC 0.2f
|
#define UPDATE_SPEED_SEC 0.2f
|
||||||
|
|
||||||
|
int trans_init(pmtranstype_t type, pmtransflag_t flags);
|
||||||
|
int trans_release();
|
||||||
int needs_transaction();
|
int needs_transaction();
|
||||||
int getcols();
|
int getcols();
|
||||||
int makepath(const char *path);
|
int makepath(const char *path);
|
||||||
|
Loading…
Reference in New Issue
Block a user