summaryrefslogtreecommitdiff
path: root/src/pacman
diff options
context:
space:
mode:
Diffstat (limited to 'src/pacman')
-rw-r--r--src/pacman/callback.c20
-rw-r--r--src/pacman/conf.c307
-rw-r--r--src/pacman/conf.h16
-rw-r--r--src/pacman/database.c218
-rw-r--r--src/pacman/ini.c147
-rw-r--r--src/pacman/pacman.c23
-rw-r--r--src/pacman/util.c3
7 files changed, 454 insertions, 280 deletions
diff --git a/src/pacman/callback.c b/src/pacman/callback.c
index 4993382d..0d87fd35 100644
--- a/src/pacman/callback.c
+++ b/src/pacman/callback.c
@@ -269,9 +269,11 @@ void cb_event(alpm_event_t *event)
case ALPM_EVENT_OPTDEP_REMOVAL:
{
alpm_event_optdep_removal_t *e = &event->optdep_removal;
+ char *dep_string = alpm_dep_compute_string(e->optdep);
colon_printf(_("%s optionally requires %s\n"),
alpm_pkg_get_name(e->pkg),
- alpm_dep_compute_string(e->optdep));
+ dep_string);
+ free(dep_string);
}
break;
case ALPM_EVENT_DATABASE_MISSING:
@@ -313,22 +315,6 @@ void cb_event(alpm_event_t *event)
}
}
break;
- case ALPM_EVENT_PACORIG_CREATED:
- {
- alpm_event_pacorig_created_t *e = &event->pacorig_created;
- if(on_progress) {
- char *string = NULL;
- pm_sprintf(&string, ALPM_LOG_WARNING, _("%s saved as %s.pacorig\n"),
- e->file, e->file);
- if(string != NULL) {
- output = alpm_list_add(output, string);
- }
- } else {
- pm_printf(ALPM_LOG_WARNING, _("%s saved as %s.pacorig\n"),
- e->file, e->file);
- }
- }
- break;
/* all the simple done events, with fallthrough for each */
case ALPM_EVENT_FILECONFLICTS_DONE:
case ALPM_EVENT_CHECKDEPS_DONE:
diff --git a/src/pacman/conf.c b/src/pacman/conf.c
index 873ca0ee..b31b2536 100644
--- a/src/pacman/conf.c
+++ b/src/pacman/conf.c
@@ -22,6 +22,7 @@
#include <limits.h>
#include <locale.h> /* setlocale */
#include <fcntl.h> /* open */
+#include <glob.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h> /* strdup */
@@ -131,6 +132,9 @@ int config_free(config_t *oldconfig)
alpm_list_free(oldconfig->explicit_adds);
alpm_list_free(oldconfig->explicit_removes);
+ alpm_list_free_inner(config->repos, (alpm_list_fn_free) config_repo_free);
+ alpm_list_free(config->repos);
+
FREELIST(oldconfig->holdpkg);
FREELIST(oldconfig->ignorepkg);
FREELIST(oldconfig->ignoregrp);
@@ -151,6 +155,16 @@ int config_free(config_t *oldconfig)
return 0;
}
+void config_repo_free(config_repo_t *repo)
+{
+ if(repo == NULL) {
+ return;
+ }
+ free(repo->name);
+ FREELIST(repo->servers);
+ free(repo);
+}
+
/** Helper function for download_with_xfercommand() */
static char *get_filename(const char *url)
{
@@ -309,12 +323,15 @@ int config_set_arch(const char *arch)
* @return 0 on success, 1 on any parsing error
*/
static int process_siglevel(alpm_list_t *values, alpm_siglevel_t *storage,
- const char *file, int linenum)
+ alpm_siglevel_t *storage_mask, const char *file, int linenum)
{
- alpm_siglevel_t level = *storage;
+ alpm_siglevel_t level = *storage, mask = *storage_mask;
alpm_list_t *i;
int ret = 0;
+#define SLSET(sl) do { level |= (sl); mask |= (sl); } while(0)
+#define SLUNSET(sl) do { level &= ~(sl); mask |= (sl); } while(0)
+
/* Collapse the option names into a single bitmasked value */
for(i = values; i; i = alpm_list_next(i)) {
const char *original = i->data, *value;
@@ -337,51 +354,40 @@ static int process_siglevel(alpm_list_t *values, alpm_siglevel_t *storage,
/* now parse out and store actual flag if it is valid */
if(strcmp(value, "Never") == 0) {
if(package) {
- level &= ~ALPM_SIG_PACKAGE;
- level |= ALPM_SIG_PACKAGE_SET;
+ SLUNSET(ALPM_SIG_PACKAGE);
}
if(database) {
- level &= ~ALPM_SIG_DATABASE;
+ SLUNSET(ALPM_SIG_DATABASE);
}
} else if(strcmp(value, "Optional") == 0) {
if(package) {
- level |= ALPM_SIG_PACKAGE;
- level |= ALPM_SIG_PACKAGE_OPTIONAL;
- level |= ALPM_SIG_PACKAGE_SET;
+ SLSET(ALPM_SIG_PACKAGE | ALPM_SIG_PACKAGE_OPTIONAL);
}
if(database) {
- level |= ALPM_SIG_DATABASE;
- level |= ALPM_SIG_DATABASE_OPTIONAL;
+ SLSET(ALPM_SIG_DATABASE | ALPM_SIG_DATABASE_OPTIONAL);
}
} else if(strcmp(value, "Required") == 0) {
if(package) {
- level |= ALPM_SIG_PACKAGE;
- level &= ~ALPM_SIG_PACKAGE_OPTIONAL;
- level |= ALPM_SIG_PACKAGE_SET;
+ SLSET(ALPM_SIG_PACKAGE);
+ SLUNSET(ALPM_SIG_PACKAGE_OPTIONAL);
}
if(database) {
- level |= ALPM_SIG_DATABASE;
- level &= ~ALPM_SIG_DATABASE_OPTIONAL;
+ SLSET(ALPM_SIG_DATABASE);
+ SLUNSET(ALPM_SIG_DATABASE_OPTIONAL);
}
} else if(strcmp(value, "TrustedOnly") == 0) {
if(package) {
- level &= ~ALPM_SIG_PACKAGE_MARGINAL_OK;
- level &= ~ALPM_SIG_PACKAGE_UNKNOWN_OK;
- level |= ALPM_SIG_PACKAGE_TRUST_SET;
+ SLUNSET(ALPM_SIG_PACKAGE_MARGINAL_OK | ALPM_SIG_PACKAGE_UNKNOWN_OK);
}
if(database) {
- level &= ~ALPM_SIG_DATABASE_MARGINAL_OK;
- level &= ~ALPM_SIG_DATABASE_UNKNOWN_OK;
+ SLUNSET(ALPM_SIG_DATABASE_MARGINAL_OK | ALPM_SIG_DATABASE_UNKNOWN_OK);
}
} else if(strcmp(value, "TrustAll") == 0) {
if(package) {
- level |= ALPM_SIG_PACKAGE_MARGINAL_OK;
- level |= ALPM_SIG_PACKAGE_UNKNOWN_OK;
- level |= ALPM_SIG_PACKAGE_TRUST_SET;
+ SLSET(ALPM_SIG_PACKAGE_MARGINAL_OK | ALPM_SIG_PACKAGE_UNKNOWN_OK);
}
if(database) {
- level |= ALPM_SIG_DATABASE_MARGINAL_OK;
- level |= ALPM_SIG_DATABASE_UNKNOWN_OK;
+ SLSET(ALPM_SIG_DATABASE_MARGINAL_OK | ALPM_SIG_DATABASE_UNKNOWN_OK);
}
} else {
pm_printf(ALPM_LOG_ERROR,
@@ -392,6 +398,9 @@ static int process_siglevel(alpm_list_t *values, alpm_siglevel_t *storage,
level &= ~ALPM_SIG_USE_DEFAULT;
}
+#undef SLSET
+#undef SLUNSET
+
/* ensure we have sig checking ability and are actually turning it on */
if(!(alpm_capabilities() & ALPM_CAPABILITY_SIGNATURES) &&
level & (ALPM_SIG_PACKAGE | ALPM_SIG_DATABASE)) {
@@ -403,6 +412,7 @@ static int process_siglevel(alpm_list_t *values, alpm_siglevel_t *storage,
if(!ret) {
*storage = level;
+ *storage_mask = mask;
}
return ret;
}
@@ -410,23 +420,13 @@ static int process_siglevel(alpm_list_t *values, alpm_siglevel_t *storage,
/**
* Merge the package entires of two signature verification levels.
* @param base initial siglevel
- * @param over overridden siglevel, derived value is stored here
+ * @param over overridden siglevel
+ * @return merged siglevel
*/
-static void merge_siglevel(alpm_siglevel_t *base, alpm_siglevel_t *over)
+static alpm_siglevel_t merge_siglevel(alpm_siglevel_t base,
+ alpm_siglevel_t over, alpm_siglevel_t mask)
{
- alpm_siglevel_t level = *over;
- if(!(level & ALPM_SIG_USE_DEFAULT)) {
- if(!(level & ALPM_SIG_PACKAGE_SET)) {
- level |= *base & ALPM_SIG_PACKAGE;
- level |= *base & ALPM_SIG_PACKAGE_OPTIONAL;
- }
- if(!(level & ALPM_SIG_PACKAGE_TRUST_SET)) {
- level |= *base & ALPM_SIG_PACKAGE_MARGINAL_OK;
- level |= *base & ALPM_SIG_PACKAGE_UNKNOWN_OK;
- }
- }
-
- *over = level;
+ return mask ? (over & mask) | (base & ~mask) : over;
}
static int process_cleanmethods(alpm_list_t *values,
@@ -575,7 +575,8 @@ static int _parse_options(const char *key, char *value,
} else if(strcmp(key, "SigLevel") == 0) {
alpm_list_t *values = NULL;
setrepeatingoption(value, "SigLevel", &values);
- if(process_siglevel(values, &config->siglevel, file, linenum)) {
+ if(process_siglevel(values, &config->siglevel,
+ &config->siglevel_mask, file, linenum)) {
FREELIST(values);
return 1;
}
@@ -583,7 +584,8 @@ static int _parse_options(const char *key, char *value,
} else if(strcmp(key, "LocalFileSigLevel") == 0) {
alpm_list_t *values = NULL;
setrepeatingoption(value, "LocalFileSigLevel", &values);
- if(process_siglevel(values, &config->localfilesiglevel, file, linenum)) {
+ if(process_siglevel(values, &config->localfilesiglevel,
+ &config->localfilesiglevel_mask, file, linenum)) {
FREELIST(values);
return 1;
}
@@ -591,7 +593,8 @@ static int _parse_options(const char *key, char *value,
} else if(strcmp(key, "RemoteFileSigLevel") == 0) {
alpm_list_t *values = NULL;
setrepeatingoption(value, "RemoteFileSigLevel", &values);
- if(process_siglevel(values, &config->remotefilesiglevel, file, linenum)) {
+ if(process_siglevel(values, &config->remotefilesiglevel,
+ &config->remotefilesiglevel_mask, file, linenum)) {
FREELIST(values);
return 1;
}
@@ -640,6 +643,40 @@ static int _add_mirror(alpm_db_t *db, char *value)
return 0;
}
+static int register_repo(config_repo_t *repo)
+{
+ alpm_list_t *i;
+ alpm_db_t *db;
+
+ repo->siglevel = merge_siglevel(config->siglevel,
+ repo->siglevel, repo->siglevel_mask);
+
+ db = alpm_register_syncdb(config->handle, repo->name, repo->siglevel);
+ if(db == NULL) {
+ pm_printf(ALPM_LOG_ERROR, _("could not register '%s' database (%s)\n"),
+ repo->name, alpm_strerror(alpm_errno(config->handle)));
+ return 1;
+ }
+
+ pm_printf(ALPM_LOG_DEBUG,
+ "setting usage of %d for %s repository\n",
+ repo->usage == 0 ? ALPM_DB_USAGE_ALL : repo->usage,
+ repo->name);
+ alpm_db_set_usage(db, repo->usage == 0 ? ALPM_DB_USAGE_ALL : repo->usage);
+
+ for(i = repo->servers; i; i = alpm_list_next(i)) {
+ char *value = i->data;
+ if(_add_mirror(db, value) != 0) {
+ pm_printf(ALPM_LOG_ERROR,
+ _("could not add mirror '%s' to database '%s' (%s)\n"),
+ value, repo->name, alpm_strerror(alpm_errno(config->handle)));
+ return 1;
+ }
+ }
+
+ return 0;
+}
+
/** Sets up libalpm global stuff in one go. Called after the command line
* and initial config file parsing. Once this is complete, we can see if any
* paths were defined. If a rootdir was defined and nothing else, we want all
@@ -680,7 +717,7 @@ static int setup_libalpm(void)
pm_printf(ALPM_LOG_ERROR, _("failed to initialize alpm library\n(%s: %s)\n"),
alpm_strerror(err), config->dbpath);
if(err == ALPM_ERR_DB_VERSION) {
- pm_printf(ALPM_LOG_ERROR, _(" try running pacman-db-upgrade\n"));
+ fprintf(stderr, _("try running pacman-db-upgrade\n"));
}
return -1;
}
@@ -719,11 +756,18 @@ static int setup_libalpm(void)
alpm_option_set_default_siglevel(handle, config->siglevel);
- merge_siglevel(&config->siglevel, &config->localfilesiglevel);
- merge_siglevel(&config->siglevel, &config->remotefilesiglevel);
+ config->localfilesiglevel = merge_siglevel(config->siglevel,
+ config->localfilesiglevel, config->localfilesiglevel_mask);
+ config->remotefilesiglevel = merge_siglevel(config->siglevel,
+ config->remotefilesiglevel, config->remotefilesiglevel_mask);
+
alpm_option_set_local_file_siglevel(handle, config->localfilesiglevel);
alpm_option_set_remote_file_siglevel(handle, config->remotefilesiglevel);
+ for(i = config->repos; i; i = alpm_list_next(i)) {
+ register_repo(i->data);
+ }
+
if(config->xfercommand) {
alpm_option_set_fetchcb(handle, download_with_xfercommand);
} else if(!(alpm_capabilities() & ALPM_CAPABILITY_DOWNLOADER)) {
@@ -754,7 +798,7 @@ static int setup_libalpm(void)
ret = alpm_option_add_assumeinstalled(handle, dep);
if(ret) {
- pm_printf(ALPM_LOG_ERROR, _("Failed to pass assume installed entry to libalpm"));
+ pm_printf(ALPM_LOG_ERROR, _("Failed to pass %s entry to libalpm"), "assume-installed");
alpm_dep_free(dep);
return ret;
}
@@ -768,14 +812,9 @@ static int setup_libalpm(void)
* calling library methods.
*/
struct section_t {
- /* useful for all sections */
const char *name;
- int is_options;
- int parse_options;
- /* db section option gathering */
- alpm_list_t *servers;
- alpm_siglevel_t siglevel;
- alpm_db_usage_t usage;
+ config_repo_t *repo;
+ int depth;
};
static int process_usage(alpm_list_t *values, alpm_db_usage_t *usage,
@@ -816,6 +855,7 @@ static int _parse_repo(const char *key, char *value, const char *file,
int line, struct section_t *section)
{
int ret = 0;
+ config_repo_t *repo = section->repo;
if(strcmp(key, "Server") == 0) {
if(!value) {
@@ -823,7 +863,7 @@ static int _parse_repo(const char *key, char *value, const char *file,
file, line, key);
ret = 1;
} else {
- section->servers = alpm_list_add(section->servers, strdup(value));
+ repo->servers = alpm_list_add(repo->servers, strdup(value));
}
} else if(strcmp(key, "SigLevel") == 0) {
if(!value) {
@@ -833,10 +873,8 @@ static int _parse_repo(const char *key, char *value, const char *file,
alpm_list_t *values = NULL;
setrepeatingoption(value, "SigLevel", &values);
if(values) {
- if(section->siglevel == ALPM_SIG_USE_DEFAULT) {
- section->siglevel = config->siglevel;
- }
- ret = process_siglevel(values, &section->siglevel, file, line);
+ ret = process_siglevel(values, &repo->siglevel,
+ &repo->siglevel_mask, file, line);
FREELIST(values);
}
}
@@ -844,7 +882,7 @@ static int _parse_repo(const char *key, char *value, const char *file,
alpm_list_t *values = NULL;
setrepeatingoption(value, "Usage", &values);
if(values) {
- if(process_usage(values, &section->usage, file, line)) {
+ if(process_usage(values, &repo->usage, file, line)) {
FREELIST(values);
return 1;
}
@@ -853,67 +891,72 @@ static int _parse_repo(const char *key, char *value, const char *file,
} else {
pm_printf(ALPM_LOG_WARNING,
_("config file %s, line %d: directive '%s' in section '%s' not recognized.\n"),
- file, line, key, section->name);
+ file, line, key, repo->name);
}
return ret;
}
-/**
- * Wrap up a section once we have reached the end of it. This should be called
- * when a subsequent section is encountered, or when we have reached the end of
- * the root config file. Once called, all existing saved config pieces on the
- * section struct are freed.
- * @param section the current parsed and saved section data
- * @param parse_options whether we are parsing options or repo data
- * @return 0 on success, 1 on failure
- */
-static int finish_section(struct section_t *section)
-{
- int ret = 0;
- alpm_list_t *i;
- alpm_db_t *db;
+static int _parse_directive(const char *file, int linenum, const char *name,
+ char *key, char *value, void *data);
- pm_printf(ALPM_LOG_DEBUG, "config: finish section '%s'\n", section->name);
+static int process_include(const char *value, void *data,
+ const char *file, int linenum)
+{
+ glob_t globbuf;
+ int globret, ret = 0;
+ size_t gindex;
+ struct section_t *section = data;
+ static const int config_max_recursion = 10;
- /* parsing options (or nothing)- nothing to do except free the pieces */
- if(!section->name || section->parse_options || section->is_options) {
- goto cleanup;
+ if(value == NULL) {
+ pm_printf(ALPM_LOG_ERROR, _("config file %s, line %d: directive '%s' needs a value\n"),
+ file, linenum, "Include");
+ return 1;
}
- /* if we are not looking at options sections only, register a db */
- db = alpm_register_syncdb(config->handle, section->name, section->siglevel);
- if(db == NULL) {
- pm_printf(ALPM_LOG_ERROR, _("could not register '%s' database (%s)\n"),
- section->name, alpm_strerror(alpm_errno(config->handle)));
- ret = 1;
- goto cleanup;
+ if(section->depth >= config_max_recursion) {
+ pm_printf(ALPM_LOG_ERROR,
+ _("config parsing exceeded max recursion depth of %d.\n"),
+ config_max_recursion);
+ return 1;
}
- pm_printf(ALPM_LOG_DEBUG,
- "setting usage of %d for %s repoistory\n",
- section->usage == 0 ? ALPM_DB_USAGE_ALL : section->usage,
- section->name);
- alpm_db_set_usage(db, section->usage == 0 ? ALPM_DB_USAGE_ALL : section->usage);
-
- for(i = section->servers; i; i = alpm_list_next(i)) {
- char *value = i->data;
- if(_add_mirror(db, value) != 0) {
- pm_printf(ALPM_LOG_ERROR,
- _("could not add mirror '%s' to database '%s' (%s)\n"),
- value, section->name, alpm_strerror(alpm_errno(config->handle)));
- ret = 1;
- goto cleanup;
- }
- free(value);
+ section->depth++;
+
+ /* Ignore include failures... assume non-critical */
+ globret = glob(value, GLOB_NOCHECK, NULL, &globbuf);
+ switch(globret) {
+ case GLOB_NOSPACE:
+ pm_printf(ALPM_LOG_DEBUG,
+ "config file %s, line %d: include globbing out of space\n",
+ file, linenum);
+ break;
+ case GLOB_ABORTED:
+ pm_printf(ALPM_LOG_DEBUG,
+ "config file %s, line %d: include globbing read error for %s\n",
+ file, linenum, value);
+ break;
+ case GLOB_NOMATCH:
+ pm_printf(ALPM_LOG_DEBUG,
+ "config file %s, line %d: no include found for %s\n",
+ file, linenum, value);
+ break;
+ default:
+ for(gindex = 0; gindex < globbuf.gl_pathc; gindex++) {
+ pm_printf(ALPM_LOG_DEBUG, "config file %s, line %d: including %s\n",
+ file, linenum, globbuf.gl_pathv[gindex]);
+ ret = parse_ini(globbuf.gl_pathv[gindex], _parse_directive, data);
+ if(ret) {
+ goto cleanup;
+ }
+ }
+ break;
}
cleanup:
- alpm_list_free(section->servers);
- section->servers = NULL;
- section->siglevel = ALPM_SIG_USE_DEFAULT;
- section->name = NULL;
- section->usage = 0;
+ section->depth--;
+ globfree(&globbuf);
return ret;
}
@@ -921,16 +964,27 @@ static int _parse_directive(const char *file, int linenum, const char *name,
char *key, char *value, void *data)
{
struct section_t *section = data;
- if(!key && !value) {
- int ret = finish_section(section);
- pm_printf(ALPM_LOG_DEBUG, "config: new section '%s'\n", name);
+ if(!name && !key && !value) {
+ pm_printf(ALPM_LOG_ERROR, _("config file %s could not be read: %s\n"),
+ file, strerror(errno));
+ return 1;
+ } else if(!key && !value) {
section->name = name;
- if(name && strcmp(name, "options") == 0) {
- section->is_options = 1;
+ pm_printf(ALPM_LOG_DEBUG, "config: new section '%s'\n", name);
+ if(strcmp(name, "options") == 0) {
+ section->repo = NULL;
} else {
- section->is_options = 0;
+ section->repo = calloc(sizeof(config_repo_t), 1);
+ section->repo->name = strdup(name);
+ section->repo->siglevel = ALPM_SIG_USE_DEFAULT;
+ section->repo->usage = 0;
+ config->repos = alpm_list_add(config->repos, section->repo);
}
- return ret;
+ return 0;
+ }
+
+ if(strcmp(key, "Include") == 0) {
+ return process_include(value, data, file, linenum);
}
if(section->name == NULL) {
@@ -939,15 +993,13 @@ static int _parse_directive(const char *file, int linenum, const char *name,
return 1;
}
- if(section->parse_options && section->is_options) {
+ if(!section->repo) {
/* we are either in options ... */
return _parse_options(key, value, file, linenum);
- } else if(!section->parse_options && !section->is_options) {
+ } else {
/* ... or in a repo section */
return _parse_repo(key, value, file, linenum, section);
}
-
- return 0;
}
/** Parse a configuration file.
@@ -959,25 +1011,18 @@ int parseconfig(const char *file)
int ret;
struct section_t section;
memset(&section, 0, sizeof(struct section_t));
- section.siglevel = ALPM_SIG_USE_DEFAULT;
- section.usage = 0;
- /* the config parse is a two-pass affair. We first parse the entire thing for
- * the [options] section so we can get all default and path options set.
- * Next, we go back and parse everything but [options]. */
-
- /* call the real parseconfig function with a null section & db argument */
- pm_printf(ALPM_LOG_DEBUG, "parseconfig: options pass\n");
- section.parse_options = 1;
+ pm_printf(ALPM_LOG_DEBUG, "config: attempting to read file %s\n", file);
if((ret = parse_ini(file, _parse_directive, &section))) {
return ret;
}
+ pm_printf(ALPM_LOG_DEBUG, "config: finished parsing %s\n", file);
if((ret = setup_libalpm())) {
return ret;
}
- /* second pass, repo section parsing */
- pm_printf(ALPM_LOG_DEBUG, "parseconfig: repo pass\n");
- section.parse_options = 0;
- return parse_ini(file, _parse_directive, &section);
+ alpm_list_free_inner(config->repos, (alpm_list_fn_free) config_repo_free);
+ alpm_list_free(config->repos);
+ config->repos = NULL;
+ return ret;
}
/* vim: set noet: */
diff --git a/src/pacman/conf.h b/src/pacman/conf.h
index 3141e2c3..51224524 100644
--- a/src/pacman/conf.h
+++ b/src/pacman/conf.h
@@ -34,6 +34,14 @@ typedef struct __colstr_t {
const char *nocolor;
} colstr_t;
+typedef struct __config_repo_t {
+ char *name;
+ alpm_list_t *servers;
+ alpm_db_usage_t usage;
+ alpm_siglevel_t siglevel;
+ alpm_siglevel_t siglevel_mask;
+} config_repo_t;
+
typedef struct __config_t {
unsigned short op;
unsigned short quiet;
@@ -88,6 +96,10 @@ typedef struct __config_t {
alpm_siglevel_t localfilesiglevel;
alpm_siglevel_t remotefilesiglevel;
+ alpm_siglevel_t siglevel_mask;
+ alpm_siglevel_t localfilesiglevel_mask;
+ alpm_siglevel_t remotefilesiglevel_mask;
+
/* conf file options */
/* I Love Candy! */
unsigned short chomp;
@@ -114,6 +126,8 @@ typedef struct __config_t {
/* Color strings for output */
colstr_t colstr;
+
+ alpm_list_t *repos;
} config_t;
/* Operations */
@@ -208,6 +222,8 @@ void enable_colors(int colors);
config_t *config_new(void);
int config_free(config_t *oldconfig);
+void config_repo_free(config_repo_t *repo);
+
int config_set_arch(const char *arch);
int parseconfig(const char *file);
#endif /* _PM_CONF_H */
diff --git a/src/pacman/database.c b/src/pacman/database.c
index e858e0c8..7c396bc7 100644
--- a/src/pacman/database.c
+++ b/src/pacman/database.c
@@ -18,6 +18,9 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
+#include <dirent.h>
+#include <errno.h>
+#include <limits.h>
#include <stdio.h>
#include <alpm.h>
@@ -35,11 +38,12 @@
*
* @return 0 on success, 1 on failure
*/
-int pacman_database(alpm_list_t *targets)
+static int change_install_reason(alpm_list_t *targets)
{
alpm_list_t *i;
alpm_db_t *db_local;
- int retval = 0;
+ int ret = 0;
+
alpm_pkgreason_t reason;
if(targets == NULL) {
@@ -68,7 +72,7 @@ int pacman_database(alpm_list_t *targets)
if(!pkg || alpm_pkg_set_reason(pkg, reason)) {
pm_printf(ALPM_LOG_ERROR, _("could not set install reason for package %s (%s)\n"),
pkgname, alpm_strerror(alpm_errno(config->handle)));
- retval = 1;
+ ret = 1;
} else {
if(reason == ALPM_PKG_REASON_DEPEND) {
printf(_("%s: install reason has been set to 'installed as dependency'\n"), pkgname);
@@ -82,7 +86,213 @@ int pacman_database(alpm_list_t *targets)
if(trans_release() == -1) {
return 1;
}
- return retval;
+ return ret;
+}
+
+static int check_db_missing_deps(alpm_list_t *pkglist)
+{
+ alpm_list_t *data, *i;
+ int ret = 0;
+ /* check dependencies */
+ data = alpm_checkdeps(config->handle, NULL, NULL, pkglist, 0);
+ for(i = data; i; i = alpm_list_next(i)) {
+ alpm_depmissing_t *miss = i->data;
+ char *depstring = alpm_dep_compute_string(miss->depend);
+ pm_printf(ALPM_LOG_ERROR, "missing '%s' dependency for '%s'\n",
+ depstring, miss->target);
+ free(depstring);
+ ret++;
+ }
+ FREELIST(data);
+ return ret;
+}
+
+static int check_db_local_files(void)
+{
+ struct dirent *ent;
+ const char *dbpath;
+ char path[PATH_MAX];
+ int ret = 0;
+ DIR *dbdir;
+
+ dbpath = alpm_option_get_dbpath(config->handle);
+ snprintf(path, PATH_MAX, "%slocal", dbpath);
+ if(!(dbdir = opendir(path))) {
+ pm_printf(ALPM_LOG_ERROR, "could not open local database directory %s: %s\n",
+ path, strerror(errno));
+ return 1;
+ }
+
+ while((ent = readdir(dbdir)) != NULL) {
+ if(strcmp(ent->d_name, ".") == 0 || strcmp(ent->d_name, "..") == 0
+ || strcmp(ent->d_name, "ALPM_DB_VERSION") == 0) {
+ continue;
+ }
+ /* check for expected db files in local database */
+ snprintf(path, PATH_MAX, "%slocal/%s/desc", dbpath, ent->d_name);
+ if(access(path, F_OK)) {
+ pm_printf(ALPM_LOG_ERROR, "'%s': description file is missing\n", ent->d_name);
+ ret++;
+ }
+ snprintf(path, PATH_MAX, "%slocal/%s/files", dbpath, ent->d_name);
+ if(access(path, F_OK)) {
+ pm_printf(ALPM_LOG_ERROR, "'%s': file list is missing\n", ent->d_name);
+ ret++;
+ }
+ }
+ closedir(dbdir);
+
+ return ret;
+}
+
+static int check_db_local_package_conflicts(alpm_list_t *pkglist)
+{
+ alpm_list_t *data, *i;
+ int ret = 0;
+ /* check conflicts */
+ data = alpm_checkconflicts(config->handle, pkglist);
+ for(i = data; i; i = i->next) {
+ alpm_conflict_t *conflict = i->data;
+ pm_printf(ALPM_LOG_ERROR, "'%s' conflicts with '%s'\n",
+ conflict->package1, conflict->package2);
+ ret++;
+ }
+ FREELIST(data);
+ return ret;
+}
+
+struct fileitem {
+ alpm_file_t *file;
+ alpm_pkg_t *pkg;
+};
+
+static int fileitem_cmp(const void *p1, const void *p2)
+{
+ const struct fileitem * fi1 = p1;
+ const struct fileitem * fi2 = p2;
+ return strcmp(fi1->file->name, fi2->file->name);
+}
+
+static int check_db_local_filelist_conflicts(alpm_list_t *pkglist)
+{
+ alpm_list_t *i;
+ int ret = 0;
+ size_t list_size = 4096;
+ size_t offset = 0, j;
+ struct fileitem *all_files;
+ struct fileitem *prev_fileitem = NULL;
+
+ all_files = malloc(list_size * sizeof(struct fileitem));
+
+ for(i = pkglist; i; i = i->next) {
+ alpm_pkg_t *pkg = i->data;
+ alpm_filelist_t *filelist = alpm_pkg_get_files(pkg);
+ for(j = 0; j < filelist->count; j++) {
+ alpm_file_t *file = filelist->files + j;
+ /* only add files, not directories, to our big list */
+ if(file->name[strlen(file->name) - 1] == '/') {
+ continue;
+ }
+
+ /* do we need to reallocate and grow our array? */
+ if(offset >= list_size) {
+ struct fileitem *new_files;
+ new_files = realloc(all_files, list_size * 2 * sizeof(struct fileitem));
+ if(!new_files) {
+ free(all_files);
+ return 1;
+ }
+ all_files = new_files;
+ list_size *= 2;
+ }
+
+ /* we can finally add it to the list */
+ all_files[offset].file = file;
+ all_files[offset].pkg = pkg;
+ offset++;
+ }
+ }
+
+ /* now sort the list so we can find duplicates */
+ qsort(all_files, offset, sizeof(struct fileitem), fileitem_cmp);
+
+ /* do a 'uniq' style check on the list */
+ for(j = 0; j < offset; j++) {
+ struct fileitem *fileitem = all_files + j;
+ if(prev_fileitem && fileitem_cmp(prev_fileitem, fileitem) == 0) {
+ pm_printf(ALPM_LOG_ERROR, "file owned by '%s' and '%s': '%s'\n",
+ alpm_pkg_get_name(prev_fileitem->pkg),
+ alpm_pkg_get_name(fileitem->pkg),
+ fileitem->file->name);
+ }
+ prev_fileitem = fileitem;
+ }
+
+ free(all_files);
+ return ret;
+}
+
+/**
+ * @brief Check 'local' package database for consistency
+ *
+ * @return 0 on success, >=1 on failure
+ */
+static int check_db_local(void) {
+ int ret = 0;
+ alpm_db_t *db = NULL;
+ alpm_list_t *pkglist;
+
+ ret = check_db_local_files();
+ if(ret) {
+ return ret;
+ }
+
+ db = alpm_get_localdb(config->handle);
+ pkglist = alpm_db_get_pkgcache(db);
+ ret += check_db_missing_deps(pkglist);
+ ret += check_db_local_package_conflicts(pkglist);
+ ret += check_db_local_filelist_conflicts(pkglist);
+
+ return 0;
+}
+
+/**
+ * @brief Check 'sync' package databases for consistency
+ *
+ * @return 0 on success, >=1 on failure
+ */
+static int check_db_sync(void) {
+ int ret = 0;
+ alpm_list_t *i, *dblist, *pkglist, *syncpkglist = NULL;
+
+ dblist = alpm_get_syncdbs(config->handle);
+ for(i = dblist; i; i = alpm_list_next(i)) {
+ pkglist = alpm_db_get_pkgcache(i->data);
+ syncpkglist = alpm_list_join(syncpkglist, alpm_list_copy(pkglist));
+ }
+ ret = check_db_missing_deps(syncpkglist);
+
+ alpm_list_free(syncpkglist);
+ return ret;
+}
+
+int pacman_database(alpm_list_t *targets)
+{
+ int ret = 0;
+
+ if(config->op_q_check) {
+ if(config->op_q_check == 1) {
+ ret = check_db_local();
+ } else {
+ ret = check_db_sync();
+ }
+ }
+
+ if(config->flags & (ALPM_TRANS_FLAG_ALLDEPS | ALPM_TRANS_FLAG_ALLEXPLICIT)) {
+ ret = change_install_reason(targets);
+ }
+
+ return ret;
}
/* vim: set noet: */
diff --git a/src/pacman/ini.c b/src/pacman/ini.c
index 2eb32302..ca1363f1 100644
--- a/src/pacman/ini.c
+++ b/src/pacman/ini.c
@@ -18,7 +18,6 @@
*/
#include <errno.h>
-#include <glob.h>
#include <limits.h>
#include <string.h> /* strdup */
@@ -27,43 +26,38 @@
#include "ini.h"
#include "util.h"
-static const int ini_max_recursion = 10;
-
/**
- * @brief INI parser backend.
+ * @brief Parse a pacman-style INI config file.
*
* @param file path to the config file
* @param cb callback for key/value pairs
* @param data caller defined data to be passed to the callback
- * @param section_name the name of the current section
- * @param line buffer to read into, must be at least PATH_MAX long
- * @param depth recursion depth, should initially be 0
*
- * @return 0 on success, 1 on parsing errors, the callback return value
- * otherwise
+ * @return the callback return value
+ *
+ * @note The callback will be called at the beginning of each section with an
+ * empty key and value and for each key/value pair.
+ *
+ * @note If the parser encounters an error the callback will be called with
+ * section, key, and value set to NULL and errno set by fopen, fgets, or
+ * strdup.
+ *
+ * @note The @a key and @a value passed to @ cb will be overwritten between
+ * calls. The section name will remain valid until after @a cb is called to
+ * begin a new section.
+ *
+ * @note Parsing will immediately stop if the callback returns non-zero.
*/
-static int _parse_ini(const char *file, ini_parser_fn cb, void *data,
- char **section_name, char *line, int depth)
+int parse_ini(const char *file, ini_parser_fn cb, void *data)
{
+ char line[PATH_MAX], *section_name = NULL;
FILE *fp = NULL;
int linenum = 0;
int ret = 0;
- if(depth >= ini_max_recursion) {
- pm_printf(ALPM_LOG_ERROR,
- _("config parsing exceeded max recursion depth of %d.\n"),
- ini_max_recursion);
- ret = 1;
- goto cleanup;
- }
-
- pm_printf(ALPM_LOG_DEBUG, "config: attempting to read file %s\n", file);
fp = fopen(file, "r");
if(fp == NULL) {
- pm_printf(ALPM_LOG_ERROR, _("config file %s could not be read: %s\n"),
- file, strerror(errno));
- ret = 1;
- goto cleanup;
+ return cb(file, 0, NULL, NULL, NULL, data);
}
while(safe_fgets(line, PATH_MAX, fp)) {
@@ -85,20 +79,13 @@ static int _parse_ini(const char *file, ini_parser_fn cb, void *data,
if(line[0] == '[' && line[line_len - 1] == ']') {
char *name;
- /* only possibility here is a line == '[]' */
- if(line_len <= 2) {
- pm_printf(ALPM_LOG_ERROR, _("config file %s, line %d: bad section name.\n"),
- file, linenum);
- ret = 1;
- goto cleanup;
- }
/* new config section, skip the '[' */
name = strdup(line + 1);
name[line_len - 2] = '\0';
ret = cb(file, linenum, name, NULL, NULL, data);
- free(*section_name);
- *section_name = name;
+ free(section_name);
+ section_name = name;
/* we're at a new section; perform any post-actions for the prior */
if(ret) {
@@ -115,103 +102,15 @@ static int _parse_ini(const char *file, ini_parser_fn cb, void *data,
strtrim(key);
strtrim(value);
- if(key == NULL) {
- pm_printf(ALPM_LOG_ERROR, _("config file %s, line %d: syntax error in config file- missing key.\n"),
- file, linenum);
- ret = 1;
- goto cleanup;
- }
- /* Include is allowed in both options and repo sections */
- if(strcmp(key, "Include") == 0) {
- glob_t globbuf;
- int globret;
- size_t gindex;
-
- if(value == NULL) {
- pm_printf(ALPM_LOG_ERROR, _("config file %s, line %d: directive '%s' needs a value\n"),
- file, linenum, key);
- ret = 1;
- goto cleanup;
- }
- /* Ignore include failures... assume non-critical */
- globret = glob(value, GLOB_NOCHECK, NULL, &globbuf);
- switch(globret) {
- case GLOB_NOSPACE:
- pm_printf(ALPM_LOG_DEBUG,
- "config file %s, line %d: include globbing out of space\n",
- file, linenum);
- break;
- case GLOB_ABORTED:
- pm_printf(ALPM_LOG_DEBUG,
- "config file %s, line %d: include globbing read error for %s\n",
- file, linenum, value);
- break;
- case GLOB_NOMATCH:
- pm_printf(ALPM_LOG_DEBUG,
- "config file %s, line %d: no include found for %s\n",
- file, linenum, value);
- break;
- default:
- for(gindex = 0; gindex < globbuf.gl_pathc; gindex++) {
- pm_printf(ALPM_LOG_DEBUG, "config file %s, line %d: including %s\n",
- file, linenum, globbuf.gl_pathv[gindex]);
- ret =_parse_ini(globbuf.gl_pathv[gindex], cb, data,
- section_name, line, depth + 1);
- if(ret) {
- globfree(&globbuf);
- goto cleanup;
- }
- }
- break;
- }
- globfree(&globbuf);
- continue;
- }
- if((ret = cb(file, linenum, *section_name, key, value, data)) != 0) {
+ if((ret = cb(file, linenum, section_name, key, value, data)) != 0) {
goto cleanup;
}
}
- if(depth == 0) {
- ret = cb(NULL, 0, NULL, NULL, NULL, data);
- }
-
cleanup:
- if(fp) {
- fclose(fp);
- }
- if(depth == 0) {
- free(*section_name);
- *section_name = NULL;
- }
- pm_printf(ALPM_LOG_DEBUG, "config: finished parsing %s\n", file);
+ fclose(fp);
+ free(section_name);
return ret;
}
-/**
- * @brief Parse a pacman-style INI config file.
- *
- * @param file path to the config file
- * @param cb callback for key/value pairs
- * @param data caller defined data to be passed to the callback
- *
- * @return 0 on success, 1 on parsing errors, the callback return value
- * otherwise
- *
- * @note The callback will be called at the beginning of each section with an
- * empty key and value, for each key/value pair, and when parsing is complete
- * with all arguments except @a data empty.
- *
- * @note The @a key and @a value passed to @ cb will be overwritten between
- * calls. The section name will remain valid until after @a cb is called to
- * begin a new section.
- *
- * @note Parsing will immediately stop if the callback returns non-zero.
- */
-int parse_ini(const char *file, ini_parser_fn cb, void *data)
-{
- char *section_name = NULL, line[PATH_MAX];
- return _parse_ini(file, cb, data, &section_name, line, 0);
-}
-
/* vim: set noet: */
diff --git a/src/pacman/pacman.c b/src/pacman/pacman.c
index 6f05c68c..792c9946 100644
--- a/src/pacman/pacman.c
+++ b/src/pacman/pacman.c
@@ -169,6 +169,7 @@ static void usage(int op, const char * const myname)
printf("%s:\n", str_opt);
addlist(_(" --asdeps mark packages as non-explicitly installed\n"));
addlist(_(" --asexplicit mark packages as explicitly installed\n"));
+ addlist(_(" -k, --check test local database for validity (-kk for sync databases)\n"));
} else if(op == PM_OP_DEPTEST) {
printf("%s: %s {-T --deptest} [%s] [%s]\n", str_usg, myname, str_opt, str_pkg);
printf("%s:\n", str_opt);
@@ -484,9 +485,18 @@ static int parsearg_global(int opt)
static int parsearg_database(int opt)
{
switch(opt) {
- case OP_ASDEPS: config->flags |= ALPM_TRANS_FLAG_ALLDEPS; break;
- case OP_ASEXPLICIT: config->flags |= ALPM_TRANS_FLAG_ALLEXPLICIT; break;
- default: return 1;
+ case OP_ASDEPS:
+ config->flags |= ALPM_TRANS_FLAG_ALLDEPS;
+ break;
+ case OP_ASEXPLICIT:
+ config->flags |= ALPM_TRANS_FLAG_ALLEXPLICIT;
+ break;
+ case OP_CHECK:
+ case 'k':
+ (config->op_q_check)++;
+ break;
+ default:
+ return 1;
}
return 0;
}
@@ -496,6 +506,13 @@ static void checkargs_database(void)
invalid_opt(config->flags & ALPM_TRANS_FLAG_ALLDEPS
&& config->flags & ALPM_TRANS_FLAG_ALLEXPLICIT,
"--asdeps", "--asexplicit");
+
+ if(config->op_q_check) {
+ invalid_opt(config->flags & ALPM_TRANS_FLAG_ALLDEPS,
+ "--asdeps", "--check");
+ invalid_opt(config->flags & ALPM_TRANS_FLAG_ALLEXPLICIT,
+ "--asexplicit", "--check");
+ }
}
static int parsearg_query(int opt)
diff --git a/src/pacman/util.c b/src/pacman/util.c
index 36f4414a..8720ba11 100644
--- a/src/pacman/util.c
+++ b/src/pacman/util.c
@@ -105,7 +105,7 @@ int needs_root(void)
{
switch(config->op) {
case PM_OP_DATABASE:
- return 1;
+ return !config->op_q_check;
case PM_OP_UPGRADE:
case PM_OP_REMOVE:
return !config->print;
@@ -284,6 +284,7 @@ void indentprint(const char *str, unsigned short indent, unsigned short cols)
cidx = indent;
if(!p || !len) {
+ free(wcstr);
return;
}