mirror of
https://github.com/moparisthebest/pacman
synced 2025-01-10 13:28:12 -05:00
Break out transaction test to a separate function
Added needs_transaction, putting out "hey do we need root?" tests in one place. Signed-off-by: Aaron Griffin <aaronmgriffin@gmail.com>
This commit is contained in:
parent
50bb16e015
commit
4942d21632
@ -775,21 +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) {
|
||||
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->flags & PM_TRANS_FLAG_PRINTURIS))
|
||||
|| 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: ignore root user check if -r is specified, fall back on
|
||||
* normal FS checking */
|
||||
} else {
|
||||
pm_printf(PM_LOG_ERROR, _("you cannot perform this operation unless you are root.\n"));
|
||||
cleanup(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
if(myuid > 0 && needs_transaction()) {
|
||||
pm_printf(PM_LOG_ERROR, _("you cannot perform this operation unless you are root.\n"));
|
||||
cleanup(EXIT_FAILURE);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -45,6 +45,25 @@
|
||||
|
||||
extern config_t *config;
|
||||
|
||||
int needs_transaction()
|
||||
{
|
||||
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->flags & PM_TRANS_FLAG_PRINTURIS))
|
||||
|| 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: ignore root user check if -r is specified, fall back on
|
||||
* normal FS checking */
|
||||
return(0);
|
||||
} else {
|
||||
return(1);
|
||||
}
|
||||
}
|
||||
return(0);
|
||||
}
|
||||
|
||||
/* gets the current screen column width */
|
||||
int getcols()
|
||||
{
|
||||
|
@ -38,6 +38,7 @@
|
||||
#define _(str) str
|
||||
#endif
|
||||
|
||||
int needs_transaction();
|
||||
int getcols();
|
||||
int makepath(const char *path);
|
||||
int rmrf(const char *path);
|
||||
|
Loading…
Reference in New Issue
Block a user