[pacman-dev] [PATCH] Rework needs_transaction() and add new needs_root() function
From 1c0e5473d2eee695b21ab7be1ea787d990853854 Mon Sep 17 00:00:00 2001 From: Nagy Gabor <ngaba@bibl.u-szeged.hu> Date: Sat, 8 Mar 2008 17:41:46 +0100 Subject: [PATCH] Rework needs_transaction() and add new needs_root() function * preparation for -Sp non-root fix * add missing -Sc root check * "no targets specified" message in case of non-root 'pacman -A/U/S/R' * sysupgrade is performed always if -Su appears in command-line Signed-off-by: Nagy Gabor <ngaba@bibl.u-szeged.hu> --- src/pacman/pacman.c | 4 ++-- src/pacman/sync.c | 3 +-- src/pacman/util.c | 27 +++++++++++++++------------ src/pacman/util.h | 3 ++- 4 files changed, 20 insertions(+), 17 deletions(-) diff --git a/src/pacman/pacman.c b/src/pacman/pacman.c index 331cbe9..7f901cd 100644 --- a/src/pacman/pacman.c +++ b/src/pacman/pacman.c @@ -47,7 +47,7 @@ pmdb_t *db_local; /* list of targets specified on command line */ -static alpm_list_t *pm_targets; +static alpm_list_t *pm_targets = NULL; /** Display usage/syntax for the specified operation. * @param op the operation code requested @@ -824,7 +824,7 @@ 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 && needs_root(pm_targets)) { 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 f2d8f4b..130d356 100644 --- a/src/pacman/sync.c +++ b/src/pacman/sync.c @@ -799,10 +799,9 @@ int pacman_sync(alpm_list_t *targets) if(!sync_synctree(config->op_s_sync, sync_dbs)) { return(1); } - config->op_s_sync = 0; } - if(needs_transaction()) { + if(needs_transaction(targets)) { if(sync_trans(targets) == 1) { return(1); } diff --git a/src/pacman/util.c b/src/pacman/util.c index 2623dbd..9c1eada 100644 --- a/src/pacman/util.c +++ b/src/pacman/util.c @@ -43,19 +43,22 @@ #include "util.h" #include "conf.h" -int needs_transaction() +int needs_root(alpm_list_t *targets) { - if(config->op != PM_OP_MAIN && config->op != PM_OP_QUERY && config->op != PM_OP_DEPTEST) { - 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 == PM_OP_DEPTEST) { - /* special case: PM_OP_SYNC can be used w/ config->op_s_search by any user */ - return(0); - } else { - return(1); - } - } - return(0); + /* If we need transaction, except -Sp */ + return((needs_transaction(targets) && !(config->op == PM_OP_SYNC && (config->flags & PM_TRANS_FLAG_PRINTURIS))) + /* or -Sc, -Sy */ + || (config->op == PM_OP_SYNC && (config->op_s_sync || config->op_s_clean))); +} + +int needs_transaction(alpm_list_t *targets) +{ + /* -U, -A, -R targets */ + return(((config->op == PM_OP_UPGRADE || config->op == PM_OP_ADD || config->op == PM_OP_REMOVE) && targets) || + /* -Su */ + (config->op == PM_OP_SYNC && (config->op_s_upgrade || + /* -S targets, except -s,-i,-g,-l */ + (targets && !config->op_s_search && !config->group && !config->op_q_list && !config->op_s_info)))); } /* gets the current screen column width */ diff --git a/src/pacman/util.h b/src/pacman/util.h index f2facbf..4b4eada 100644 --- a/src/pacman/util.h +++ b/src/pacman/util.h @@ -36,7 +36,8 @@ /* update speed for the fill_progress based functions */ #define UPDATE_SPEED_SEC 0.2f -int needs_transaction(); +int needs_root(alpm_list_t *targets); +int needs_transaction(alpm_list_t *targets); int getcols(); int makepath(const char *path); int rmrf(const char *path); -- 1.5.3.8
On Sat, Mar 08, 2008 at 05:52:01PM +0100, Nagy Gabor wrote:
From 1c0e5473d2eee695b21ab7be1ea787d990853854 Mon Sep 17 00:00:00 2001 From: Nagy Gabor <ngaba@bibl.u-szeged.hu> Date: Sat, 8 Mar 2008 17:41:46 +0100 Subject: [PATCH] Rework needs_transaction() and add new needs_root() function
* "no targets specified" message in case of non-root 'pacman -A/U/S/R'
diff --git a/src/pacman/util.h b/src/pacman/util.h index f2facbf..4b4eada 100644 --- a/src/pacman/util.h +++ b/src/pacman/util.h @@ -36,7 +36,8 @@ /* update speed for the fill_progress based functions */ #define UPDATE_SPEED_SEC 0.2f
-int needs_transaction(); +int needs_root(alpm_list_t *targets); +int needs_transaction(alpm_list_t *targets); int getcols(); int makepath(const char *path); int rmrf(const char *path); -- 1.5.3.8
I don't like this targets arg. Do we really need that? Imo, the current behavior is acceptable.
participants (2)
-
Nagy Gabor
-
Xavier