index : pacman | |
Archlinux32 fork of pacman | gitolite user |
summaryrefslogtreecommitdiff |
-rw-r--r-- | src/pacman/pacman.c | 261 |
diff --git a/src/pacman/pacman.c b/src/pacman/pacman.c index a345977d..aa128261 100644 --- a/src/pacman/pacman.c +++ b/src/pacman/pacman.c @@ -1,8 +1,8 @@ /* * pacman.c - * - * Copyright (c) 2002-2006 by Judd Vinet <jvinet@zeroflux.org> - * + * + * Copyright (c) 2002-2007 by Judd Vinet <jvinet@zeroflux.org> + * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or @@ -15,14 +15,13 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, * USA. */ #include "config.h" -/* TODO hard to believe all these are needed just for this file */ -#include <stdlib.h> +#include <stdlib.h> /* atoi */ #include <stdio.h> #include <limits.h> #include <getopt.h> @@ -30,11 +29,10 @@ #include <signal.h> #include <unistd.h> #include <sys/types.h> -#include <sys/stat.h> -#include <sys/utsname.h> -#include <libintl.h> -#include <locale.h> -#include <time.h> +#include <sys/utsname.h> /* uname */ +#include <libintl.h> /* bindtextdomain, textdomain */ +#include <locale.h> /* setlocale */ +#include <time.h> /* time_t */ #if defined(PACMAN_DEBUG) && defined(HAVE_MTRACE) #include <mcheck.h> /* debug tracing (mtrace) */ #endif @@ -56,9 +54,7 @@ pmdb_t *db_local; /* list of targets specified on command line */ static alpm_list_t *pm_targets; -/** - * @brief Display usage/syntax for the specified operation. - * +/** Display usage/syntax for the specified operation. * @param op the operation code requested * @param myname basename(argv[0]) */ @@ -88,6 +84,7 @@ static void usage(int op, char *myname) if(op == PM_OP_ADD) { printf("%s: %s {-A --add} [%s] <%s>\n", str_usg, myname, str_opt, str_file); printf("%s:\n", str_opt); + printf(_(" --asdeps install packages as non-explicitly installed\n")); printf(_(" -d, --nodeps skip dependency checks\n")); printf(_(" -f, --force force install, overwrite conflicting files\n")); } else if(op == PM_OP_REMOVE) { @@ -106,14 +103,15 @@ static void usage(int op, char *myname) printf("%s: %s {-U --upgrade} [%s] <%s>\n", str_usg, myname, str_opt, str_file); } printf("%s:\n", str_opt); + printf(_(" --asdeps install packages as non-explicitly installed\n")); printf(_(" -d, --nodeps skip dependency checks\n")); printf(_(" -f, --force force install, overwrite conflicting files\n")); } else if(op == PM_OP_QUERY) { printf("%s: %s {-Q --query} [%s] [%s]\n", str_usg, myname, str_opt, str_pkg); printf("%s:\n", str_opt); printf(_(" -c, --changelog view the changelog of a package\n")); - printf(_(" -e, --orphans list all packages installed as dependencies but no longer\n" - " required by any package\n")); + printf(_(" -d, --deps list all packages installed as dependencies\n")); + printf(_(" -e, --explicit list all packages explicitly installed\n")); printf(_(" -g, --groups view all members of a package group\n")); printf(_(" -i, --info view package information\n")); printf(_(" -l, --list list the contents of the queried package\n")); @@ -121,11 +119,12 @@ static void usage(int op, char *myname) printf(_(" -o, --owns <file> query the package that owns <file>\n")); printf(_(" -p, --file <package> query a package file instead of the database\n")); printf(_(" -s, --search <regex> search locally-installed packages for matching strings\n")); - printf(_(" -t, --test check the consistency of the local database\n")); + printf(_(" -t, --orphans list all packages not required by any package\n")); printf(_(" -u, --upgrades list all packages that can be upgraded\n")); } else if(op == PM_OP_SYNC) { printf("%s: %s {-S --sync} [%s] [%s]\n", str_usg, myname, str_opt, str_pkg); printf("%s:\n", str_opt); + printf(_(" --asdeps install packages as non-explicitly installed\n")); printf(_(" -c, --clean remove old packages from cache directory (-cc for all)\n")); printf(_(" -d, --nodeps skip dependency checks\n")); printf(_(" -e, --dependsonly install dependencies only\n")); @@ -152,8 +151,7 @@ static void usage(int op, char *myname) } } -/** - * @brief Output pacman version and copyright. +/** Output pacman version and copyright. */ static void version(void) { @@ -167,9 +165,7 @@ static void version(void) printf("\n"); } -/** - * @brief Sets up gettext localization. - * Safe to call multiple times. +/** Sets up gettext localization. Safe to call multiple times. */ /* Inspired by the monotone function localize_monotone. */ static void localize(void) @@ -183,8 +179,7 @@ static void localize(void) } } -/** - * @brief Set user agent environment variable. +/** Set user agent environment variable. */ static void setuseragent(void) { @@ -199,11 +194,8 @@ static void setuseragent(void) setenv("HTTP_USER_AGENT", agent, 0); } -/** - * @brief Catches thrown signals. - * Performs necessary cleanup to ensure database is in a consistant - * state. - * +/** Catches thrown signals. Performs necessary cleanup to ensure database is + * in a consistant state. * @param signum the thrown signal */ static void cleanup(int signum) @@ -215,14 +207,19 @@ static void cleanup(int signum) pm_fprintf(stderr, PM_LOG_ERROR, "Internal pacman error: Segmentation fault.\n" "Please submit a full bug report with --debug if appropriate.\n"); exit(signum); - } else if((signum == SIGINT) && (alpm_trans_release() == -1) - && (pm_errno == PM_ERR_TRANS_COMMITING)) { - return; + } else if((signum == SIGINT)) { + if(alpm_trans_interrupt() == 0) { + /* a transaction is being interrupted, don't exit pacman yet. */ + return; + } else { + /* no commiting transaction, we can release it now and then exit pacman */ + alpm_trans_release(); + } } /* free alpm library resources */ if(alpm_release() == -1) { - fprintf(stderr, _("error: %s\n"), alpm_strerror(pm_errno)); + pm_printf(PM_LOG_ERROR, alpm_strerrorlast()); } /* free memory */ @@ -235,12 +232,9 @@ static void cleanup(int signum) exit(signum); } -/** - * @brief Parse command-line arguments for each operation - * +/** Parse command-line arguments for each operation. * @param argc argc * @param argv argv - * * @return 0 on success, 1 on error */ static int parseargs(int argc, char *argv[]) @@ -262,8 +256,9 @@ static int parseargs(int argc, char *argv[]) {"changelog", no_argument, 0, 'c'}, {"clean", no_argument, 0, 'c'}, {"nodeps", no_argument, 0, 'd'}, + {"deps", no_argument, 0, 'd'}, {"dependsonly",no_argument, 0, 'e'}, - {"orphans", no_argument, 0, 'e'}, + {"explicit", no_argument, 0, 'e'}, {"force", no_argument, 0, 'f'}, {"groups", no_argument, 0, 'g'}, {"help", no_argument, 0, 'h'}, @@ -278,7 +273,7 @@ static int parseargs(int argc, char *argv[]) {"root", required_argument, 0, 'r'}, {"recursive", no_argument, 0, 's'}, {"search", no_argument, 0, 's'}, - {"test", no_argument, 0, 't'}, + {"orphans", no_argument, 0, 't'}, {"upgrades", no_argument, 0, 'u'}, {"sysupgrade", no_argument, 0, 'u'}, {"verbose", no_argument, 0, 'v'}, @@ -288,13 +283,13 @@ static int parseargs(int argc, char *argv[]) {"config", required_argument, 0, 1001}, {"ignore", required_argument, 0, 1002}, {"debug", optional_argument, 0, 1003}, - {"noprogressbar", no_argument, 0, 1004}, + {"noprogressbar", no_argument, 0, 1004}, {"noscriptlet", no_argument, 0, 1005}, {"ask", required_argument, 0, 1006}, {"cachedir", required_argument, 0, 1007}, + {"asdeps", no_argument, 0, 1008}, {0, 0, 0, 0} }; - struct stat st; while((opt = getopt_long(argc, argv, "ARUFQSTr:b:vkhscVfmnoldepituwygz", opts, &option_index))) { if(opt < 0) { @@ -323,8 +318,8 @@ static int parseargs(int argc, char *argv[]) config->logmask |= PM_LOG_DEBUG; break; default: - fprintf(stderr, _("error: '%s' is not a valid debug level\n"), - optarg); + pm_printf(PM_LOG_ERROR, _("'%s' is not a valid debug level\n"), + optarg); return(1); } } else { @@ -337,13 +332,14 @@ static int parseargs(int argc, char *argv[]) case 1005: config->flags |= PM_TRANS_FLAG_NOSCRIPTLET; break; case 1006: config->noask = 1; config->ask = atoi(optarg); break; case 1007: - /* TODO redo this logic- check path somewhere else, delete other cachedirs, etc */ - if(stat(optarg, &st) == -1 || !S_ISDIR(st.st_mode)) { - fprintf(stderr, _("error: '%s' is not a valid cache directory\n"), - optarg); + if(alpm_option_add_cachedir(optarg) != 0) { + pm_printf(PM_LOG_ERROR, _("problem adding cachedir '%s' (%s)\n"), + optarg, alpm_strerrorlast()); return(1); } - alpm_option_add_cachedir(optarg); + break; + case 1008: + config->flags |= PM_TRANS_FLAG_ALLDEPS; break; case 'A': config->op = (config->op != PM_OP_MAIN ? 0 : PM_OP_ADD); break; case 'F': @@ -357,21 +353,24 @@ static int parseargs(int argc, char *argv[]) case 'U': config->op = (config->op != PM_OP_MAIN ? 0 : PM_OP_UPGRADE); break; case 'V': config->version = 1; break; case 'b': - if(stat(optarg, &st) == -1 || !S_ISDIR(st.st_mode)) { - fprintf(stderr, _("error: '%s' is not a valid db path\n"), - optarg); + if(alpm_option_set_dbpath(optarg) != 0) { + pm_printf(PM_LOG_ERROR, _("problem setting dbpath '%s' (%s)\n"), + optarg, alpm_strerrorlast()); return(1); } - alpm_option_set_dbpath(optarg); + config->have_dbpath = 1; break; case 'c': (config->op_s_clean)++; config->flags |= PM_TRANS_FLAG_CASCADE; config->op_q_changelog = 1; break; - case 'd': config->flags |= PM_TRANS_FLAG_NODEPS; break; + case 'd': + config->op_q_deps = 1; + config->flags |= PM_TRANS_FLAG_NODEPS; + break; case 'e': - config->op_q_orphans++; + config->op_q_explicit = 1; config->flags |= PM_TRANS_FLAG_DEPENDSONLY; break; case 'f': config->flags |= PM_TRANS_FLAG_FORCE; break; @@ -388,12 +387,12 @@ static int parseargs(int argc, char *argv[]) config->flags |= PM_TRANS_FLAG_PRINTURIS; break; case 'r': - if(stat(optarg, &st) == -1 || !S_ISDIR(st.st_mode)) { - fprintf(stderr, _("error: '%s' is not a valid root path\n"), - optarg); + if(alpm_option_set_root(optarg) != 0) { + pm_printf(PM_LOG_ERROR, _("problem setting root '%s' (%s)\n"), + optarg, alpm_strerrorlast()); return(1); } - alpm_option_set_root(optarg); + config->have_root = 1; break; case 's': config->op_s_search = 1; @@ -401,7 +400,7 @@ static int parseargs(int argc, char *argv[]) config->flags |= PM_TRANS_FLAG_RECURSE; break; case 't': - config->op_q_test = 1; + config->op_q_orphans = 1; break; case 'u': config->op_s_upgrade = 1; @@ -420,7 +419,7 @@ static int parseargs(int argc, char *argv[]) } if(config->op == 0) { - fprintf(stderr, _("error: only one operation may be used at a time\n")); + pm_printf(PM_LOG_ERROR, _("only one operation may be used at a time\n")); return(1); } @@ -453,7 +452,7 @@ static int _parseconfig(const char *file, const char *givensection, char *ptr, *section = NULL; pmdb_t *db = NULL; - pm_printf(PM_LOG_DEBUG, _("config: attempting to read file %s\n"), file); + pm_printf(PM_LOG_DEBUG, "config: attempting to read file %s\n", file); fp = fopen(file, "r"); if(fp == NULL) { pm_printf(PM_LOG_ERROR, _("config file %s could not be read.\n"), file); @@ -490,26 +489,19 @@ static int _parseconfig(const char *file, const char *givensection, } section = strdup(ptr); section[strlen(section)-1] = '\0'; - pm_printf(PM_LOG_DEBUG, _("config: new section '%s'\n"), section); + pm_printf(PM_LOG_DEBUG, "config: new section '%s'\n", section); if(!strlen(section)) { pm_printf(PM_LOG_ERROR, _("config file %s, line %d: bad section name.\n"), file, linenum); return(1); } - /* a section/database named local is not allowed */ - if(!strcmp(section, "local")) { - pm_printf(PM_LOG_ERROR, _("config file %s, line %d: 'local' cannot be used as section name.\n"), - file, linenum); - return(1); - } /* if we are not looking at the options section, register a db */ if(strcmp(section, "options") != 0) { - db = alpm_db_register(section); + db = alpm_db_register_sync(section); } } else { /* directive */ - char *key; - const char *upperkey; + char *key, *upperkey; /* strsep modifies the 'line' string: 'key \0 ptr' */ key = line; ptr = line; @@ -522,6 +514,10 @@ static int _parseconfig(const char *file, const char *givensection, file, linenum); return(1); } + /* For each directive, compare to the uppercase and camelcase string. + * This prevents issues with certain locales where characters don't + * follow the toupper() rules we may expect, e.g. tr_TR where i != I. + */ upperkey = strtoupper(strdup(key)); if(section == NULL && (strcmp(key, "Include") == 0 || strcmp(upperkey, "INCLUDE") == 0)) { pm_printf(PM_LOG_ERROR, _("config file %s, line %d: 'Include' directive must belong to a section.\n"), @@ -532,19 +528,19 @@ static int _parseconfig(const char *file, const char *givensection, /* directives without settings, all in [options] */ if(strcmp(key, "NoPassiveFTP") == 0 || strcmp(upperkey, "NOPASSIVEFTP") == 0) { alpm_option_set_nopassiveftp(1); - pm_printf(PM_LOG_DEBUG, _("config: nopassiveftp\n")); + pm_printf(PM_LOG_DEBUG, "config: nopassiveftp\n"); } else if(strcmp(key, "UseSyslog") == 0 || strcmp(upperkey, "USESYSLOG") == 0) { alpm_option_set_usesyslog(1); - pm_printf(PM_LOG_DEBUG, _("config: usesyslog\n")); + pm_printf(PM_LOG_DEBUG, "config: usesyslog\n"); } else if(strcmp(key, "ILoveCandy") == 0 || strcmp(upperkey, "ILOVECANDY") == 0) { config->chomp = 1; - pm_printf(PM_LOG_DEBUG, _("config: chomp\n")); + pm_printf(PM_LOG_DEBUG, "config: chomp\n"); } else if(strcmp(key, "UseColor") == 0 || strcmp(upperkey, "USECOLOR") == 0) { config->usecolor = 1; - pm_printf(PM_LOG_DEBUG, _("config: usecolor\n")); + pm_printf(PM_LOG_DEBUG, "config: usecolor\n"); } else if(strcmp(key, "ShowSize") == 0 || strcmp(upperkey, "SHOWSIZE") == 0) { config->showsize= 1; - pm_printf(PM_LOG_DEBUG, _("config: showsize\n")); + pm_printf(PM_LOG_DEBUG, "config: showsize\n"); } else { pm_printf(PM_LOG_ERROR, _("config file %s, line %d: directive '%s' not recognized.\n"), file, linenum, key); @@ -554,7 +550,7 @@ static int _parseconfig(const char *file, const char *givensection, /* directives with settings */ if(strcmp(key, "Include") == 0 || strcmp(upperkey, "INCLUDE") == 0) { int ret; - pm_printf(PM_LOG_DEBUG, _("config: including %s\n"), ptr); + pm_printf(PM_LOG_DEBUG, "config: including %s\n", ptr); ret = _parseconfig(ptr, section, db); if(ret != 0) { return(ret); @@ -568,12 +564,12 @@ static int _parseconfig(const char *file, const char *givensection, while((q = strchr(p, ' '))) { *q = '\0'; alpm_option_add_noupgrade(p); - pm_printf(PM_LOG_DEBUG, _("config: noupgrade: %s\n"), p); + pm_printf(PM_LOG_DEBUG, "config: noupgrade: %s\n", p); p = q; p++; } alpm_option_add_noupgrade(p); - pm_printf(PM_LOG_DEBUG, _("config: noupgrade: %s\n"), p); + pm_printf(PM_LOG_DEBUG, "config: noupgrade: %s\n", p); } else if(strcmp(key, "NoExtract") == 0 || strcmp(upperkey, "NOEXTRACT") == 0) { char *p = ptr; char *q; @@ -581,12 +577,12 @@ static int _parseconfig(const char *file, const char *givensection, while((q = strchr(p, ' '))) { *q = '\0'; alpm_option_add_noextract(p); - pm_printf(PM_LOG_DEBUG, _("config: noextract: %s\n"), p); + pm_printf(PM_LOG_DEBUG, "config: noextract: %s\n", p); p = q; p++; } alpm_option_add_noextract(p); - pm_printf(PM_LOG_DEBUG, _("config: noextract: %s\n"), p); + pm_printf(PM_LOG_DEBUG, "config: noextract: %s\n", p); } else if(strcmp(key, "IgnorePkg") == 0 || strcmp(upperkey, "IGNOREPKG") == 0) { char *p = ptr; char *q; @@ -594,12 +590,12 @@ static int _parseconfig(const char *file, const char *givensection, while((q = strchr(p, ' '))) { *q = '\0'; alpm_option_add_ignorepkg(p); - pm_printf(PM_LOG_DEBUG, _("config: ignorepkg: %s"), p); + pm_printf(PM_LOG_DEBUG, "config: ignorepkg: %s", p); p = q; p++; } alpm_option_add_ignorepkg(p); - pm_printf(PM_LOG_DEBUG, _("config: ignorepkg: %s\n"), p); + pm_printf(PM_LOG_DEBUG, "config: ignorepkg: %s\n", p); } else if(strcmp(key, "HoldPkg") == 0 || strcmp(upperkey, "HOLDPKG") == 0) { char *p = ptr; char *q; @@ -607,38 +603,56 @@ static int _parseconfig(const char *file, const char *givensection, while((q = strchr(p, ' '))) { *q = '\0'; alpm_option_add_holdpkg(p); - pm_printf(PM_LOG_DEBUG, _("config: holdpkg: %s\n"), p); + pm_printf(PM_LOG_DEBUG, "config: holdpkg: %s\n", p); p = q; p++; } alpm_option_add_holdpkg(p); - pm_printf(PM_LOG_DEBUG, _("config: holdpkg: %s\n"), p); + pm_printf(PM_LOG_DEBUG, "config: holdpkg: %s\n", p); } else if(strcmp(key, "DBPath") == 0 || strcmp(upperkey, "DBPATH") == 0) { - if(alpm_option_get_dbpath() == NULL) { - alpm_option_set_dbpath(ptr); - pm_printf(PM_LOG_DEBUG, _("config: dbpath: %s\n"), ptr); + /* don't overwrite a path specified on the command line */ + if(!config->have_dbpath) { + if(alpm_option_set_dbpath(ptr) != 0) { + pm_printf(PM_LOG_ERROR, _("problem setting dbpath '%s' (%s)\n"), + ptr, alpm_strerrorlast()); + return(1); + } + pm_printf(PM_LOG_DEBUG, "config: dbpath: %s\n", ptr); } } else if(strcmp(key, "CacheDir") == 0 || strcmp(upperkey, "CACHEDIR") == 0) { - alpm_option_add_cachedir(ptr); - pm_printf(PM_LOG_DEBUG, _("config: cachedir: %s\n"), ptr); + if(alpm_option_add_cachedir(ptr) != 0) { + pm_printf(PM_LOG_ERROR, _("problem adding cachedir '%s' (%s)\n"), + ptr, alpm_strerrorlast()); + return(1); + } + pm_printf(PM_LOG_DEBUG, "config: cachedir: %s\n", ptr); } else if(strcmp(key, "RootDir") == 0 || strcmp(upperkey, "ROOTDIR") == 0) { - if(alpm_option_get_root() == NULL) { - alpm_option_set_root(ptr); - pm_printf(PM_LOG_DEBUG, _("config: rootdir: %s\n"), ptr); + /* don't overwrite a path specified on the command line */ + if(!config->have_root) { + if(alpm_option_set_root(ptr) != 0) { + pm_printf(PM_LOG_ERROR, _("problem setting root '%s' (%s)\n"), + ptr, alpm_strerrorlast()); + return(1); + } + pm_printf(PM_LOG_DEBUG, "config: rootdir: %s\n", ptr); } } else if (strcmp(key, "LogFile") == 0 || strcmp(upperkey, "LOGFILE") == 0) { - if(alpm_option_get_logfile() == NULL) { - alpm_option_set_logfile(ptr); - pm_printf(PM_LOG_DEBUG, _("config: logfile: %s\n"), ptr); + if(!config->have_logfile) { + if(alpm_option_set_logfile(ptr) != 0) { + pm_printf(PM_LOG_ERROR, _("problem setting logfile '%s' (%s)\n"), + ptr, alpm_strerrorlast()); + return(1); + } + pm_printf(PM_LOG_DEBUG, "config: logfile: %s\n", ptr); } } else if (strcmp(key, "XferCommand") == 0 || strcmp(upperkey, "XFERCOMMAND") == 0) { alpm_option_set_xfercommand(ptr); - pm_printf(PM_LOG_DEBUG, _("config: xfercommand: %s\n"), ptr); + pm_printf(PM_LOG_DEBUG, "config: xfercommand: %s\n", ptr); } else if (strcmp(key, "UpgradeDelay") == 0 || strcmp(upperkey, "UPGRADEDELAY") == 0) { /* The config value is in days, we use seconds */ time_t ud = atol(ptr) * 60 * 60 *24; alpm_option_set_upgradedelay(ud); - pm_printf(PM_LOG_DEBUG, _("config: upgradedelay: %d\n"), (int)ud); + pm_printf(PM_LOG_DEBUG, "config: upgradedelay: %d\n", (int)ud); } else { pm_printf(PM_LOG_ERROR, _("config file %s, line %d: directive '%s' not recognized.\n"), file, linenum, key); @@ -660,9 +674,13 @@ static int _parseconfig(const char *file, const char *givensection, return(1); } } + free(upperkey); } } fclose(fp); + if(section){ + free(section); + } pm_printf(PM_LOG_DEBUG, "config: finished parsing %s\n", file); return(0); @@ -678,12 +696,9 @@ int parseconfig(const char *file) return(_parseconfig(file, NULL, NULL)); } -/** - * @brief Main function. - * +/** Main function. * @param argc argc * @param argv argv - * * @return A return code indicating success, failure, etc. */ int main(int argc, char *argv[]) @@ -718,16 +733,28 @@ int main(int argc, char *argv[]) config->noprogressbar = 1; } - /* initialize pm library */ + /* initialize library */ if(alpm_initialize() == -1) { - fprintf(stderr, _("error: failed to initialize alpm library (%s)\n"), - alpm_strerror(pm_errno)); + pm_printf(PM_LOG_ERROR, _("failed to initialize alpm library (%s)\n"), + alpm_strerrorlast()); cleanup(EXIT_FAILURE); } /* Setup logging as soon as possible, to print out maximum debugging info */ alpm_option_set_logcb(cb_log); alpm_option_set_dlcb(cb_dl_progress); + /* define root and dbpath to reasonable defaults */ + alpm_option_set_root(ROOTDIR); + alpm_option_set_dbpath(DBPATH); + + /* Priority of options: + * 1. command line + * 2. config file + * 3. compiled-in defaults + * However, we have to parse the command line first because a config file + * location can be specified here, so we need to make sure we prefer these + * options over the config file coming second. + */ /* parse the command line */ ret = parseargs(argc, argv); @@ -735,37 +762,35 @@ int main(int argc, char *argv[]) cleanup(ret); } - /* use default config file if location wasn't specified on cmdline */ - if(config->configfile == NULL) { - config->configfile = strdup(CONFFILE); - } - /* parse the config file */ ret = parseconfig(config->configfile); if(ret != 0) { cleanup(ret); } + /* add a default cachedir if one wasn't specified */ + if(alpm_option_get_cachedirs() == NULL) { + alpm_option_add_cachedir(CACHEDIR); + } + #if defined(HAVE_GETEUID) /* check if we have sufficient permission for the requested operation */ -if(0) { 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 && config->op_d_resolve) + || 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 { - fprintf(stderr, _("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); } } } -} #endif if(config->verbose > 0) { @@ -784,10 +809,10 @@ if(0) { } /* Opening local database */ - db_local = alpm_db_register("local"); + db_local = alpm_db_register_local(); if(db_local == NULL) { - fprintf(stderr, _("error: could not register 'local' database (%s)\n"), - alpm_strerror(pm_errno)); + pm_printf(PM_LOG_ERROR, _("could not register 'local' database (%s)\n"), + alpm_strerrorlast()); cleanup(EXIT_FAILURE); } @@ -812,7 +837,7 @@ if(0) { ret = pacman_deptest(pm_targets); break; default: - fprintf(stderr, _("error: no operation specified (use -h for help)\n")); + pm_printf(PM_LOG_ERROR, _("no operation specified (use -h for help)\n")); ret = EXIT_FAILURE; } |