summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorChantry Xavier <shiningxc@gmail.com>2007-10-03 21:02:36 -0500
committerAaron Griffin <aaronmgriffin@gmail.com>2007-10-03 21:02:36 -0500
commit52e7e6d74733f7a431376a9e528c4fe4d3732068 (patch)
treee21405be433b04b9280c1abf4836e98cab603d14 /src
parent4453ce155c2f2c5d48e45269250ac0bab52ac63f (diff)
downloadpacman-52e7e6d74733f7a431376a9e528c4fe4d3732068.tar.xz
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>
Diffstat (limited to 'src')
-rw-r--r--src/pacman/pacman.c4
-rw-r--r--src/pacman/sync.c115
-rw-r--r--src/pacman/util.c5
3 files changed, 69 insertions, 55 deletions
diff --git a/src/pacman/pacman.c b/src/pacman/pacman.c
index c57d3464..74493986 100644
--- a/src/pacman/pacman.c
+++ b/src/pacman/pacman.c
@@ -775,7 +775,9 @@ int main(int argc, char *argv[])
#if defined(HAVE_GETEUID)
/* 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"));
cleanup(EXIT_FAILURE);
}
diff --git a/src/pacman/sync.c b/src/pacman/sync.c
index 0d10d70a..78ce9b71 100644
--- a/src/pacman/sync.c
+++ b/src/pacman/sync.c
@@ -390,33 +390,14 @@ static int sync_list(alpm_list_t *syncs, alpm_list_t *targets)
return(0);
}
-int pacman_sync(alpm_list_t *targets)
+int sync_trans(alpm_list_t *targets, int sync_only)
{
int retval = 0;
- alpm_list_t *sync_dbs = NULL;
-
- /* 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);
- }
+ alpm_list_t *data = NULL;
+ alpm_list_t *sync_dbs = alpm_option_get_syncdbs();
/* Step 1: create a new transaction... */
- if(needs_transaction() &&
- alpm_trans_init(PM_TRANS_TYPE_SYNC, config->flags, cb_trans_evt,
+ if(alpm_trans_init(PM_TRANS_TYPE_SYNC, config->flags, cb_trans_evt,
cb_trans_conv, cb_trans_progress) == -1) {
fprintf(stderr, _("error: failed to init transaction (%s)\n"),
alpm_strerrorlast());
@@ -435,30 +416,9 @@ int pacman_sync(alpm_list_t *targets)
fprintf(stderr, _("error: failed to synchronize any databases\n"));
return(1);
}
- }
-
- /* search for a package */
- if(config->op_s_search) {
- retval = sync_search(sync_dbs, targets);
- 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(sync_only) {
+ goto cleanup;
+ }
}
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 */
- 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);
grp = alpm_db_readgrp(db, targ);
if(grp) {
@@ -565,7 +525,7 @@ int pacman_sync(alpm_list_t *targets)
if(!found) {
/* targ not found in sync db, searching for providers... */
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);
alpm_list_t *prov = alpm_db_whatprovides(db, targ);
if(prov) {
@@ -588,7 +548,6 @@ int pacman_sync(alpm_list_t *targets)
}
/* Step 2: "compute" the transaction based on targets and flags */
- alpm_list_t *data;
if(alpm_trans_prepare(&data) == -1) {
fprintf(stderr, _("error: failed to prepare transaction (%s)\n"),
alpm_strerrorlast());
@@ -716,4 +675,60 @@ cleanup:
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: */
diff --git a/src/pacman/util.c b/src/pacman/util.c
index 4cb93156..d82b5769 100644
--- a/src/pacman/util.c
+++ b/src/pacman/util.c
@@ -51,11 +51,8 @@ int needs_transaction()
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->flags & PM_TRANS_FLAG_PRINTURIS))
- || config->op == PM_OP_DEPTEST
- || (strcmp(alpm_option_get_root(), "/") != 0)) {
+ || config->op == PM_OP_DEPTEST) {
/* 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);
} else {
return(1);