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