diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/common/util-common.c | 2 | ||||
-rw-r--r-- | src/common/util-common.h | 2 | ||||
-rw-r--r-- | src/pacman/callback.c | 22 | ||||
-rw-r--r-- | src/pacman/callback.h | 2 | ||||
-rw-r--r-- | src/pacman/check.c | 2 | ||||
-rw-r--r-- | src/pacman/check.h | 2 | ||||
-rw-r--r-- | src/pacman/conf.c | 309 | ||||
-rw-r--r-- | src/pacman/conf.h | 18 | ||||
-rw-r--r-- | src/pacman/database.c | 220 | ||||
-rw-r--r-- | src/pacman/deptest.c | 2 | ||||
-rw-r--r-- | src/pacman/ini.c | 149 | ||||
-rw-r--r-- | src/pacman/ini.h | 2 | ||||
-rw-r--r-- | src/pacman/package.c | 2 | ||||
-rw-r--r-- | src/pacman/package.h | 2 | ||||
-rw-r--r-- | src/pacman/pacman.c | 27 | ||||
-rw-r--r-- | src/pacman/pacman.h | 2 | ||||
-rw-r--r-- | src/pacman/query.c | 2 | ||||
-rw-r--r-- | src/pacman/remove.c | 2 | ||||
-rw-r--r-- | src/pacman/sync.c | 2 | ||||
-rw-r--r-- | src/pacman/upgrade.c | 2 | ||||
-rw-r--r-- | src/pacman/util.c | 5 | ||||
-rw-r--r-- | src/pacman/util.h | 2 | ||||
-rw-r--r-- | src/util/.gitignore | 2 | ||||
-rw-r--r-- | src/util/Makefile.am | 5 | ||||
-rw-r--r-- | src/util/cleanupdelta.c | 2 | ||||
-rw-r--r-- | src/util/pacsort.c | 3 | ||||
-rw-r--r-- | src/util/pactree.c | 2 | ||||
-rw-r--r-- | src/util/testdb.c | 297 | ||||
-rw-r--r-- | src/util/testpkg.c | 2 | ||||
-rw-r--r-- | src/util/vercmp.c | 2 |
30 files changed, 484 insertions, 611 deletions
diff --git a/src/common/util-common.c b/src/common/util-common.c index ab74e7c6..f5b00f17 100644 --- a/src/common/util-common.c +++ b/src/common/util-common.c @@ -1,7 +1,7 @@ /* * util-common.c * - * Copyright (c) 2006-2014 Pacman Development Team <pacman-dev@archlinux.org> + * Copyright (c) 2006-2015 Pacman Development Team <pacman-dev@archlinux.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 diff --git a/src/common/util-common.h b/src/common/util-common.h index ca8db5ab..a2093bef 100644 --- a/src/common/util-common.h +++ b/src/common/util-common.h @@ -1,7 +1,7 @@ /* * util-common.h * - * Copyright (c) 2006-2014 Pacman Development Team <pacman-dev@archlinux.org> + * Copyright (c) 2006-2015 Pacman Development Team <pacman-dev@archlinux.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 diff --git a/src/pacman/callback.c b/src/pacman/callback.c index 4993382d..695e38d4 100644 --- a/src/pacman/callback.c +++ b/src/pacman/callback.c @@ -1,7 +1,7 @@ /* * callback.c * - * Copyright (c) 2006-2014 Pacman Development Team <pacman-dev@archlinux.org> + * Copyright (c) 2006-2015 Pacman Development Team <pacman-dev@archlinux.org> * Copyright (c) 2002-2006 by Judd Vinet <jvinet@zeroflux.org> * * This program is free software; you can redistribute it and/or modify @@ -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/callback.h b/src/pacman/callback.h index 498536fe..a0e9e120 100644 --- a/src/pacman/callback.h +++ b/src/pacman/callback.h @@ -1,7 +1,7 @@ /* * callback.h * - * Copyright (c) 2006-2014 Pacman Development Team <pacman-dev@archlinux.org> + * Copyright (c) 2006-2015 Pacman Development Team <pacman-dev@archlinux.org> * Copyright (c) 2002-2006 by Judd Vinet <jvinet@zeroflux.org> * * This program is free software; you can redistribute it and/or modify diff --git a/src/pacman/check.c b/src/pacman/check.c index 628e79de..74d17ce1 100644 --- a/src/pacman/check.c +++ b/src/pacman/check.c @@ -1,7 +1,7 @@ /* * check.c * - * Copyright (c) 2012-2014 Pacman Development Team <pacman-dev@archlinux.org> + * Copyright (c) 2012-2015 Pacman Development Team <pacman-dev@archlinux.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 diff --git a/src/pacman/check.h b/src/pacman/check.h index c2940dd3..fc129b48 100644 --- a/src/pacman/check.h +++ b/src/pacman/check.h @@ -1,7 +1,7 @@ /* * check.h * - * Copyright (c) 2012-2014 Pacman Development Team <pacman-dev@archlinux.org> + * Copyright (c) 2012-2015 Pacman Development Team <pacman-dev@archlinux.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 diff --git a/src/pacman/conf.c b/src/pacman/conf.c index 873ca0ee..ccf8183d 100644 --- a/src/pacman/conf.c +++ b/src/pacman/conf.c @@ -1,7 +1,7 @@ /* * conf.c * - * Copyright (c) 2006-2014 Pacman Development Team <pacman-dev@archlinux.org> + * Copyright (c) 2006-2015 Pacman Development Team <pacman-dev@archlinux.org> * Copyright (c) 2002-2006 by Judd Vinet <jvinet@zeroflux.org> * * This program is free software; you can redistribute it and/or modify @@ -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, §ion->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, §ion->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(§ion, 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, §ion))) { 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, §ion); + 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..d6feb7ac 100644 --- a/src/pacman/conf.h +++ b/src/pacman/conf.h @@ -1,7 +1,7 @@ /* * conf.h * - * Copyright (c) 2006-2014 Pacman Development Team <pacman-dev@archlinux.org> + * Copyright (c) 2006-2015 Pacman Development Team <pacman-dev@archlinux.org> * Copyright (c) 2002-2006 by Judd Vinet <jvinet@zeroflux.org> * * This program is free software; you can redistribute it and/or modify @@ -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..abc3fd28 100644 --- a/src/pacman/database.c +++ b/src/pacman/database.c @@ -1,7 +1,7 @@ /* * database.c * - * Copyright (c) 2006-2014 Pacman Development Team <pacman-dev@archlinux.org> + * Copyright (c) 2006-2015 Pacman Development Team <pacman-dev@archlinux.org> * Copyright (c) 2002-2006 by Judd Vinet <jvinet@zeroflux.org> * * This program is free software; you can redistribute it and/or modify @@ -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/deptest.c b/src/pacman/deptest.c index 511c398d..a43d1797 100644 --- a/src/pacman/deptest.c +++ b/src/pacman/deptest.c @@ -1,7 +1,7 @@ /* * deptest.c * - * Copyright (c) 2006-2014 Pacman Development Team <pacman-dev@archlinux.org> + * Copyright (c) 2006-2015 Pacman Development Team <pacman-dev@archlinux.org> * Copyright (c) 2002-2006 by Judd Vinet <jvinet@zeroflux.org> * * This program is free software; you can redistribute it and/or modify diff --git a/src/pacman/ini.c b/src/pacman/ini.c index 2eb32302..fed0b187 100644 --- a/src/pacman/ini.c +++ b/src/pacman/ini.c @@ -1,7 +1,7 @@ /* * ini.c * - * Copyright (c) 2013-2014 Pacman Development Team <pacman-dev@archlinux.org> + * Copyright (c) 2013-2015 Pacman Development Team <pacman-dev@archlinux.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 @@ -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, §ion_name, line, 0); -} - /* vim: set noet: */ diff --git a/src/pacman/ini.h b/src/pacman/ini.h index 23786a09..e85a505d 100644 --- a/src/pacman/ini.h +++ b/src/pacman/ini.h @@ -1,7 +1,7 @@ /* * ini.h * - * Copyright (c) 2013-2014 Pacman Development Team <pacman-dev@archlinux.org> + * Copyright (c) 2013-2015 Pacman Development Team <pacman-dev@archlinux.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 diff --git a/src/pacman/package.c b/src/pacman/package.c index 1ac0fcae..14a7b9f0 100644 --- a/src/pacman/package.c +++ b/src/pacman/package.c @@ -1,7 +1,7 @@ /* * package.c * - * Copyright (c) 2006-2014 Pacman Development Team <pacman-dev@archlinux.org> + * Copyright (c) 2006-2015 Pacman Development Team <pacman-dev@archlinux.org> * Copyright (c) 2002-2006 by Judd Vinet <jvinet@zeroflux.org> * * This program is free software; you can redistribute it and/or modify diff --git a/src/pacman/package.h b/src/pacman/package.h index a6f02b97..4860d577 100644 --- a/src/pacman/package.h +++ b/src/pacman/package.h @@ -1,7 +1,7 @@ /* * package.h * - * Copyright (c) 2006-2014 Pacman Development Team <pacman-dev@archlinux.org> + * Copyright (c) 2006-2015 Pacman Development Team <pacman-dev@archlinux.org> * Copyright (c) 2002-2006 by Judd Vinet <jvinet@zeroflux.org> * * This program is free software; you can redistribute it and/or modify diff --git a/src/pacman/pacman.c b/src/pacman/pacman.c index 6f05c68c..fce0131c 100644 --- a/src/pacman/pacman.c +++ b/src/pacman/pacman.c @@ -1,7 +1,7 @@ /* * pacman.c * - * Copyright (c) 2006-2014 Pacman Development Team <pacman-dev@archlinux.org> + * Copyright (c) 2006-2015 Pacman Development Team <pacman-dev@archlinux.org> * Copyright (c) 2002-2006 by Judd Vinet <jvinet@zeroflux.org> * * This program is free software; you can redistribute it and/or modify @@ -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); @@ -223,7 +224,7 @@ static void version(void) { printf("\n"); printf(" .--. Pacman v%s - libalpm v%s\n", PACKAGE_VERSION, alpm_version()); - printf("/ _.-' .-. .-. .-. Copyright (C) 2006-2014 Pacman Development Team\n"); + printf("/ _.-' .-. .-. .-. Copyright (C) 2006-2015 Pacman Development Team\n"); printf("\\ '-. '-' '-' '-' Copyright (C) 2002-2006 Judd Vinet\n"); printf(" '--'\n"); printf(_(" This program may be freely redistributed under\n" @@ -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/pacman.h b/src/pacman/pacman.h index 7b33a74e..ddf6e62a 100644 --- a/src/pacman/pacman.h +++ b/src/pacman/pacman.h @@ -1,7 +1,7 @@ /* * pacman.h * - * Copyright (c) 2006-2014 Pacman Development Team <pacman-dev@archlinux.org> + * Copyright (c) 2006-2015 Pacman Development Team <pacman-dev@archlinux.org> * Copyright (c) 2002-2006 by Judd Vinet <jvinet@zeroflux.org> * * This program is free software; you can redistribute it and/or modify diff --git a/src/pacman/query.c b/src/pacman/query.c index 477e4fed..f7570156 100644 --- a/src/pacman/query.c +++ b/src/pacman/query.c @@ -1,7 +1,7 @@ /* * query.c * - * Copyright (c) 2006-2014 Pacman Development Team <pacman-dev@archlinux.org> + * Copyright (c) 2006-2015 Pacman Development Team <pacman-dev@archlinux.org> * Copyright (c) 2002-2006 by Judd Vinet <jvinet@zeroflux.org> * * This program is free software; you can redistribute it and/or modify diff --git a/src/pacman/remove.c b/src/pacman/remove.c index 38ad2a29..069f2363 100644 --- a/src/pacman/remove.c +++ b/src/pacman/remove.c @@ -1,7 +1,7 @@ /* * remove.c * - * Copyright (c) 2006-2014 Pacman Development Team <pacman-dev@archlinux.org> + * Copyright (c) 2006-2015 Pacman Development Team <pacman-dev@archlinux.org> * Copyright (c) 2002-2006 by Judd Vinet <jvinet@zeroflux.org> * * This program is free software; you can redistribute it and/or modify diff --git a/src/pacman/sync.c b/src/pacman/sync.c index 215497f6..91eca7e4 100644 --- a/src/pacman/sync.c +++ b/src/pacman/sync.c @@ -1,7 +1,7 @@ /* * sync.c * - * Copyright (c) 2006-2014 Pacman Development Team <pacman-dev@archlinux.org> + * Copyright (c) 2006-2015 Pacman Development Team <pacman-dev@archlinux.org> * Copyright (c) 2002-2006 by Judd Vinet <jvinet@zeroflux.org> * * This program is free software; you can redistribute it and/or modify diff --git a/src/pacman/upgrade.c b/src/pacman/upgrade.c index a6be0e18..a3faf7ac 100644 --- a/src/pacman/upgrade.c +++ b/src/pacman/upgrade.c @@ -1,7 +1,7 @@ /* * upgrade.c * - * Copyright (c) 2006-2014 Pacman Development Team <pacman-dev@archlinux.org> + * Copyright (c) 2006-2015 Pacman Development Team <pacman-dev@archlinux.org> * Copyright (c) 2002-2006 by Judd Vinet <jvinet@zeroflux.org> * * This program is free software; you can redistribute it and/or modify diff --git a/src/pacman/util.c b/src/pacman/util.c index 36f4414a..5d683608 100644 --- a/src/pacman/util.c +++ b/src/pacman/util.c @@ -1,7 +1,7 @@ /* * util.c * - * Copyright (c) 2006-2014 Pacman Development Team <pacman-dev@archlinux.org> + * Copyright (c) 2006-2015 Pacman Development Team <pacman-dev@archlinux.org> * Copyright (c) 2002-2006 by Judd Vinet <jvinet@zeroflux.org> * * This program is free software; you can redistribute it and/or modify @@ -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; } diff --git a/src/pacman/util.h b/src/pacman/util.h index b591fbaf..fda9b51a 100644 --- a/src/pacman/util.h +++ b/src/pacman/util.h @@ -1,7 +1,7 @@ /* * util.h * - * Copyright (c) 2006-2014 Pacman Development Team <pacman-dev@archlinux.org> + * Copyright (c) 2006-2015 Pacman Development Team <pacman-dev@archlinux.org> * Copyright (c) 2002-2006 by Judd Vinet <jvinet@zeroflux.org> * * This program is free software; you can redistribute it and/or modify diff --git a/src/util/.gitignore b/src/util/.gitignore index 1813506b..202fb753 100644 --- a/src/util/.gitignore +++ b/src/util/.gitignore @@ -6,8 +6,6 @@ pacsort pacsort.exe pactree pactree.exe -testdb -testdb.exe testpkg testpkg.exe vercmp diff --git a/src/util/Makefile.am b/src/util/Makefile.am index a0075887..25c025b5 100644 --- a/src/util/Makefile.am +++ b/src/util/Makefile.am @@ -4,7 +4,7 @@ dbpath = ${localstatedir}/lib/pacman/ gpgdir = ${sysconfdir}/pacman.d/gnupg/ cachedir = ${localstatedir}/cache/pacman/pkg/ -bin_PROGRAMS = vercmp testpkg testdb cleanupdelta pacsort pactree +bin_PROGRAMS = vercmp testpkg cleanupdelta pacsort pactree AM_CPPFLAGS = \ -imacros $(top_builddir)/config.h \ @@ -26,9 +26,6 @@ pacsort_LDADD = $(top_builddir)/lib/libalpm/.libs/libalpm.la pactree_SOURCES = pactree.c pactree_LDADD = $(top_builddir)/lib/libalpm/.libs/libalpm.la -testdb_SOURCES = testdb.c -testdb_LDADD = $(top_builddir)/lib/libalpm/.libs/libalpm.la - testpkg_SOURCES = testpkg.c testpkg_LDADD = $(top_builddir)/lib/libalpm/.libs/libalpm.la diff --git a/src/util/cleanupdelta.c b/src/util/cleanupdelta.c index 4a67fc38..8fe14b08 100644 --- a/src/util/cleanupdelta.c +++ b/src/util/cleanupdelta.c @@ -1,7 +1,7 @@ /* * cleanupdelta.c : return list of unused delta in a given sync database * - * Copyright (c) 2011-2014 Pacman Development Team <pacman-dev@archlinux.org> + * Copyright (c) 2011-2015 Pacman Development Team <pacman-dev@archlinux.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 diff --git a/src/util/pacsort.c b/src/util/pacsort.c index 665f2180..02b9084b 100644 --- a/src/util/pacsort.c +++ b/src/util/pacsort.c @@ -1,7 +1,7 @@ /* * pacsort.c - a sort utility implementing alpm_pkg_vercmp * - * Copyright (c) 2010-2014 Pacman Development Team <pacman-dev@archlinux.org> + * Copyright (c) 2010-2015 Pacman Development Team <pacman-dev@archlinux.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 @@ -227,6 +227,7 @@ static struct input_t *input_new(const char *path, int pathlen) in->data = strndup(path, pathlen); if(in->data == NULL) { + free(in); return NULL; } diff --git a/src/util/pactree.c b/src/util/pactree.c index 14579e42..67f456fe 100644 --- a/src/util/pactree.c +++ b/src/util/pactree.c @@ -1,7 +1,7 @@ /* * pactree.c - a simple dependency tree viewer * - * Copyright (c) 2010-2014 Pacman Development Team <pacman-dev@archlinux.org> + * Copyright (c) 2010-2015 Pacman Development Team <pacman-dev@archlinux.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 diff --git a/src/util/testdb.c b/src/util/testdb.c deleted file mode 100644 index cd8c4d83..00000000 --- a/src/util/testdb.c +++ /dev/null @@ -1,297 +0,0 @@ -/* - * testdb.c : Test a pacman local database for validity - * - * Copyright (c) 2007-2014 Pacman Development Team <pacman-dev@archlinux.org> - * Copyright (c) 2007 by Aaron Griffin <aaronmgriffin@gmail.com> - * - * 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 - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#include <unistd.h> -#include <stdio.h> -#include <stdlib.h> -#include <errno.h> -#include <string.h> -#include <dirent.h> - -#include <alpm.h> -#include <alpm_list.h> - -alpm_handle_t *handle = NULL; - -static void cleanup(int signum) -{ - if(handle && alpm_release(handle) == -1) { - fprintf(stderr, "error releasing alpm\n"); - } - - exit(signum); -} - -__attribute__((format(printf, 2, 0))) -static void output_cb(alpm_loglevel_t level, const char *fmt, va_list args) -{ - if(strlen(fmt)) { - switch(level) { - case ALPM_LOG_ERROR: printf("error: "); break; - case ALPM_LOG_WARNING: printf("warning: "); break; - default: return; - } - vprintf(fmt, args); - } -} - -static int check_localdb_files(void) -{ - struct dirent *ent; - const char *dbpath; - char path[4096]; - int ret = 0; - DIR *dir; - - dbpath = alpm_option_get_dbpath(handle); - snprintf(path, sizeof(path), "%slocal", dbpath); - if(!(dir = opendir(path))) { - fprintf(stderr, "error : '%s' : %s\n", path, strerror(errno)); - return 1; - } - - while((ent = readdir(dir)) != NULL) { - if(strcmp(ent->d_name, ".") == 0 || strcmp(ent->d_name, "..") == 0 - || strcmp(ent->d_name, "ALPM_DB_VERSION") == 0) { - continue; - } - /* check for known db files in local database */ - snprintf(path, sizeof(path), "%slocal/%s/desc", dbpath, ent->d_name); - if(access(path, F_OK)) { - printf("'%s': description file is missing\n", ent->d_name); - ret++; - } - snprintf(path, sizeof(path), "%slocal/%s/files", dbpath, ent->d_name); - if(access(path, F_OK)) { - printf("'%s': file list is missing\n", ent->d_name); - ret++; - } - } - if(closedir(dir)) { - fprintf(stderr, "error closing dbpath : %s\n", strerror(errno)); - return 1; - } - - return ret; -} - -static int check_deps(alpm_list_t *pkglist) -{ - alpm_list_t *data, *i; - int ret = 0; - /* check dependencies */ - data = alpm_checkdeps(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); - printf("missing '%s' dependency for '%s'\n", depstring, miss->target); - free(depstring); - ret++; - } - FREELIST(data); - return ret; -} - -static int check_conflicts(alpm_list_t *pkglist) -{ - alpm_list_t *data, *i; - int ret = 0; - /* check conflicts */ - data = alpm_checkconflicts(handle, pkglist); - for(i = data; i; i = i->next) { - alpm_conflict_t *conflict = i->data; - printf("'%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_filelists(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) { - printf("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; -} - -static int check_localdb(void) -{ - int ret = 0; - alpm_db_t *db = NULL; - alpm_list_t *pkglist; - - ret = check_localdb_files(); - if(ret) { - return ret; - } - - db = alpm_get_localdb(handle); - pkglist = alpm_db_get_pkgcache(db); - ret += check_deps(pkglist); - ret += check_conflicts(pkglist); - ret += check_filelists(pkglist); - return ret; -} - -static int check_syncdbs(alpm_list_t *dbnames) -{ - int ret = 0; - alpm_db_t *db = NULL; - alpm_list_t *i, *pkglist, *syncpkglist = NULL; - const alpm_siglevel_t level = ALPM_SIG_DATABASE | ALPM_SIG_DATABASE_OPTIONAL; - - for(i = dbnames; i; i = alpm_list_next(i)) { - const char *dbname = i->data; - db = alpm_register_syncdb(handle, dbname, level); - if(db == NULL) { - fprintf(stderr, "error: could not register sync database (%s)\n", - alpm_strerror(alpm_errno(handle))); - ret = 1; - goto cleanup; - } - pkglist = alpm_db_get_pkgcache(db); - syncpkglist = alpm_list_join(syncpkglist, alpm_list_copy(pkglist)); - } - ret += check_deps(syncpkglist); - -cleanup: - alpm_list_free(syncpkglist); - return ret; -} - -static void usage(void) -{ - fprintf(stderr, "testdb (pacman) v" PACKAGE_VERSION "\n\n" - "Test a pacman local database for validity.\n\n" - "Usage: testdb [options]\n\n" - " -b <pacman db> : check the local database\n" - " -b <pacman db> core extra ... : check the listed sync databases\n"); - exit(1); -} - -int main(int argc, char *argv[]) -{ - int errors = 0; - alpm_errno_t err; - const char *dbpath = DBPATH; - int a = 1; - alpm_list_t *dbnames = NULL; - - while(a < argc) { - if(strcmp(argv[a], "-b") == 0) { - if(++a < argc) { - dbpath = argv[a]; - } else { - usage(); - } - } else if(strcmp(argv[a], "-h") == 0 || - strcmp(argv[a], "--help") == 0 ) { - usage(); - } else { - dbnames = alpm_list_add(dbnames, argv[a]); - } - a++; - } - - handle = alpm_initialize(ROOTDIR, dbpath, &err); - if(!handle) { - fprintf(stderr, "cannot initialize alpm: %s\n", alpm_strerror(err)); - return EXIT_FAILURE; - } - - /* let us get log messages from libalpm */ - alpm_option_set_logcb(handle, output_cb); - - if(!dbnames) { - errors = check_localdb(); - } else { - errors = check_syncdbs(dbnames); - alpm_list_free(dbnames); - } - - cleanup(errors > 0); -} - -/* vim: set noet: */ diff --git a/src/util/testpkg.c b/src/util/testpkg.c index cc7d9c2b..bd95a86b 100644 --- a/src/util/testpkg.c +++ b/src/util/testpkg.c @@ -1,7 +1,7 @@ /* * testpkg.c : Test a pacman package for validity * - * Copyright (c) 2007-2014 Pacman Development Team <pacman-dev@archlinux.org> + * Copyright (c) 2007-2015 Pacman Development Team <pacman-dev@archlinux.org> * Copyright (c) 2007 by Aaron Griffin <aaronmgriffin@gmail.com> * * This program is free software; you can redistribute it and/or modify diff --git a/src/util/vercmp.c b/src/util/vercmp.c index cc445185..561881e0 100644 --- a/src/util/vercmp.c +++ b/src/util/vercmp.c @@ -2,7 +2,7 @@ * vercmp.c - Compare package version numbers using pacman's version * comparison logic * - * Copyright (c) 2006-2014 Pacman Development Team <pacman-dev@archlinux.org> + * Copyright (c) 2006-2015 Pacman Development Team <pacman-dev@archlinux.org> * Copyright (c) 2002-2005 by Judd Vinet <jvinet@zeroflux.org> * * This program is free software; you can redistribute it and/or modify |