diff options
Diffstat (limited to 'src')
33 files changed, 162 insertions, 1187 deletions
diff --git a/src/common/ini.c b/src/common/ini.c index a4b29d17..e6437de3 100644 --- a/src/common/ini.c +++ b/src/common/ini.c @@ -1,7 +1,7 @@ /* * ini.c * - * Copyright (c) 2013-2016 Pacman Development Team <pacman-dev@archlinux.org> + * Copyright (c) 2013-2017 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 @@ -61,19 +61,14 @@ int parse_ini(const char *file, ini_parser_fn cb, void *data) } while(safe_fgets(line, PATH_MAX, fp)) { - char *key, *value, *ptr; + char *key, *value; size_t line_len; linenum++; - /* ignore whole line and end of line comments */ - if((ptr = strchr(line, '#'))) { - *ptr = '\0'; - } - line_len = strtrim(line); - if(line_len == 0) { + if(line_len == 0 || line[0] == '#') { continue; } diff --git a/src/common/ini.h b/src/common/ini.h index e03a83fd..4a4b1edf 100644 --- a/src/common/ini.h +++ b/src/common/ini.h @@ -1,7 +1,7 @@ /* * ini.h * - * Copyright (c) 2013-2016 Pacman Development Team <pacman-dev@archlinux.org> + * Copyright (c) 2013-2017 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.c b/src/common/util-common.c index 794273fd..6825a435 100644 --- a/src/common/util-common.c +++ b/src/common/util-common.c @@ -1,7 +1,7 @@ /* * util-common.c * - * Copyright (c) 2006-2016 Pacman Development Team <pacman-dev@archlinux.org> + * Copyright (c) 2006-2017 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 14520944..b0280d7a 100644 --- a/src/common/util-common.h +++ b/src/common/util-common.h @@ -1,7 +1,7 @@ /* * util-common.h * - * Copyright (c) 2006-2016 Pacman Development Team <pacman-dev@archlinux.org> + * Copyright (c) 2006-2017 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/Makefile.am b/src/pacman/Makefile.am index 14572cd4..8999f2b7 100644 --- a/src/pacman/Makefile.am +++ b/src/pacman/Makefile.am @@ -47,6 +47,9 @@ pacman_SOURCES = \ util.h util.c \ util-common.h util-common.c -LDADD = $(LTLIBINTL) $(top_builddir)/lib/libalpm/.libs/libalpm.la +pacman_LDADD = \ + $(LTLIBINTL) \ + $(top_builddir)/lib/libalpm/.libs/libalpm.la \ + $(LIBARCHIVE_LIBS) # vim:set noet: diff --git a/src/pacman/callback.c b/src/pacman/callback.c index 7f72b84f..e1e77f78 100644 --- a/src/pacman/callback.c +++ b/src/pacman/callback.c @@ -1,7 +1,7 @@ /* * callback.c * - * Copyright (c) 2006-2016 Pacman Development Team <pacman-dev@archlinux.org> + * Copyright (c) 2006-2017 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/callback.h b/src/pacman/callback.h index ad395e9d..b9bfeab5 100644 --- a/src/pacman/callback.h +++ b/src/pacman/callback.h @@ -1,7 +1,7 @@ /* * callback.h * - * Copyright (c) 2006-2016 Pacman Development Team <pacman-dev@archlinux.org> + * Copyright (c) 2006-2017 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 87fcf677..5c7d3631 100644 --- a/src/pacman/check.c +++ b/src/pacman/check.c @@ -1,7 +1,7 @@ /* * check.c * - * Copyright (c) 2012-2016 Pacman Development Team <pacman-dev@archlinux.org> + * Copyright (c) 2012-2017 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 5052376e..9fe1a1e2 100644 --- a/src/pacman/check.h +++ b/src/pacman/check.h @@ -1,7 +1,7 @@ /* * check.h * - * Copyright (c) 2012-2016 Pacman Development Team <pacman-dev@archlinux.org> + * Copyright (c) 2012-2017 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 25de7afa..261c8213 100644 --- a/src/pacman/conf.c +++ b/src/pacman/conf.c @@ -1,7 +1,7 @@ /* * conf.c * - * Copyright (c) 2006-2016 Pacman Development Team <pacman-dev@archlinux.org> + * Copyright (c) 2006-2017 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 @@ -325,10 +325,10 @@ int config_set_arch(const char *arch) * @param linenum current line number in file * @return 0 on success, 1 on any parsing error */ -static int process_siglevel(alpm_list_t *values, alpm_siglevel_t *storage, - alpm_siglevel_t *storage_mask, const char *file, int linenum) +static int process_siglevel(alpm_list_t *values, int *storage, + int *storage_mask, const char *file, int linenum) { - alpm_siglevel_t level = *storage, mask = *storage_mask; + int level = *storage, mask = *storage_mask; alpm_list_t *i; int ret = 0; @@ -421,13 +421,12 @@ static int process_siglevel(alpm_list_t *values, alpm_siglevel_t *storage, } /** - * Merge the package entires of two signature verification levels. + * Merge the package entries of two signature verification levels. * @param base initial siglevel - * @param over overridden siglevel + * @param over overriding siglevel * @return merged siglevel */ -static alpm_siglevel_t merge_siglevel(alpm_siglevel_t base, - alpm_siglevel_t over, alpm_siglevel_t mask) +static int merge_siglevel(int base, int over, int mask) { return mask ? (over & mask) | (base & ~mask) : over; } @@ -499,6 +498,8 @@ static int _parse_options(const char *key, char *value, config->color = isatty(fileno(stdout)) ? PM_COLOR_ON : PM_COLOR_OFF; enable_colors(config->color); } + } else if(strcmp(key, "DisableDownloadTimeout") == 0) { + config->disable_dl_timeout = 1; } else { pm_printf(ALPM_LOG_WARNING, _("config file %s, line %d: directive '%s' in section '%s' not recognized.\n"), @@ -782,6 +783,8 @@ static int setup_libalpm(void) alpm_option_set_cachedirs(handle, config->cachedirs); } + alpm_option_set_overwrite_files(handle, config->overwrite_files); + alpm_option_set_default_siglevel(handle, config->siglevel); config->localfilesiglevel = merge_siglevel(config->siglevel, @@ -816,6 +819,8 @@ static int setup_libalpm(void) alpm_option_set_noupgrades(handle, config->noupgrade); alpm_option_set_noextracts(handle, config->noextract); + alpm_option_set_disable_dl_timeout(handle, config->disable_dl_timeout); + for(i = config->assumeinstalled; i; i = i->next) { char *entry = i->data; alpm_depend_t *dep = alpm_dep_from_string(entry); @@ -845,11 +850,11 @@ struct section_t { int depth; }; -static int process_usage(alpm_list_t *values, alpm_db_usage_t *usage, +static int process_usage(alpm_list_t *values, int *usage, const char *file, int linenum) { alpm_list_t *i; - alpm_db_usage_t level = *usage; + int level = *usage; int ret = 0; for(i = values; i; i = i->next) { diff --git a/src/pacman/conf.h b/src/pacman/conf.h index 2ddeadb3..53b44be6 100644 --- a/src/pacman/conf.h +++ b/src/pacman/conf.h @@ -1,7 +1,7 @@ /* * conf.h * - * Copyright (c) 2006-2016 Pacman Development Team <pacman-dev@archlinux.org> + * Copyright (c) 2006-2017 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 @@ -37,9 +37,9 @@ typedef struct __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; + int usage; + int siglevel; + int siglevel_mask; } config_repo_t; typedef struct __config_t { @@ -55,6 +55,7 @@ typedef struct __config_t { unsigned short checkspace; unsigned short usesyslog; unsigned short color; + unsigned short disable_dl_timeout; double deltaratio; char *arch; char *print_format; @@ -66,6 +67,7 @@ typedef struct __config_t { char *dbpath; char *logfile; char *gpgdir; + char *sysroot; alpm_list_t *hookdirs; alpm_list_t *cachedirs; @@ -95,14 +97,16 @@ typedef struct __config_t { unsigned short group; unsigned short noask; unsigned int ask; - alpm_transflag_t flags; - alpm_siglevel_t siglevel; - alpm_siglevel_t localfilesiglevel; - alpm_siglevel_t remotefilesiglevel; + /* Bitfield of alpm_transflag_t */ + int flags; + /* Bitfields of alpm_siglevel_t */ + int siglevel; + int localfilesiglevel; + int remotefilesiglevel; - alpm_siglevel_t siglevel_mask; - alpm_siglevel_t localfilesiglevel_mask; - alpm_siglevel_t remotefilesiglevel_mask; + int siglevel_mask; + int localfilesiglevel_mask; + int remotefilesiglevel_mask; /* conf file options */ /* I Love Candy! */ @@ -120,6 +124,7 @@ typedef struct __config_t { alpm_list_t *assumeinstalled; alpm_list_t *noupgrade; alpm_list_t *noextract; + alpm_list_t *overwrite_files; char *xfercommand; /* our connection to libalpm */ @@ -169,6 +174,7 @@ enum { OP_GPGDIR, OP_DBONLY, OP_FORCE, + OP_OVERWRITE_FILES, OP_COLOR, OP_DBPATH, OP_CASCADE, @@ -190,6 +196,7 @@ enum { OP_PRINT, OP_QUIET, OP_ROOT, + OP_SYSROOT, OP_RECURSIVE, OP_SEARCH, OP_REGEX, @@ -201,7 +208,8 @@ enum { OP_VERBOSE, OP_DOWNLOADONLY, OP_REFRESH, - OP_ASSUMEINSTALLED + OP_ASSUMEINSTALLED, + OP_DISABLEDLTIMEOUT }; /* clean method */ diff --git a/src/pacman/database.c b/src/pacman/database.c index 01979034..8b99fdf6 100644 --- a/src/pacman/database.c +++ b/src/pacman/database.c @@ -1,7 +1,7 @@ /* * database.c * - * Copyright (c) 2006-2016 Pacman Development Team <pacman-dev@archlinux.org> + * Copyright (c) 2006-2017 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 @@ -74,10 +74,12 @@ static int change_install_reason(alpm_list_t *targets) pkgname, alpm_strerror(alpm_errno(config->handle))); ret = 1; } else { - if(reason == ALPM_PKG_REASON_DEPEND) { - printf(_("%s: install reason has been set to 'installed as dependency'\n"), pkgname); - } else { - printf(_("%s: install reason has been set to 'explicitly installed'\n"), pkgname); + if(!config->quiet) { + if(reason == ALPM_PKG_REASON_DEPEND) { + printf(_("%s: install reason has been set to 'installed as dependency'\n"), pkgname); + } else { + printf(_("%s: install reason has been set to 'explicitly installed'\n"), pkgname); + } } } } @@ -286,6 +288,10 @@ int pacman_database(alpm_list_t *targets) } else { ret = check_db_sync(); } + + if(ret == 0 && !config->quiet) { + printf(_("No database errors have been found!\n")); + } } if(config->flags & (ALPM_TRANS_FLAG_ALLDEPS | ALPM_TRANS_FLAG_ALLEXPLICIT)) { diff --git a/src/pacman/deptest.c b/src/pacman/deptest.c index 7c89ad8e..2163c1ce 100644 --- a/src/pacman/deptest.c +++ b/src/pacman/deptest.c @@ -1,7 +1,7 @@ /* * deptest.c * - * Copyright (c) 2006-2016 Pacman Development Team <pacman-dev@archlinux.org> + * Copyright (c) 2006-2017 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/files.c b/src/pacman/files.c index f5cba5b2..3072e280 100644 --- a/src/pacman/files.c +++ b/src/pacman/files.c @@ -1,7 +1,7 @@ /* * files.c * - * Copyright (c) 2015-2016 Pacman Development Team <pacman-dev@archlinux.org> + * Copyright (c) 2015-2017 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 3ab9abc0..65f7aee6 100644 --- a/src/pacman/package.c +++ b/src/pacman/package.c @@ -1,7 +1,7 @@ /* * package.c * - * Copyright (c) 2006-2016 Pacman Development Team <pacman-dev@archlinux.org> + * Copyright (c) 2006-2017 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 @@ -230,7 +230,7 @@ void dump_pkg_full(alpm_pkg_t *pkg, int extra) break; } - alpm_pkgvalidation_t v = alpm_pkg_get_validation(pkg); + int v = alpm_pkg_get_validation(pkg); if(v) { if(v & ALPM_PKG_VALIDATION_NONE) { validation = alpm_list_add(validation, _("None")); diff --git a/src/pacman/package.h b/src/pacman/package.h index 3129a736..46081381 100644 --- a/src/pacman/package.h +++ b/src/pacman/package.h @@ -1,7 +1,7 @@ /* * package.h * - * Copyright (c) 2006-2016 Pacman Development Team <pacman-dev@archlinux.org> + * Copyright (c) 2006-2017 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 be52d1be..605aec3e 100644 --- a/src/pacman/pacman.c +++ b/src/pacman/pacman.c @@ -1,7 +1,7 @@ /* * pacman.c * - * Copyright (c) 2006-2016 Pacman Development Team <pacman-dev@archlinux.org> + * Copyright (c) 2006-2017 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 @@ -171,6 +171,7 @@ static void usage(int op, const char * const myname) 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")); + addlist(_(" -q, --quiet suppress output of success messages\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); @@ -188,7 +189,8 @@ static void usage(int op, const char * const myname) switch(op) { case PM_OP_SYNC: case PM_OP_UPGRADE: - addlist(_(" --force force install, overwrite conflicting files\n")); + addlist(_(" --overwrite <path>\n" + " overwrite conflicting files (can be used more than once)\n")); addlist(_(" --asdeps install packages as non-explicitly installed\n")); addlist(_(" --asexplicit install packages as explicitly installed\n")); addlist(_(" --ignore <pkg> ignore a package upgrade (can be used more than once)\n")); @@ -212,6 +214,7 @@ static void usage(int op, const char * const myname) addlist(_(" -r, --root <path> set an alternate installation root\n")); addlist(_(" -v, --verbose be verbose\n")); addlist(_(" --arch <arch> set an alternate architecture\n")); + addlist(_(" --sysroot operate on a mounted guest system (root-only)\n")); addlist(_(" --cachedir <dir> set an alternate package cache location\n")); addlist(_(" --hookdir <dir> set an alternate hook location\n")); addlist(_(" --color <when> colorize the output\n")); @@ -221,6 +224,8 @@ static void usage(int op, const char * const myname) addlist(_(" --logfile <path> set an alternate log file\n")); addlist(_(" --noconfirm do not ask for any confirmation\n")); addlist(_(" --confirm always ask for confirmation\n")); + addlist(_(" --disable-download-timeout\n" + " use relaxed timeouts for download\n")); } list = alpm_list_msort(list, alpm_list_count(list), options_cmp); for(i = list; i; i = alpm_list_next(i)) { @@ -236,7 +241,7 @@ static void version(void) { printf("\n"); printf(" .--. Pacman v%s - libalpm v%s\n", PACKAGE_VERSION, alpm_version()); - printf("/ _.-' .-. .-. .-. Copyright (C) 2006-2016 Pacman Development Team\n"); + printf("/ _.-' .-. .-. .-. Copyright (C) 2006-2017 Pacman Development Team\n"); printf("\\ '-. '-' '-' '-' Copyright (C) 2002-2006 Judd Vinet\n"); printf(" '--'\n"); printf(_(" This program may be freely redistributed under\n" @@ -443,6 +448,13 @@ static int parsearg_global(int opt) free(config->rootdir); config->rootdir = strdup(optarg); break; + case OP_SYSROOT: + free(config->sysroot); + config->sysroot = strdup(optarg); + break; + case OP_DISABLEDLTIMEOUT: + config->disable_dl_timeout = 1; + break; case OP_VERBOSE: case 'v': (config->verbose)++; @@ -466,6 +478,10 @@ static int parsearg_database(int opt) case 'k': (config->op_q_check)++; break; + case OP_QUIET: + case 'q': + config->quiet = 1; + break; default: return 1; } @@ -696,8 +712,13 @@ static int parsearg_upgrade(int opt) } switch(opt) { case OP_FORCE: + pm_printf(ALPM_LOG_WARNING, + _("option --force is deprecated; use --overwrite instead\n")); config->flags |= ALPM_TRANS_FLAG_FORCE; break; + case OP_OVERWRITE_FILES: + parsearg_util_addlist(&(config->overwrite_files)); + break; case OP_ASDEPS: config->flags |= ALPM_TRANS_FLAG_ALLDEPS; break; @@ -901,6 +922,7 @@ static int parseargs(int argc, char *argv[]) {"print", no_argument, 0, OP_PRINT}, {"quiet", no_argument, 0, OP_QUIET}, {"root", required_argument, 0, OP_ROOT}, + {"sysroot", required_argument, 0, OP_SYSROOT}, {"recursive", no_argument, 0, OP_RECURSIVE}, {"search", no_argument, 0, OP_SEARCH}, {"regex", no_argument, 0, OP_REGEX}, @@ -919,6 +941,7 @@ static int parseargs(int argc, char *argv[]) {"assume-installed", required_argument, 0, OP_ASSUMEINSTALLED}, {"debug", optional_argument, 0, OP_DEBUG}, {"force", no_argument, 0, OP_FORCE}, + {"overwrite", required_argument, 0, OP_OVERWRITE_FILES}, {"noprogressbar", no_argument, 0, OP_NOPROGRESSBAR}, {"noscriptlet", no_argument, 0, OP_NOSCRIPTLET}, {"ask", required_argument, 0, OP_ASK}, @@ -934,6 +957,7 @@ static int parseargs(int argc, char *argv[]) {"gpgdir", required_argument, 0, OP_GPGDIR}, {"dbonly", no_argument, 0, OP_DBONLY}, {"color", required_argument, 0, OP_COLOR}, + {"disable-download-timeout", no_argument, 0, OP_DISABLEDLTIMEOUT}, {0, 0, 0, 0} }; @@ -1089,7 +1113,6 @@ static void cl_to_log(int argc, char *argv[]) int main(int argc, char *argv[]) { int ret = 0; - size_t i; uid_t myuid = getuid(); install_segv_handler(); @@ -1133,48 +1156,52 @@ int main(int argc, char *argv[]) cleanup(ret); } + /* check if we have sufficient permission for the requested operation */ + if(myuid > 0 && needs_root()) { + pm_printf(ALPM_LOG_ERROR, _("you cannot perform this operation unless you are root.\n")); + cleanup(EXIT_FAILURE); + } + + if(config->sysroot && (chroot(config->sysroot) != 0 || chdir("/") != 0)) { + pm_printf(ALPM_LOG_ERROR, + _("chroot to '%s' failed: (%s)\n"), config->sysroot, strerror(errno)); + cleanup(EXIT_FAILURE); + } + /* we support reading targets from stdin if a cmdline parameter is '-' */ if(alpm_list_find_str(pm_targets, "-")) { if(!isatty(fileno(stdin))) { int target_found = 0; - size_t current_size = PATH_MAX; - char *vdata, *line = malloc(current_size); - int c; + char *vdata, *line = NULL; + size_t line_size = 0; + ssize_t nread; /* remove the '-' from the list */ pm_targets = alpm_list_remove_str(pm_targets, "-", &vdata); free(vdata); - i = 0; - do { - c = fgetc(stdin); - if(c == EOF || isspace(c)) { - /* avoid adding zero length arg when multiple spaces separate args */ - if(i > 0) { - line[i] = '\0'; - pm_targets = alpm_list_add(pm_targets, strdup(line)); - target_found = 1; - i = 0; - } - } else { - line[i++] = (char)c; - /* we may be at the end of our allocated buffer now */ - if(i >= current_size) { - char *new = realloc(line, current_size * 2); - if(new) { - line = new; - current_size *= 2; - } else { - free(line); - pm_printf(ALPM_LOG_ERROR, - _("memory exhausted in argument parsing\n")); - cleanup(EXIT_FAILURE); - } - } + while((nread = getline(&line, &line_size, stdin)) != -1) { + if(line[nread - 1] == '\n') { + /* remove trailing newline */ + line[nread - 1] = '\0'; } - } while(c != EOF); - + if(line[0] == '\0') { + /* skip empty lines */ + continue; + } + if(!alpm_list_append_strdup(&pm_targets, line)) { + break; + } + target_found = 1; + } free(line); + + if(ferror(stdin)) { + pm_printf(ALPM_LOG_ERROR, + _("failed to read arguments from stdin: (%s)\n"), strerror(errno)); + cleanup(EXIT_FAILURE); + } + if(!freopen(ctermid(NULL), "r", stdin)) { pm_printf(ALPM_LOG_ERROR, _("failed to reopen stdin for reading: (%s)\n"), strerror(errno)); @@ -1213,12 +1240,6 @@ int main(int argc, char *argv[]) config->logmask &= ~ALPM_LOG_WARNING; } - /* check if we have sufficient permission for the requested operation */ - if(myuid > 0 && needs_root()) { - pm_printf(ALPM_LOG_ERROR, _("you cannot perform this operation unless you are root.\n")); - cleanup(EXIT_FAILURE); - } - if(config->verbose > 0) { alpm_list_t *j; printf("Root : %s\n", alpm_option_get_root(config->handle)); diff --git a/src/pacman/pacman.h b/src/pacman/pacman.h index 84f70a66..107d4268 100644 --- a/src/pacman/pacman.h +++ b/src/pacman/pacman.h @@ -1,7 +1,7 @@ /* * pacman.h * - * Copyright (c) 2006-2016 Pacman Development Team <pacman-dev@archlinux.org> + * Copyright (c) 2006-2017 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 a8f4e675..a8417570 100644 --- a/src/pacman/query.c +++ b/src/pacman/query.c @@ -1,7 +1,7 @@ /* * query.c * - * Copyright (c) 2006-2016 Pacman Development Team <pacman-dev@archlinux.org> + * Copyright (c) 2006-2017 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 73b48c36..7de6f8b6 100644 --- a/src/pacman/remove.c +++ b/src/pacman/remove.c @@ -1,7 +1,7 @@ /* * remove.c * - * Copyright (c) 2006-2016 Pacman Development Team <pacman-dev@archlinux.org> + * Copyright (c) 2006-2017 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/sighandler.c b/src/pacman/sighandler.c index 366718b2..73a46db6 100644 --- a/src/pacman/sighandler.c +++ b/src/pacman/sighandler.c @@ -1,7 +1,7 @@ /* * sighandler.c * - * Copyright (c) 2015-2016 Pacman Development Team <pacman-dev@archlinux.org> + * Copyright (c) 2015-2017 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/sighandler.h b/src/pacman/sighandler.h index 108a7e00..e39f546c 100644 --- a/src/pacman/sighandler.h +++ b/src/pacman/sighandler.h @@ -1,7 +1,7 @@ /* * sighandler.h * - * Copyright (c) 2015-2016 Pacman Development Team <pacman-dev@archlinux.org> + * Copyright (c) 2015-2017 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/sync.c b/src/pacman/sync.c index 8b306034..680d7b3e 100644 --- a/src/pacman/sync.c +++ b/src/pacman/sync.c @@ -1,7 +1,7 @@ /* * sync.c * - * Copyright (c) 2006-2016 Pacman Development Team <pacman-dev@archlinux.org> + * Copyright (c) 2006-2017 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 @@ -630,7 +630,7 @@ static int process_target(const char *target, int error) if(targname && targname != targstring) { alpm_db_t *db; const char *dbname; - alpm_db_usage_t usage; + int usage; *targname = '\0'; targname++; @@ -823,8 +823,13 @@ int sync_prepare_execute(void) conflict->file, conflict->target, conflict->ctarget); break; case ALPM_FILECONFLICT_FILESYSTEM: - printf(_("%s: %s exists in filesystem\n"), - conflict->target, conflict->file); + if(conflict->ctarget[0]) { + printf(_("%s: %s exists in filesystem (owned by %s)\n"), + conflict->target, conflict->file, conflict->ctarget); + } else { + printf(_("%s: %s exists in filesystem\n"), + conflict->target, conflict->file); + } break; } alpm_fileconflict_free(conflict); diff --git a/src/pacman/upgrade.c b/src/pacman/upgrade.c index 591556d3..d4808b60 100644 --- a/src/pacman/upgrade.c +++ b/src/pacman/upgrade.c @@ -1,7 +1,7 @@ /* * upgrade.c * - * Copyright (c) 2006-2016 Pacman Development Team <pacman-dev@archlinux.org> + * Copyright (c) 2006-2017 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 @@ -89,15 +89,15 @@ int pacman_upgrade(alpm_list_t *targets) for(i = targets, n = 0; i; i = alpm_list_next(i), n++) { const char *targ = i->data; alpm_pkg_t *pkg; - alpm_siglevel_t level; + int siglevel; if(file_is_remote[n]) { - level = alpm_option_get_remote_file_siglevel(config->handle); + siglevel = alpm_option_get_remote_file_siglevel(config->handle); } else { - level = alpm_option_get_local_file_siglevel(config->handle); + siglevel = alpm_option_get_local_file_siglevel(config->handle); } - if(alpm_pkg_load(config->handle, targ, 1, level, &pkg) != 0) { + if(alpm_pkg_load(config->handle, targ, 1, siglevel, &pkg) != 0) { pm_printf(ALPM_LOG_ERROR, "'%s': %s\n", targ, alpm_strerror(alpm_errno(config->handle))); retval = 1; diff --git a/src/pacman/util.c b/src/pacman/util.c index b9790836..ae8a74d3 100644 --- a/src/pacman/util.c +++ b/src/pacman/util.c @@ -1,7 +1,7 @@ /* * util.c * - * Copyright (c) 2006-2016 Pacman Development Team <pacman-dev@archlinux.org> + * Copyright (c) 2006-2017 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 @@ -61,7 +61,7 @@ enum { CELL_FREE = (1 << 3) }; -int trans_init(alpm_transflag_t flags, int check_valid) +int trans_init(int flags, int check_valid) { int ret; @@ -103,6 +103,9 @@ int trans_release(void) int needs_root(void) { + if(config->sysroot) { + return 1; + } switch(config->op) { case PM_OP_DATABASE: return !config->op_q_check; diff --git a/src/pacman/util.h b/src/pacman/util.h index 74ce4cb2..5f1df2f2 100644 --- a/src/pacman/util.h +++ b/src/pacman/util.h @@ -1,7 +1,7 @@ /* * util.h * - * Copyright (c) 2006-2016 Pacman Development Team <pacman-dev@archlinux.org> + * Copyright (c) 2006-2017 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 @@ -45,7 +45,8 @@ typedef struct _pm_target_t { } pm_target_t; void trans_init_error(void); -int trans_init(alpm_transflag_t flags, int check_valid); +/* flags is a bitfield of alpm_transflag_t flags */ +int trans_init(int flags, int check_valid); int trans_release(void); int needs_root(void); int check_syncdbs(size_t need_repos, int check_valid); diff --git a/src/util/.gitignore b/src/util/.gitignore index 202fb753..4cb3103e 100644 --- a/src/util/.gitignore +++ b/src/util/.gitignore @@ -2,10 +2,6 @@ .libs cleanupdelta cleanupdelta.exe -pacsort -pacsort.exe -pactree -pactree.exe testpkg testpkg.exe vercmp diff --git a/src/util/Makefile.am b/src/util/Makefile.am index 6a89ea69..562151bc 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 cleanupdelta pacsort pactree +bin_PROGRAMS = vercmp testpkg cleanupdelta AM_CPPFLAGS = \ -imacros $(top_builddir)/config.h \ @@ -21,12 +21,6 @@ AM_CFLAGS = -pedantic -D_GNU_SOURCE $(WARNING_CFLAGS) \ cleanupdelta_SOURCES = cleanupdelta.c cleanupdelta_LDADD = $(top_builddir)/lib/libalpm/.libs/libalpm.la -pacsort_SOURCES = pacsort.c util-common.c -pacsort_LDADD = $(top_builddir)/lib/libalpm/.libs/libalpm.la - -pactree_SOURCES = pactree.c util-common.c -pactree_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 043acf1a..2a1544e4 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-2016 Pacman Development Team <pacman-dev@archlinux.org> + * Copyright (c) 2011-2017 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 @@ -68,11 +68,11 @@ static void checkdbs(alpm_list_t *dbnames) { alpm_db_t *db = NULL; alpm_list_t *i; - const alpm_siglevel_t level = ALPM_SIG_DATABASE | ALPM_SIG_DATABASE_OPTIONAL; + const int siglevel = 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); + db = alpm_register_syncdb(handle, dbname, siglevel); if(db == NULL) { fprintf(stderr, "error: could not register sync database '%s' (%s)\n", dbname, alpm_strerror(alpm_errno(handle))); diff --git a/src/util/pacsort.c b/src/util/pacsort.c deleted file mode 100644 index 662b250d..00000000 --- a/src/util/pacsort.c +++ /dev/null @@ -1,552 +0,0 @@ -/* - * pacsort.c - a sort utility implementing alpm_pkg_vercmp - * - * Copyright (c) 2010-2016 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 - * 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 <errno.h> -#include <fnmatch.h> -#include <getopt.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> - -#include <alpm.h> -#include "util-common.h" - -#define DELIM ' ' -#define INVALD_ESCAPE_CHAR ((char)-1) - -#ifndef MIN -#define MIN(a, b) \ - __extension__({ \ - __typeof__(a) _a = (a); \ - __typeof__(b) _b = (b); \ - _a < _b ? _a : _b; \ - }) -#endif - -struct buffer_t { - char *mem; - size_t len; - size_t maxlen; -}; - -struct list_t { - void **list; - size_t count; - size_t maxcount; -}; - -struct input_t { - char *data; - int is_file; - - const char *pkgname; - size_t pkgname_len; - - const char *pkgver; - size_t pkgver_len; -}; - -static struct options_t { - int order; - int sortkey; - int null; - int filemode; - int help; - char delim; -} opts; - -static struct buffer_t *buffer_new(size_t initial_size) -{ - struct buffer_t *buf; - - buf = calloc(1, sizeof(*buf)); - if(!buf) { - return NULL; - } - - buf->mem = calloc(initial_size, sizeof(char)); - if(!buf->mem) { - free(buf); - return NULL; - } - - buf->len = 0; - buf->maxlen = initial_size; - - return buf; -} - -static void buffer_free(struct buffer_t *buf) -{ - if(!buf) { - return; - } - - free(buf->mem); - free(buf); -} - -static int buffer_grow(struct buffer_t *buffer) -{ - size_t newsz = buffer->maxlen * 2.5; - char* new_mem = realloc(buffer->mem, newsz * sizeof(char)); - if(!new_mem) { - return 1; - } - buffer->mem = new_mem; - buffer->maxlen = newsz; - - return 0; -} - -static struct list_t *list_new(size_t initial_size) -{ - struct list_t *list; - - list = calloc(1, sizeof(struct list_t)); - if(!list) { - return NULL; - } - - list->list = calloc(initial_size, sizeof(char *)); - if(!list->list) { - free(list); - return NULL; - } - - list->maxcount = initial_size; - - return list; -} - -static int list_grow(struct list_t *list) -{ - size_t newsz = list->maxcount * 2.5; - void **new_list = realloc(list->list, newsz * sizeof(char *)); - if(!new_list) { - return 1; - } - - list->list = new_list; - list->maxcount = newsz; - - return 0; -} - -static int list_add(struct list_t *list, void *obj) -{ - if(!list || !obj) { - return 1; - } - - if(list->count + 1 >= list->maxcount) { - if(list_grow(list) != 0) { - return 1; - } - } - - list->list[list->count] = obj; - list->count++; - - return 0; -} - -static void list_free(struct list_t *list, void (*freefn)(void *)) -{ - size_t i; - - if(!list) { - return; - } - - if(list->list) { - for(i = 0; i < list->count; i++) { - freefn(list->list[i]); - } - free(list->list); - } - free(list); -} - -static void input_free(void *p) -{ - struct input_t *in = p; - - if(in == NULL) { - return; - } - - free(in->data); - free(in); -} - -static struct input_t *input_new(const char *path, int pathlen) -{ - const char *pkgver_end; - const char *slash; - struct input_t *in; - - in = calloc(1, sizeof(struct input_t)); - if(in == NULL) { - return NULL; - } - - in->data = strndup(path, pathlen); - if(in->data == NULL) { - free(in); - return NULL; - } - - in->is_file = fnmatch("*-*.pkg.tar.?z", in->data, 0) == 0; - if(!in->is_file) { - return in; - } - - /* for files, we parse the pkgname and pkgrel from the full filename. */ - - slash = strrchr(in->data, '/'); - if(slash == NULL) { - in->pkgname = in->data; - } else { - in->pkgname = slash + 1; - } - - pkgver_end = strrchr(in->pkgname, '-'); - - /* read backwards through pkgrel */ - for(in->pkgver = pkgver_end - 1; - in->pkgver > in->pkgname && *in->pkgver != '-'; - --in->pkgver) - ; - /* read backwards through pkgver */ - for(--in->pkgver; - in->pkgver > in->pkgname && *in->pkgver != '-'; - --in->pkgver) - ; - ++in->pkgver; - - in->pkgname_len = in->pkgver - in->pkgname - 1; - in->pkgver_len = pkgver_end - in->pkgver; - - return in; -} - -static char *explode(struct buffer_t *buffer, struct list_t *list) -{ - char *ptr, *end; - const char linedelim = opts.null ? '\0' : '\n'; - struct input_t *meta; - - ptr = buffer->mem; - while((end = memchr(ptr, linedelim, &buffer->mem[buffer->len] - ptr))) { - *end = '\0'; - meta = input_new(ptr, end - ptr); - if(meta == NULL || list_add(list, meta) != 0) { - input_free(meta); - return NULL; - } - ptr = end + 1; - } - - return ptr; -} - -static int splitfile(FILE *stream, struct buffer_t *buffer, struct list_t *list) -{ - size_t nread; - char *ptr; - - while(!feof(stream)) { - /* check if a read of BUFSIZ chars will overflow */ - if(buffer->len + BUFSIZ + 1 >= buffer->maxlen) { - if(buffer_grow(buffer) != 0) { - return 1; - } - } - - nread = fread(&buffer->mem[buffer->len], 1, BUFSIZ, stream); - if(nread == 0) { - break; /* EOF */ - } - buffer->len += nread; - - if((ptr = explode(buffer, list)) == NULL) { - return 1; - } - - if(ptr != buffer->mem) { - /* realign the data in the buffer */ - buffer->len = &buffer->mem[buffer->len] - ptr; - memmove(&buffer->mem[0], ptr, buffer->len + 1); - } - } - - if(buffer->len) { - struct input_t *meta = input_new(buffer->mem, buffer->len + 1); - if(meta == NULL || list_add(list, meta) != 0) { - input_free(meta); - return 1; - } - } - - return 0; -} - -/* returns a pointer to the nth column of a string without being destructive */ -static const char *nth_column(const char *string) -{ - const char *prev, *ptr; - int col; - - ptr = prev = string; - for(col = 0; ptr && col < opts.sortkey; col++) { - prev = ptr; - ptr = strchr(ptr, opts.delim); - if(ptr) { - ptr++; - } - } - - return prev; -} - -static int compare_versions(const char *v1, const char *v2) -{ - if(opts.sortkey == 0) { - return opts.order * alpm_pkg_vercmp(v1, v2); - } else { - return opts.order * alpm_pkg_vercmp(nth_column(v1), nth_column(v2)); - } -} - -static int compare_files(const struct input_t *meta1, const struct input_t *meta2) -{ - int cmp; - char *verbuf; - const char *v1, *v2; - - /* sort first by package name */ - cmp = memcmp(meta1->pkgname, meta2->pkgname, - MIN(meta1->pkgname_len, meta2->pkgname_len)); - - /* 1) package names differ, sort by package name */ - if(cmp != 0) { - return opts.order * cmp; - } - - /* 2) prefixes are the same but length differs, sort by length */ - if(meta1->pkgname_len != meta2->pkgname_len) { - return opts.order * (meta1->pkgname_len - meta2->pkgname_len); - } - - /* allocate once with enough space for both pkgver */ - verbuf = calloc(1, meta1->pkgver_len + 1 + meta2->pkgver_len + 1); - memcpy(verbuf, meta1->pkgver, meta1->pkgver_len); - memcpy(&verbuf[meta1->pkgver_len + 1], meta2->pkgver, meta2->pkgver_len); - - /* 3) sort by package version */ - v1 = verbuf; - v2 = verbuf + meta1->pkgver_len + 1; - cmp = compare_versions(v1, v2); - free(verbuf); - - return cmp; -} - -static int vercmp(const void *p1, const void *p2) -{ - const struct input_t *meta1, *meta2; - - meta1 = *(struct input_t **)p1; - meta2 = *(struct input_t **)p2; - - if(opts.filemode && meta1->is_file && meta2->is_file) { - return compare_files(meta1, meta2); - } else { - return compare_versions(meta1->data, meta2->data); - } -} - -static char escape_char(const char *string) -{ - if(!string) { - return INVALD_ESCAPE_CHAR; - } - - const size_t len = strlen(string); - - if(len > 2) { - return INVALD_ESCAPE_CHAR; - } - - if(len == 1) { - return *string; - } - - if(*string != '\\') { - return INVALD_ESCAPE_CHAR; - } - - switch(string[1]) { - case 't': - return '\t'; - case 'n': - return '\n'; - case 'v': - return '\v'; - case '0': - return '\0'; - default: - return INVALD_ESCAPE_CHAR; - } -} - -static void usage(void) -{ - fprintf(stderr, "pacsort (pacman) v" PACKAGE_VERSION "\n\n" - "A sort utility implementing alpm_pkg_vercmp.\n\n" - "Usage: pacsort [options] [files...]\n\n" - " -f, --files assume inputs are file paths of packages\n" - " -h, --help display this help message\n" - " -k, --key <index> sort input starting on specified column\n" - " -r, --reverse sort in reverse order (default: oldest to newest)\n" - " -t, --separator <sep> specify field separator (default: space)\n" - " -z, --null lines end with null bytes, not newlines\n\n" - "pacsort writes the sorted concatenation of all files, to standard output.\n" - "Files should contain a list of inputs to sort.\n\n" - "Standard input is read when no files are given.\n\n"); -} - -static int parse_options(int argc, char **argv) -{ - int opt; - - static const struct option opttable[] = { - {"files", no_argument, 0, 'f'}, - {"help", no_argument, 0, 'h'}, - {"key", required_argument, 0, 'k'}, - {"reverse", no_argument, 0, 'r'}, - {"separator", required_argument, 0, 't'}, - {"null", no_argument, 0, 'z'}, - {0, 0, 0, 0} - }; - - while((opt = getopt_long(argc, argv, "fhk:rt:z", opttable, NULL)) != -1) { - switch(opt) { - case 'f': - opts.filemode = 1; - break; - case 'h': - opts.help = 1; - return 0; - case 'k': - opts.sortkey = (int)strtol(optarg, NULL, 10); - if(opts.sortkey <= 0) { - fprintf(stderr, "error: invalid sort key -- %s\n", optarg); - return 1; - } - break; - case 'r': - opts.order = -1; - break; - case 't': - opts.delim = escape_char(optarg); - if(opts.delim == INVALD_ESCAPE_CHAR) { - fprintf(stderr, "error: invalid field separator -- `%s'\n", optarg); - return 1; - } - break; - case 'z': - opts.null = 1; - break; - default: - return 1; - } - } - - return 0; -} - -int main(int argc, char *argv[]) -{ - struct list_t *list; - struct buffer_t *buffer; - size_t i; - int ret = 0; - - /* option defaults */ - opts.order = 1; - opts.delim = DELIM; - opts.sortkey = 0; - opts.null = 0; - - if(parse_options(argc, argv) != 0) { - usage(); - return 2; - } - - if(opts.help) { - usage(); - return 0; - } - - list = list_new(100); - buffer = buffer_new(BUFSIZ * 3); - - if(optind == argc) { - if(splitfile(stdin, buffer, list) != 0) { - fprintf(stderr, "%s: memory exhausted\n", argv[0]); - ret = ENOMEM; - goto cleanup; - } - } else { - while(optind < argc) { - FILE *input = fopen(argv[optind], "r"); - if(input) { - if(splitfile(input, buffer, list) != 0) { - fprintf(stderr, "%s: memory exhausted\n", argv[0]); - fclose(input); - ret = ENOMEM; - goto cleanup; - } - fclose(input); - } else { - fprintf(stderr, "%s: %s: %s\n", argv[0], argv[optind], strerror(errno)); - } - optind++; - } - } - - if(list->count) { - const char linedelim = opts.null ? '\0' : '\n'; - qsort(list->list, list->count, sizeof(void *), vercmp); - for(i = 0; i < list->count; i++) { - const struct input_t *in = list->list[i]; - printf("%s%c", in->data, linedelim); - } - } - -cleanup: - list_free(list, input_free); - buffer_free(buffer); - - return ret; -} - -/* vim: set noet: */ diff --git a/src/util/pactree.c b/src/util/pactree.c deleted file mode 100644 index 67be9f94..00000000 --- a/src/util/pactree.c +++ /dev/null @@ -1,510 +0,0 @@ -/* - * pactree.c - a simple dependency tree viewer - * - * Copyright (c) 2010-2016 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 - * 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 <ctype.h> -#include <getopt.h> -#include <stdio.h> -#include <string.h> -#include <locale.h> -#include <alpm.h> -#include <alpm_list.h> - -#ifdef HAVE_LANGINFO_H -#include <langinfo.h> -#endif - -#include "util-common.h" - -#define LINE_MAX 512 - -typedef struct tdepth { - struct tdepth *prev; - struct tdepth *next; - int level; -} tdepth; - -/* output */ -struct graph_style { - const char *provides; - const char *tip; - const char *last; - const char *limb; - int indent; -}; - -#define UTF_V "\342\224\202" /* U+2502, Vertical line drawing char */ -#define UTF_VR "\342\224\234" /* U+251C, Vertical and right */ -#define UTF_H "\342\224\200" /* U+2500, Horizontal */ -#define UTF_UR "\342\224\224" /* U+2514, Up and right */ - -static struct graph_style graph_utf8 = { - " provides", - UTF_VR UTF_H, - UTF_UR UTF_H, - UTF_V " ", - 2 -}; - -static struct graph_style graph_default = { - " provides", - "|-", - "`-", - "|", - 2 -}; - -static struct graph_style graph_linear = { - "", - "", - "", - "", - 0 -}; - -/* color choices */ -struct color_choices { - const char *branch1; - const char *branch2; - const char *leaf1; - const char *leaf2; - const char *off; -}; - -static struct color_choices use_color = { - "\033[0;33m", /* yellow */ - "\033[0;37m", /* white */ - "\033[1;32m", /* bold green */ - "\033[0;32m", /* green */ - "\033[0m" -}; - -static struct color_choices no_color = { - "", - "", - "", - "", - "" -}; - -/* long operations */ -enum { - OP_CONFIG = 1000 -}; - -/* globals */ -alpm_handle_t *handle = NULL; -alpm_list_t *walked = NULL; -alpm_list_t *provisions = NULL; - -/* options */ -struct color_choices *color = &no_color; -struct graph_style *style = &graph_utf8; -int graphviz = 0; -int max_depth = -1; -int reverse = 0; -int unique = 0; -int searchsyncs = 0; -const char *dbpath = DBPATH; -const char *configfile = CONFFILE; - -static int register_syncs(void) -{ - FILE *fp; - char *section = NULL; - char line[LINE_MAX]; - const alpm_siglevel_t level = ALPM_SIG_DATABASE | ALPM_SIG_DATABASE_OPTIONAL; - - fp = fopen(configfile, "r"); - if(!fp) { - fprintf(stderr, "error: config file %s could not be read\n", configfile); - return 1; - } - - while(fgets(line, LINE_MAX, fp)) { - size_t linelen; - char *ptr; - - /* ignore whole line and end of line comments */ - if((ptr = strchr(line, '#'))) { - *ptr = '\0'; - } - - linelen = strtrim(line); - - if(linelen == 0) { - continue; - } - - if(line[0] == '[' && line[linelen - 1] == ']') { - free(section); - section = strndup(&line[1], linelen - 2); - - if(section && strcmp(section, "options") != 0) { - alpm_db_t *db = alpm_register_syncdb(handle, section, level); - alpm_db_set_usage(db, ALPM_DB_USAGE_ALL); - } - } - } - - free(section); - fclose(fp); - - return 0; -} - -static int parse_options(int argc, char *argv[]) -{ - int opt, option_index = 0; - char *endptr = NULL; - - static const struct option opts[] = { - {"ascii", no_argument, 0, 'a'}, - {"dbpath", required_argument, 0, 'b'}, - {"color", no_argument, 0, 'c'}, - {"depth", required_argument, 0, 'd'}, - {"graph", no_argument, 0, 'g'}, - {"help", no_argument, 0, 'h'}, - {"linear", no_argument, 0, 'l'}, - {"reverse", no_argument, 0, 'r'}, - {"sync", no_argument, 0, 's'}, - {"unique", no_argument, 0, 'u'}, - - {"config", required_argument, 0, OP_CONFIG}, - {0, 0, 0, 0} - }; - -#ifdef HAVE_LANGINFO_H - setlocale(LC_ALL, ""); - if(strcmp(nl_langinfo(CODESET), "UTF-8") == 0) { - style = &graph_utf8; - } -#else - style = &graph_default; -#endif - - while((opt = getopt_long(argc, argv, "ab:cd:ghlrsu", opts, &option_index))) { - if(opt < 0) { - break; - } - - switch(opt) { - case 'a': - style = &graph_default; - break; - case OP_CONFIG: - configfile = optarg; - break; - case 'b': - dbpath = optarg; - break; - case 'c': - color = &use_color; - break; - case 'd': - /* validate depth */ - max_depth = (int)strtol(optarg, &endptr, 10); - if(*endptr != '\0') { - fprintf(stderr, "error: invalid depth -- %s\n", optarg); - return 1; - } - break; - case 'g': - graphviz = 1; - break; - case 'l': - style = &graph_linear; - break; - case 'r': - reverse = 1; - break; - case 's': - searchsyncs = 1; - break; - case 'u': - unique = 1; - style = &graph_linear; - break; - case 'h': - case '?': - default: - return 1; - } - } - - if(!argv[optind]) { - return 1; - } - - return 0; -} - -static void usage(void) -{ - fprintf(stderr, "pactree (pacman) v" PACKAGE_VERSION "\n\n" - "A simple dependency tree viewer.\n\n" - "Usage: pactree [options] PACKAGE\n\n" - " -a, --ascii use ASCII characters for tree formatting\n" - " -b, --dbpath <path> set an alternate database location\n" - " -c, --color colorize output\n" - " -d, --depth <#> limit the depth of recursion\n" - " -g, --graph generate output for graphviz's dot\n" - " -h, --help display this help message\n" - " -l, --linear enable linear output\n" - " -r, --reverse list packages that depend on the named package\n" - " -s, --sync search sync databases instead of local\n" - " -u, --unique show dependencies with no duplicates (implies -l)\n" - " --config <path> set an alternate configuration file\n"); -} - -static void cleanup(void) -{ - alpm_list_free(walked); - alpm_list_free(provisions); - alpm_release(handle); -} - -/* pkg provides provision */ -static void print_text(const char *pkg, const char *provision, - tdepth *depth, int last) -{ - const char *tip = ""; - int level = 1; - if(!pkg && !provision) { - /* not much we can do */ - return; - } - - if(depth->level > 0) { - tip = last ? style->last : style->tip; - - /* print limbs */ - while(depth->prev) { - depth = depth->prev; - } - printf("%s", color->branch1); - while(depth->next) { - printf("%*s%-*s", style->indent * (depth->level - level), "", - style->indent, style->limb); - level = depth->level + 1; - depth = depth->next; - } - printf("%*s", style->indent * (depth->level - level), ""); - } - - /* print tip */ - /* If style->provides is empty (e.g. when using linear style), we do not - * want to print the provided package. This makes output easier to parse and - * to reuse. */ - if(!pkg && provision) { - printf("%s%s%s%s [unresolvable]%s\n", tip, color->leaf1, - provision, color->branch1, color->off); - } else if(provision && strcmp(pkg, provision) != 0 && *(style->provides) != '\0') { - printf("%s%s%s%s%s %s%s%s\n", tip, color->leaf1, pkg, - color->leaf2, style->provides, color->leaf1, provision, - color->off); - } else { - printf("%s%s%s%s\n", tip, color->leaf1, pkg, color->off); - } -} - -static void print_graph(const char *parentname, const char *pkgname, const char *depname) -{ - if(depname) { - printf("\"%s\" -> \"%s\" [color=chocolate4];\n", parentname, depname); - if(pkgname && strcmp(depname, pkgname) != 0 && !alpm_list_find_str(provisions, depname)) { - printf("\"%s\" -> \"%s\" [arrowhead=none, color=grey];\n", depname, pkgname); - provisions = alpm_list_add(provisions, (char *)depname); - } - } else if(pkgname) { - printf("\"%s\" -> \"%s\" [color=chocolate4];\n", parentname, pkgname); - } -} - -/* parent depends on dep which is satisfied by pkg */ -static void print(const char *parentname, const char *pkgname, - const char *depname, tdepth *depth, int last) -{ - if(graphviz) { - print_graph(parentname, pkgname, depname); - } else { - print_text(pkgname, depname, depth, last); - } -} - -static void print_start(const char *pkgname, const char *provname) -{ - if(graphviz) { - printf("digraph G { START [color=red, style=filled];\n" - "node [style=filled, color=green];\n" - " \"START\" -> \"%s\";\n", pkgname); - } else { - tdepth d = { - NULL, - NULL, - 0 - }; - print_text(pkgname, provname, &d, 0); - } -} - -static void print_end(void) -{ - if(graphviz) { - /* close graph output */ - printf("}\n"); - } -} - -static alpm_list_t *get_pkg_dep_names(alpm_pkg_t *pkg) -{ - alpm_list_t *i, *names = NULL; - for(i = alpm_pkg_get_depends(pkg); i; i = alpm_list_next(i)) { - alpm_depend_t *d = i->data; - names = alpm_list_add(names, d->name); - } - return names; -} - -/** - * walk dependencies, showing dependencies of the target - */ -static void walk_deps(alpm_list_t *dblist, alpm_pkg_t *pkg, tdepth *depth, int rev) -{ - alpm_list_t *deps, *i; - - if(!pkg || ((max_depth >= 0) && (depth->level > max_depth))) { - return; - } - - walked = alpm_list_add(walked, (void *)alpm_pkg_get_name(pkg)); - - if(rev) { - deps = alpm_pkg_compute_requiredby(pkg); - } else { - deps = get_pkg_dep_names(pkg); - } - - for(i = deps; i; i = alpm_list_next(i)) { - const char *pkgname = i->data; - int last = alpm_list_next(i) ? 0 : 1; - - alpm_pkg_t *dep_pkg = alpm_find_dbs_satisfier(handle, dblist, pkgname); - - if(alpm_list_find_str(walked, dep_pkg ? alpm_pkg_get_name(dep_pkg) : pkgname)) { - /* if we've already seen this package, don't print in "unique" output - * and don't recurse */ - if(!unique) { - print(alpm_pkg_get_name(pkg), alpm_pkg_get_name(dep_pkg), pkgname, depth, last); - } - } else { - print(alpm_pkg_get_name(pkg), alpm_pkg_get_name(dep_pkg), pkgname, depth, last); - if(dep_pkg) { - tdepth d = { - depth, - NULL, - depth->level + 1 - }; - depth->next = &d; - /* last dep, cut off the limb here */ - if(last) { - if(depth->prev) { - depth->prev->next = &d; - d.prev = depth->prev; - depth = &d; - } else { - d.prev = NULL; - } - } - walk_deps(dblist, dep_pkg, &d, rev); - depth->next = NULL; - } - } - } - - if(rev) { - FREELIST(deps); - } else { - alpm_list_free(deps); - } -} - -int main(int argc, char *argv[]) -{ - int freelist = 0, ret = 0; - alpm_errno_t err; - const char *target_name; - alpm_pkg_t *pkg; - alpm_list_t *dblist = NULL; - - if(parse_options(argc, argv) != 0) { - usage(); - ret = 1; - goto finish; - } - - handle = alpm_initialize(ROOTDIR, dbpath, &err); - if(!handle) { - fprintf(stderr, "error: cannot initialize alpm: %s\n", - alpm_strerror(err)); - ret = 1; - goto finish; - } - - if(searchsyncs) { - if(register_syncs() != 0) { - ret = 1; - goto finish; - } - dblist = alpm_get_syncdbs(handle); - } else { - dblist = alpm_list_add(dblist, alpm_get_localdb(handle)); - freelist = 1; - } - - /* we only care about the first non option arg for walking */ - target_name = argv[optind]; - - pkg = alpm_find_dbs_satisfier(handle, dblist, target_name); - if(!pkg) { - fprintf(stderr, "error: package '%s' not found\n", target_name); - ret = 1; - goto finish; - } - - print_start(alpm_pkg_get_name(pkg), target_name); - - tdepth d = { - NULL, - NULL, - 1 - }; - walk_deps(dblist, pkg, &d, reverse); - - print_end(); - - if(freelist) { - alpm_list_free(dblist); - } - -finish: - cleanup(); - return ret; -} - -/* vim: set noet: */ diff --git a/src/util/testpkg.c b/src/util/testpkg.c index 89e8dbd4..6bbded06 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-2016 Pacman Development Team <pacman-dev@archlinux.org> + * Copyright (c) 2007-2017 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 @@ -43,7 +43,7 @@ int main(int argc, char *argv[]) alpm_handle_t *handle; alpm_errno_t err; alpm_pkg_t *pkg = NULL; - const alpm_siglevel_t level = ALPM_SIG_PACKAGE | ALPM_SIG_PACKAGE_OPTIONAL; + const int siglevel = ALPM_SIG_PACKAGE | ALPM_SIG_PACKAGE_OPTIONAL; if(argc != 2) { fprintf(stderr, "testpkg (pacman) v" PACKAGE_VERSION "\n\n" @@ -64,7 +64,7 @@ int main(int argc, char *argv[]) /* set gpgdir to default */ alpm_option_set_gpgdir(handle, GPGDIR); - if(alpm_pkg_load(handle, argv[1], 1, level, &pkg) == -1 + if(alpm_pkg_load(handle, argv[1], 1, siglevel, &pkg) == -1 || pkg == NULL) { err = alpm_errno(handle); switch(err) { diff --git a/src/util/vercmp.c b/src/util/vercmp.c index adeebc0f..3521a96a 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-2016 Pacman Development Team <pacman-dev@archlinux.org> + * Copyright (c) 2006-2017 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 |