needs_transaction adjustments
I just moved the root path check out of needs_transaction, and put it directly in pacman.c . I think this part is alright. For the other problems, I thought about doing the transaction first, in a new sync trans function, which will init and release a transaction. And then doing the commands like -Ss / -Sl / -Sg / -Si. The problem is that for commands like -Sys / -Syl / etc, only the refresh part of the transaction should be done. So I had to introduce an ugly sync_only hack. Signed-off-by: Aaron Griffin <aaronmgriffin@gmail.com>
This commit is contained in:
parent
4453ce155c
commit
52e7e6d747
3 changed files with 69 additions and 55 deletions
|
@ -775,7 +775,9 @@ int main(int argc, char *argv[])
|
||||||
|
|
||||||
#if defined(HAVE_GETEUID)
|
#if defined(HAVE_GETEUID)
|
||||||
/* check if we have sufficient permission for the requested operation */
|
/* check if we have sufficient permission for the requested operation */
|
||||||
if(myuid > 0 && needs_transaction()) {
|
if(myuid > 0 && !strcmp(alpm_option_get_root(), "/") && needs_transaction()) {
|
||||||
|
/* special case: ignore root user check if -r is specified, fall back on
|
||||||
|
* normal FS checking */
|
||||||
pm_printf(PM_LOG_ERROR, _("you cannot perform this operation unless you are root.\n"));
|
pm_printf(PM_LOG_ERROR, _("you cannot perform this operation unless you are root.\n"));
|
||||||
cleanup(EXIT_FAILURE);
|
cleanup(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
|
@ -390,33 +390,14 @@ static int sync_list(alpm_list_t *syncs, alpm_list_t *targets)
|
||||||
return(0);
|
return(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
int pacman_sync(alpm_list_t *targets)
|
int sync_trans(alpm_list_t *targets, int sync_only)
|
||||||
{
|
{
|
||||||
int retval = 0;
|
int retval = 0;
|
||||||
alpm_list_t *sync_dbs = NULL;
|
alpm_list_t *data = NULL;
|
||||||
|
alpm_list_t *sync_dbs = alpm_option_get_syncdbs();
|
||||||
/* clean the cache */
|
|
||||||
if(config->op_s_clean) {
|
|
||||||
return(sync_cleancache(config->op_s_clean));
|
|
||||||
}
|
|
||||||
|
|
||||||
/* ensure we have at least one valid sync db set up */
|
|
||||||
sync_dbs = alpm_option_get_syncdbs();
|
|
||||||
if(sync_dbs == NULL || alpm_list_count(sync_dbs) == 0) {
|
|
||||||
pm_printf(PM_LOG_ERROR, _("no usable package repositories configured.\n"));
|
|
||||||
return(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* don't proceed here unless we have an operation that doesn't require
|
|
||||||
* a target list */
|
|
||||||
if(targets == NULL && !(config->op_s_sync || config->op_s_upgrade)) {
|
|
||||||
pm_printf(PM_LOG_ERROR, _("no targets specified (use -h for help)\n"));
|
|
||||||
return(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Step 1: create a new transaction... */
|
/* Step 1: create a new transaction... */
|
||||||
if(needs_transaction() &&
|
if(alpm_trans_init(PM_TRANS_TYPE_SYNC, config->flags, cb_trans_evt,
|
||||||
alpm_trans_init(PM_TRANS_TYPE_SYNC, config->flags, cb_trans_evt,
|
|
||||||
cb_trans_conv, cb_trans_progress) == -1) {
|
cb_trans_conv, cb_trans_progress) == -1) {
|
||||||
fprintf(stderr, _("error: failed to init transaction (%s)\n"),
|
fprintf(stderr, _("error: failed to init transaction (%s)\n"),
|
||||||
alpm_strerrorlast());
|
alpm_strerrorlast());
|
||||||
|
@ -435,30 +416,9 @@ int pacman_sync(alpm_list_t *targets)
|
||||||
fprintf(stderr, _("error: failed to synchronize any databases\n"));
|
fprintf(stderr, _("error: failed to synchronize any databases\n"));
|
||||||
return(1);
|
return(1);
|
||||||
}
|
}
|
||||||
}
|
if(sync_only) {
|
||||||
|
|
||||||
/* search for a package */
|
|
||||||
if(config->op_s_search) {
|
|
||||||
retval = sync_search(sync_dbs, targets);
|
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* look for groups */
|
|
||||||
if(config->group) {
|
|
||||||
retval = sync_group(config->group, sync_dbs, targets);
|
|
||||||
goto cleanup;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* get package info */
|
|
||||||
if(config->op_s_info) {
|
|
||||||
retval = sync_info(sync_dbs, targets);
|
|
||||||
goto cleanup;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* get a listing of files in sync DBs */
|
|
||||||
if(config->op_q_list) {
|
|
||||||
retval = sync_list(sync_dbs, targets);
|
|
||||||
goto cleanup;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(config->op_s_upgrade) {
|
if(config->op_s_upgrade) {
|
||||||
|
@ -535,7 +495,7 @@ int pacman_sync(alpm_list_t *targets)
|
||||||
}
|
}
|
||||||
/* target not found: check if it's a group */
|
/* target not found: check if it's a group */
|
||||||
|
|
||||||
for(j = alpm_option_get_syncdbs(); j; j = alpm_list_next(j)) {
|
for(j = sync_dbs; j; j = alpm_list_next(j)) {
|
||||||
pmdb_t *db = alpm_list_getdata(j);
|
pmdb_t *db = alpm_list_getdata(j);
|
||||||
grp = alpm_db_readgrp(db, targ);
|
grp = alpm_db_readgrp(db, targ);
|
||||||
if(grp) {
|
if(grp) {
|
||||||
|
@ -565,7 +525,7 @@ int pacman_sync(alpm_list_t *targets)
|
||||||
if(!found) {
|
if(!found) {
|
||||||
/* targ not found in sync db, searching for providers... */
|
/* targ not found in sync db, searching for providers... */
|
||||||
const char *pname = NULL;
|
const char *pname = NULL;
|
||||||
for(j = alpm_option_get_syncdbs(); j; j = alpm_list_next(j)) {
|
for(j = sync_dbs; j; j = alpm_list_next(j)) {
|
||||||
pmdb_t *db = alpm_list_getdata(j);
|
pmdb_t *db = alpm_list_getdata(j);
|
||||||
alpm_list_t *prov = alpm_db_whatprovides(db, targ);
|
alpm_list_t *prov = alpm_db_whatprovides(db, targ);
|
||||||
if(prov) {
|
if(prov) {
|
||||||
|
@ -588,7 +548,6 @@ int pacman_sync(alpm_list_t *targets)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Step 2: "compute" the transaction based on targets and flags */
|
/* Step 2: "compute" the transaction based on targets and flags */
|
||||||
alpm_list_t *data;
|
|
||||||
if(alpm_trans_prepare(&data) == -1) {
|
if(alpm_trans_prepare(&data) == -1) {
|
||||||
fprintf(stderr, _("error: failed to prepare transaction (%s)\n"),
|
fprintf(stderr, _("error: failed to prepare transaction (%s)\n"),
|
||||||
alpm_strerrorlast());
|
alpm_strerrorlast());
|
||||||
|
@ -716,4 +675,60 @@ cleanup:
|
||||||
return(retval);
|
return(retval);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int pacman_sync(alpm_list_t *targets)
|
||||||
|
{
|
||||||
|
alpm_list_t *sync_dbs = NULL;
|
||||||
|
int sync_only = 0;
|
||||||
|
|
||||||
|
/* clean the cache */
|
||||||
|
if(config->op_s_clean) {
|
||||||
|
return(sync_cleancache(config->op_s_clean));
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ensure we have at least one valid sync db set up */
|
||||||
|
sync_dbs = alpm_option_get_syncdbs();
|
||||||
|
if(sync_dbs == NULL || alpm_list_count(sync_dbs) == 0) {
|
||||||
|
pm_printf(PM_LOG_ERROR, _("no usable package repositories configured.\n"));
|
||||||
|
return(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(config->op_s_search || config->group
|
||||||
|
|| config->op_s_info || config->op_q_list) {
|
||||||
|
sync_only = 1;
|
||||||
|
} else if(targets == NULL && !(config->op_s_sync || config->op_s_upgrade)) {
|
||||||
|
/* don't proceed here unless we have an operation that doesn't require
|
||||||
|
* a target list */
|
||||||
|
pm_printf(PM_LOG_ERROR, _("no targets specified (use -h for help)\n"));
|
||||||
|
return(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(needs_transaction()) {
|
||||||
|
if(sync_trans(targets, sync_only) == 1) {
|
||||||
|
return(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* search for a package */
|
||||||
|
if(config->op_s_search) {
|
||||||
|
return(sync_search(sync_dbs, targets));
|
||||||
|
}
|
||||||
|
|
||||||
|
/* look for groups */
|
||||||
|
if(config->group) {
|
||||||
|
return(sync_group(config->group, sync_dbs, targets));
|
||||||
|
}
|
||||||
|
|
||||||
|
/* get package info */
|
||||||
|
if(config->op_s_info) {
|
||||||
|
return(sync_info(sync_dbs, targets));
|
||||||
|
}
|
||||||
|
|
||||||
|
/* get a listing of files in sync DBs */
|
||||||
|
if(config->op_q_list) {
|
||||||
|
return(sync_list(sync_dbs, targets));
|
||||||
|
}
|
||||||
|
|
||||||
|
return(0);
|
||||||
|
}
|
||||||
|
|
||||||
/* vim: set ts=2 sw=2 noet: */
|
/* vim: set ts=2 sw=2 noet: */
|
||||||
|
|
|
@ -51,11 +51,8 @@ int needs_transaction()
|
||||||
if((config->op == PM_OP_SYNC && !config->op_s_sync &&
|
if((config->op == PM_OP_SYNC && !config->op_s_sync &&
|
||||||
(config->op_s_search || config->group || config->op_q_list || config->op_q_info
|
(config->op_s_search || config->group || config->op_q_list || config->op_q_info
|
||||||
|| config->flags & PM_TRANS_FLAG_PRINTURIS))
|
|| config->flags & PM_TRANS_FLAG_PRINTURIS))
|
||||||
|| config->op == PM_OP_DEPTEST
|
|| config->op == PM_OP_DEPTEST) {
|
||||||
|| (strcmp(alpm_option_get_root(), "/") != 0)) {
|
|
||||||
/* special case: PM_OP_SYNC can be used w/ config->op_s_search by any user */
|
/* special case: PM_OP_SYNC can be used w/ config->op_s_search by any user */
|
||||||
/* special case: ignore root user check if -r is specified, fall back on
|
|
||||||
* normal FS checking */
|
|
||||||
return(0);
|
return(0);
|
||||||
} else {
|
} else {
|
||||||
return(1);
|
return(1);
|
||||||
|
|
Loading…
Add table
Reference in a new issue