From 5e1432f41872dee9d822cf392d243f1f5710cbb2 Mon Sep 17 00:00:00 2001 From: Juan RP Date: Wed, 18 Sep 2013 16:45:05 +0200 Subject: [PATCH] Added support to specify multiple repositories via cmdline (close #17). --- bin/xbps-install/main.c | 16 ++++++++----- bin/xbps-install/xbps-install.8 | 6 ++--- bin/xbps-query/main.c | 14 +++++++---- bin/xbps-query/xbps-query.8 | 5 ++-- etc/xbps.conf | 2 +- include/xbps.h.in | 32 ++++++++++++------------- lib/initend.c | 41 +++++++++++++++++---------------- lib/rpool.c | 13 ++++------- 8 files changed, 67 insertions(+), 62 deletions(-) diff --git a/bin/xbps-install/main.c b/bin/xbps-install/main.c index bfe62fe1..e5ee5bf2 100644 --- a/bin/xbps-install/main.c +++ b/bin/xbps-install/main.c @@ -52,7 +52,8 @@ usage(bool fail) " overwritten.\n" " -h --help Print help usage\n" " -n --dry-run Dry-run mode\n" - " -R --repository Default repository to be used if config not set\n" + " -R --repository Repository to be used. Can be specified\n" + " multiple times.\n" " -r --rootdir Full path to rootdir\n" " -S --sync Sync remote repository index\n" " -u --update Update target package(s)\n" @@ -97,15 +98,17 @@ main(int argc, char **argv) }; struct xbps_handle xh; struct xferstat xfer; - const char *rootdir, *cachedir, *conffile, *defrepo; + const char *rootdir, *cachedir, *conffile; int i, c, flags, rv, fflag = 0; bool sync, yes, reinstall, drun, update; int maxcols; - rootdir = cachedir = conffile = defrepo = NULL; + rootdir = cachedir = conffile = NULL; flags = rv = 0; sync = yes = reinstall = drun = update = false; + memset(&xh, 0, sizeof(xh)); + while ((c = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1) { switch (c) { case 'A': @@ -133,7 +136,10 @@ main(int argc, char **argv) drun = true; break; case 'R': - defrepo = optarg; + if (xh.repositories == NULL) + xh.repositories = xbps_array_create(); + + xbps_array_add_cstring_nocopy(xh.repositories, optarg); break; case 'r': rootdir = optarg; @@ -165,7 +171,6 @@ main(int argc, char **argv) /* * Initialize libxbps. */ - memset(&xh, 0, sizeof(xh)); xh.state_cb = state_cb; xh.fetch_cb = fetch_file_progress_cb; xh.fetch_cb_data = &xfer; @@ -173,7 +178,6 @@ main(int argc, char **argv) xh.cachedir = cachedir; xh.conffile = conffile; xh.flags = flags; - xh.repository = defrepo; if (flags & XBPS_FLAG_VERBOSE) xh.unpack_cb = unpack_progress_cb; diff --git a/bin/xbps-install/xbps-install.8 b/bin/xbps-install/xbps-install.8 index 120f6c8f..057c2a50 100644 --- a/bin/xbps-install/xbps-install.8 +++ b/bin/xbps-install/xbps-install.8 @@ -1,4 +1,4 @@ -.Dd August 18, 2013 +.Dd September 18, 2013 .Os Void Linux .Dt xbps-install 8 .Sh NAME @@ -70,8 +70,8 @@ Show the help usage. .It Fl n, Fl -dry-run Dry-run mode. Show what actions would be done but don't do anything. .It Fl R, Fl -repository Ar uri -Default repository to be used overriding repository list in configuration file. -Only a single repository can be specified. +Default repository to be used. Multiple repositories can be specified. This repository +list overrides the list in a configuration file. .It Fl r, Fl -rootdir Ar dir Specifies a full path for the target root directory. .It Fl S, Fl -sync diff --git a/bin/xbps-query/main.c b/bin/xbps-query/main.c index 3b832dc2..0f6c61aa 100644 --- a/bin/xbps-query/main.c +++ b/bin/xbps-query/main.c @@ -40,10 +40,11 @@ usage(bool fail) "\nOPTIONS\n" " -C --config Full path to configuration file\n" " -c --cachedir Full path to cachedir\n" - " -D --defrepo Default repository to be used if config not set\n" + " -D --defrepo Repository to be used. Can be specified\n" + " multiple times.\n" " -d --debug Debug mode shown to stderr\n" " -h --help Print help usage\n" - " -R --repository Enable repository mode\n" + " -R --repoisotyr Enable repository mode\n" " -r --rootdir Full path to rootdir\n" " -V --version Show XBPS version\n" " -v --verbose Verbose messages\n" @@ -104,6 +105,8 @@ main(int argc, char **argv) show = show_rdeps = fulldeptree = false; repo_mode = opmode = false; + memset(&xh, 0, sizeof(xh)); + while ((c = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1) { switch (c) { case 'C': @@ -113,7 +116,10 @@ main(int argc, char **argv) cachedir = optarg; break; case 'D': - defrepo = optarg; + if (xh.repositories == NULL) + xh.repositories = xbps_array_create(); + + xbps_array_add_cstring_nocopy(xh.repositories, optarg); break; case 'd': flags |= XBPS_FLAG_DEBUG; @@ -183,12 +189,10 @@ main(int argc, char **argv) /* * Initialize libxbps. */ - memset(&xh, 0, sizeof(xh)); xh.rootdir = rootdir; xh.cachedir = cachedir; xh.conffile = conffile; xh.flags = flags; - xh.repository = defrepo; if ((rv = xbps_init(&xh)) != 0) { xbps_error_printf("Failed to initialize libxbps: %s\n", diff --git a/bin/xbps-query/xbps-query.8 b/bin/xbps-query/xbps-query.8 index 2a31f823..08cc6162 100644 --- a/bin/xbps-query/xbps-query.8 +++ b/bin/xbps-query/xbps-query.8 @@ -1,4 +1,4 @@ -.Dd September 13, 2013 +.Dd September 18, 2013 .Os Void Linux .Dt xbps-query 8 .Sh NAME @@ -55,7 +55,8 @@ Specifies a full path to the XBPS configuration file. .It Fl c, Fl -cachedir Ar dir Specifies a full path to the cache directory, where binary packages are stored. .It Fl D, Fl -defrepo Ar uri -Default repository to be used if no repository is specified in configuration file. +Default repository to be used. Multiple repositories can be specified. This repository +list overrides the list in a configuration file. .It Fl d, Fl -debug Enables extra debugging shown to stderr. .It Fl h, Fl -help diff --git a/etc/xbps.conf b/etc/xbps.conf index 3f556c57..59c4dc1b 100644 --- a/etc/xbps.conf +++ b/etc/xbps.conf @@ -32,7 +32,7 @@ # # By default we use the official "public" repositories. You can add # your own repositories by specifying the path to the directory -# where the plist index file is stored. +# where the -repodata file is stored. # # Repositories not matching the host architecture are simply ignored. # diff --git a/include/xbps.h.in b/include/xbps.h.in index f58fab48..6703c53e 100644 --- a/include/xbps.h.in +++ b/include/xbps.h.in @@ -46,7 +46,7 @@ * * This header documents the full API for the XBPS Library. */ -#define XBPS_API_VERSION "20130917" +#define XBPS_API_VERSION "20130918" #ifndef XBPS_VERSION #define XBPS_VERSION "UNSET" @@ -455,7 +455,7 @@ struct xbps_handle { /** * @var pkgdb * - * Internalized proplib dictionary with the master package database + * Proplib dictionary with the master package database * stored in XBPS_META_PATH/XBPS_PKGDB. */ xbps_dictionary_t pkgdb; @@ -470,10 +470,17 @@ struct xbps_handle { /** * @var transd * - * Proplib dictionary with transaction details, required by + * Proplib dictionary with transaction objects, required by * xbps_transaction_commit(). */ xbps_dictionary_t transd; + /** + * @var repositories + * + * Proplib array of strings with repositories, overriding the list + * in the configuration file. + */ + xbps_array_t repositories; /** * Pointer to the supplifed function callback to be used * in the XBPS possible states. @@ -531,6 +538,12 @@ struct xbps_handle { * If NULL, defaults to \a XBPS_CACHE_PATH (relative to rootdir). */ const char *metadir; + /** + * @var conffile + * + * Full path to the xbps configuration file. + */ + const char *conffile; /** * @private */ @@ -538,19 +551,6 @@ struct xbps_handle { char *metadir_priv; char *native_arch; const char *target_arch; - /* - * @var repository - * - * Default repository to be used if a configuration file - * couldn't be found. - */ - const char *repository; - /** - * @var conffile - * - * Full path to the xbps configuration file. - */ - const char *conffile; /** * @var fetch_timeout * diff --git a/lib/initend.c b/lib/initend.c index 377a26e2..a5c29638 100644 --- a/lib/initend.c +++ b/lib/initend.c @@ -75,22 +75,6 @@ set_metadir(struct xbps_handle *xh) } } -static int -config_inject_repos(struct xbps_handle *xh) -{ - char *buf; - - if (xh->repository) { - int rv; - - buf = xbps_xasprintf("repositories = { %s }", xh->repository); - if ((rv = cfg_parse_buf(xh->cfg, buf)) != 0) - return rv; - free(buf); - } - return 0; -} - static int cb_validate_virtual(cfg_t *cfg, cfg_opt_t *opt) { @@ -131,6 +115,7 @@ xbps_init(struct xbps_handle *xhp) CFG_END() }; struct utsname un; + const char *repodir; int rv, cc, cch; bool syslog_enabled = false; @@ -163,10 +148,6 @@ xbps_init(struct xbps_handle *xhp) return ENOTSUP; } } - /* Inject custom repo overriding the ones from configuration file */ - if ((rv = config_inject_repos(xhp)) != 0) - return rv; - xbps_dbg_printf(xhp, "Configuration file: %s\n", xhp->conffile ? xhp->conffile : "not found"); /* @@ -190,6 +171,19 @@ xbps_init(struct xbps_handle *xhp) xhp->rootdir = buf; } } + /* + * If repositories array is empty use the provided list from + * configuration file. + */ + if (xbps_array_count(xhp->repositories) == 0) { + for (unsigned int i = 0; i < cfg_size(xhp->cfg, "repositories"); i++) { + if (xhp->repositories == NULL) + xhp->repositories = xbps_array_create(); + + repodir = cfg_getnstr(xhp->cfg, "repositories", i); + xbps_array_add_cstring_nocopy(xhp->repositories, repodir); + } + } if (xhp->cachedir == NULL) { if (xhp->cfg == NULL) @@ -237,6 +231,13 @@ xbps_init(struct xbps_handle *xhp) xbps_dbg_printf(xhp, "Architecture: %s\n", xhp->native_arch); xbps_dbg_printf(xhp, "Target Architecture: %s\n", xhp->target_arch); + if (xhp->flags & XBPS_FLAG_DEBUG) { + for (unsigned int i = 0; i < xbps_array_count(xhp->repositories); i++) { + xbps_array_get_cstring_nocopy(xhp->repositories, i, &repodir); + xbps_dbg_printf(xhp, "Repository[%u]=%s\n", i, repodir); + } + } + xhp->initialized = true; return 0; diff --git a/lib/rpool.c b/lib/rpool.c index 3dcdada4..30b2d224 100644 --- a/lib/rpool.c +++ b/lib/rpool.c @@ -59,13 +59,11 @@ xbps_rpool_init(struct xbps_handle *xhp) if (xhp->rpool_initialized) return 0; - else if (xhp->cfg == NULL) - return ENOTSUP; - for (unsigned int i = 0; i < cfg_size(xhp->cfg, "repositories"); i++) { + for (unsigned int i = 0; i < xbps_array_count(xhp->repositories); i++) { rp = malloc(sizeof(struct rpool)); assert(rp); - repouri = cfg_getnstr(xhp->cfg, "repositories", i); + xbps_array_get_cstring_nocopy(xhp->repositories, i, &repouri); if ((rp->repo = xbps_repo_open(xhp, repouri)) == NULL) { rp->repo = calloc(1, sizeof(struct xbps_repo)); assert(rp->repo); @@ -114,11 +112,8 @@ xbps_rpool_sync(struct xbps_handle *xhp, const char *uri) { const char *repouri; - if (xhp->cfg == NULL) - return ENOTSUP; - - for (unsigned int i = 0; i < cfg_size(xhp->cfg, "repositories"); i++) { - repouri = cfg_getnstr(xhp->cfg, "repositories", i); + for (unsigned int i = 0; i < xbps_array_count(xhp->repositories); i++) { + xbps_array_get_cstring_nocopy(xhp->repositories, i, &repouri); /* If argument was set just process that repository */ if (uri && strcmp(repouri, uri)) continue;