diff --git a/bin/xbps-rindex/defs.h b/bin/xbps-rindex/defs.h index 62089f5e..ada46df8 100644 --- a/bin/xbps-rindex/defs.h +++ b/bin/xbps-rindex/defs.h @@ -70,7 +70,7 @@ int index_add(struct xbps_handle *, int, int, char **, bool); /* From index-clean.c */ -int index_clean(struct xbps_handle *, const char *); +int index_clean(struct xbps_handle *, const char *, bool); /* From remove-obsoletes.c */ int remove_obsoletes(struct xbps_handle *, const char *); diff --git a/bin/xbps-rindex/index-clean.c b/bin/xbps-rindex/index-clean.c index a3d3d1e3..364d57ed 100644 --- a/bin/xbps-rindex/index-clean.c +++ b/bin/xbps-rindex/index-clean.c @@ -40,6 +40,10 @@ static xbps_dictionary_t dest; +struct CleanerCbInfo { + const char *repourl; + bool hashcheck; +}; static int idx_cleaner_cb(struct xbps_handle *xhp, xbps_object_t obj, @@ -47,16 +51,16 @@ idx_cleaner_cb(struct xbps_handle *xhp, void *arg, bool *done _unused) { - const char *repourl = arg; + struct CleanerCbInfo *info = arg; const char *arch, *pkgver, *sha256; char *filen, *pkgname; xbps_dictionary_get_cstring_nocopy(obj, "architecture", &arch); xbps_dictionary_get_cstring_nocopy(obj, "pkgver", &pkgver); - xbps_dbg_printf(xhp, "%s: checking %s [%s] ...\n", repourl, pkgver, arch); + xbps_dbg_printf(xhp, "%s: checking %s [%s] ...\n", info->repourl, pkgver, arch); - filen = xbps_xasprintf("%s/%s.%s.xbps", repourl, pkgver, arch); + filen = xbps_xasprintf("%s/%s.%s.xbps", info->repourl, pkgver, arch); if (access(filen, R_OK) == -1) { /* * File cannot be read, might be permissions, @@ -68,7 +72,7 @@ idx_cleaner_cb(struct xbps_handle *xhp, xbps_dictionary_remove(dest, pkgname); free(pkgname); printf("index: removed pkg %s\n", pkgver); - } else { + } else if (info->hashcheck) { /* * File can be read; check its hash. */ @@ -90,15 +94,19 @@ out: static int cleanup_repo(struct xbps_handle *xhp, const char *repodir, struct xbps_repo *repo, - const char *reponame) { + const char *reponame, bool hashcheck) { int rv = 0; xbps_array_t allkeys; + struct CleanerCbInfo info = { + .hashcheck = hashcheck, + .repourl = repodir + }; /* * First pass: find out obsolete entries on index and index-files. */ dest = xbps_dictionary_copy_mutable(repo->idx); allkeys = xbps_dictionary_all_keys(dest); - (void)xbps_array_foreach_cb_multi(xhp, allkeys, repo->idx, idx_cleaner_cb, __UNCONST(repodir)); + (void)xbps_array_foreach_cb_multi(xhp, allkeys, repo->idx, idx_cleaner_cb, &info); xbps_object_release(allkeys); if(strcmp("stagedata", reponame) == 0 && xbps_dictionary_count(dest) == 0) { @@ -126,7 +134,7 @@ cleanup_repo(struct xbps_handle *xhp, const char *repodir, struct xbps_repo *rep * binary package cannot be read (unavailable, not enough perms, etc). */ int -index_clean(struct xbps_handle *xhp, const char *repodir) +index_clean(struct xbps_handle *xhp, const char *repodir, const bool hashcheck) { struct xbps_repo *repo, *stage; char *rlockfname = NULL; @@ -158,10 +166,10 @@ index_clean(struct xbps_handle *xhp, const char *repodir) } printf("Cleaning `%s' index, please wait...\n", repodir); - if((rv = cleanup_repo(xhp, repodir, repo, "repodata"))) + if((rv = cleanup_repo(xhp, repodir, repo, "repodata", hashcheck))) goto out; if(stage) { - cleanup_repo(xhp, repodir, stage, "stagedata"); + cleanup_repo(xhp, repodir, stage, "stagedata", hashcheck); } out: diff --git a/bin/xbps-rindex/main.c b/bin/xbps-rindex/main.c index 2542f159..b3ede2e2 100644 --- a/bin/xbps-rindex/main.c +++ b/bin/xbps-rindex/main.c @@ -42,6 +42,7 @@ usage(bool fail) " -h --help Show help usage\n" " -v --verbose Verbose messages\n" " -V --version Show XBPS version\n" + " -C --hashcheck Consider file hashes for cleaning up packages\n" " --privkey Path to the private key for signing\n" " --signedby Signature details, i.e \"name \"\n\n" "MODE\n" @@ -56,7 +57,7 @@ usage(bool fail) int main(int argc, char **argv) { - const char *shortopts = "acdfhrsSVv"; + const char *shortopts = "acdfhrsCSVv"; struct option longopts[] = { { "add", no_argument, NULL, 'a' }, { "clean", no_argument, NULL, 'c' }, @@ -70,14 +71,17 @@ main(int argc, char **argv) { "signedby", required_argument, NULL, 1}, { "sign", no_argument, NULL, 's'}, { "sign-pkg", no_argument, NULL, 'S'}, + { "hashcheck", no_argument, NULL, 'C' }, { NULL, 0, NULL, 0 } }; struct xbps_handle xh; const char *privkey = NULL, *signedby = NULL; int rv, c, flags = 0; - bool add_mode, clean_mode, rm_mode, sign_mode, sign_pkg_mode, force; + bool add_mode, clean_mode, rm_mode, sign_mode, sign_pkg_mode, force, + hashcheck; - add_mode = clean_mode = rm_mode = sign_mode = sign_pkg_mode = force = false; + add_mode = clean_mode = rm_mode = sign_mode = sign_pkg_mode = force = + hashcheck = false; while ((c = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1) { switch (c) { @@ -108,6 +112,9 @@ main(int argc, char **argv) case 's': sign_mode = true; break; + case 'C': + hashcheck = true; + break; case 'S': sign_pkg_mode = true; break; @@ -144,7 +151,7 @@ main(int argc, char **argv) if (add_mode) rv = index_add(&xh, optind, argc, argv, force); else if (clean_mode) - rv = index_clean(&xh, argv[optind]); + rv = index_clean(&xh, argv[optind], hashcheck); else if (rm_mode) rv = remove_obsoletes(&xh, argv[optind]); else if (sign_mode)