From 20f2d105277999a70337c21587fd279410522b92 Mon Sep 17 00:00:00 2001 From: Juan RP Date: Fri, 26 Jul 2013 11:42:52 +0200 Subject: [PATCH] xbps-query(8): -L now prints all repos, including non working repos (close #11). --- NEWS | 10 ++++++++++ bin/xbps-query/list.c | 3 +-- bin/xbps-query/xbps-query.8 | 6 ++++-- lib/repo.c | 23 +++++++++++++++++------ lib/rpool.c | 9 ++------- 5 files changed, 34 insertions(+), 17 deletions(-) diff --git a/NEWS b/NEWS index 81b56aa0..c5751112 100644 --- a/NEWS +++ b/NEWS @@ -1,5 +1,15 @@ xbps-0.26 (???): + * xbps-query(8): make -L list all repositories in the configuration file, even + the non working ones and print -1 in them. Closes issue #11 from github. + + $ xbps-query -L + -1 /mnt/foo + -1 /blah/foo + 2619 /mnt/xbps_builder/host/binpkgs + 16 /mnt/xbps_builder/host/binpkgs/nonfree + $ + * xbps-query(8): fixed some memleaks in local and repository owned mode. * xbps-query(8): fix regression in -R, also print repository string object. diff --git a/bin/xbps-query/list.c b/bin/xbps-query/list.c index 0de27531..194ee5cf 100644 --- a/bin/xbps-query/list.c +++ b/bin/xbps-query/list.c @@ -156,8 +156,7 @@ repo_list_uri_cb(struct xbps_repo *repo, void *arg, bool *done) (void)arg; (void)done; - printf("%s (%u packages)\n", repo->uri, - xbps_dictionary_count(repo->idx)); + printf("%5zd %s\n", repo->idx ? (ssize_t)xbps_dictionary_count(repo->idx) : -1, repo->uri); return 0; } diff --git a/bin/xbps-query/xbps-query.8 b/bin/xbps-query/xbps-query.8 index 66df8775..b4e0363e 100644 --- a/bin/xbps-query/xbps-query.8 +++ b/bin/xbps-query/xbps-query.8 @@ -1,4 +1,4 @@ -.Dd March 4, 2013 +.Dd July 26, 2013 .Os Void Linux .Dt xbps-query 8 .Sh NAME @@ -101,7 +101,9 @@ and can be fully removed with Package state is unknown. .El .It Fl L, Fl -list-repos -Lists registered and working repositories. +Lists repositories and the number of packages contained on them. If a repository is not +available the number of packages will be +.Sy -1 . .It Fl m, Fl -list-manual-pkgs Lists registered packages in the package database (pkgdb) that were installed manually by the user (i.e not as dependency of any package). diff --git a/lib/repo.c b/lib/repo.c index 906cae90..92febff6 100644 --- a/lib/repo.c +++ b/lib/repo.c @@ -84,7 +84,7 @@ xbps_repo_open(struct xbps_handle *xhp, const char *url) archive_read_support_format_tar(repo->ar); if (archive_read_open_filename(repo->ar, repofile, ARCHIVE_READ_BLOCKSIZE)) { - xbps_dbg_printf(xhp, "cannot open repository file %s: %s\n", + xbps_dbg_printf(xhp, "[repo] cannot open repository file %s: %s\n", repofile, strerror(archive_errno(repo->ar))); archive_read_free(repo->ar); free(repo); @@ -105,9 +105,11 @@ xbps_repo_get_plist(struct xbps_repo *repo, const char *file) int rv; assert(repo); - assert(repo->ar); assert(file); + if (repo->ar == NULL) + return NULL; + for (;;) { rv = archive_read_next_header(repo->ar, &entry); if (rv == ARCHIVE_EOF || rv == ARCHIVE_FATAL) @@ -137,6 +139,9 @@ xbps_repo_close(struct xbps_repo *repo) { assert(repo); + if (repo->ar == NULL) + return; + archive_read_free(repo->ar); if (xbps_object_type(repo->idx) == XBPS_TYPE_DICTIONARY) xbps_object_release(repo->idx); @@ -151,12 +156,15 @@ xbps_repo_get_virtualpkg(struct xbps_repo *repo, const char *pkg) xbps_dictionary_t pkgd; assert(repo); - assert(repo->ar); assert(pkg); + if (repo->ar == NULL) + return NULL; + if (xbps_object_type(repo->idx) != XBPS_TYPE_DICTIONARY) { repo->idx = xbps_repo_get_plist(repo, XBPS_PKGINDEX); - assert(repo->idx); + if (repo->idx == NULL) + return NULL; } pkgd = xbps_find_virtualpkg_in_dict(repo->xhp, repo->idx, pkg); if (pkgd) { @@ -173,12 +181,15 @@ xbps_repo_get_pkg(struct xbps_repo *repo, const char *pkg) xbps_dictionary_t pkgd; assert(repo); - assert(repo->ar); assert(pkg); + if (repo->ar == NULL) + return NULL; + if (xbps_object_type(repo->idx) != XBPS_TYPE_DICTIONARY) { repo->idx = xbps_repo_get_plist(repo, XBPS_PKGINDEX); - assert(repo->idx); + if (repo->idx == NULL) + return NULL; } pkgd = xbps_find_pkg_in_dict(repo->idx, pkg); if (pkgd) { diff --git a/lib/rpool.c b/lib/rpool.c index 927f6903..cc1b4100 100644 --- a/lib/rpool.c +++ b/lib/rpool.c @@ -68,15 +68,10 @@ xbps_rpool_init(struct xbps_handle *xhp) assert(rp); repouri = cfg_getnstr(xhp->cfg, "repositories", i); if ((rp->repo = xbps_repo_open(xhp, repouri)) == NULL) { - free(rp); - continue; + rp->repo = calloc(1, sizeof(struct xbps_repo)); + assert(rp->repo); } rp->repo->idx = xbps_repo_get_plist(rp->repo, XBPS_PKGINDEX); - if (rp->repo->idx == NULL) { - xbps_repo_close(rp->repo); - free(rp); - continue; - } rp->repo->uri = repouri; rp->repo->xhp = xhp; SIMPLEQ_INSERT_TAIL(&rpool_queue, rp, entries);