xbps-rindex(8): fix #19. An ATF test-case will be imported later.
This commit is contained in:
parent
2b40d8ad54
commit
616d4420d2
5
NEWS
5
NEWS
@ -1,5 +1,7 @@
|
|||||||
xbps-0.27 (???):
|
xbps-0.27 (???):
|
||||||
|
|
||||||
|
* Fixed issue #19: https://github.com/xtraeme/xbps/issues/19
|
||||||
|
|
||||||
* Fixed issue #18: https://github.com/xtraeme/xbps/issues/18
|
* Fixed issue #18: https://github.com/xtraeme/xbps/issues/18
|
||||||
|
|
||||||
* xbps-rindex(8): also understands the XBPS_PASSPHRASE environmental variable to
|
* xbps-rindex(8): also understands the XBPS_PASSPHRASE environmental variable to
|
||||||
@ -7,9 +9,6 @@ xbps-0.27 (???):
|
|||||||
|
|
||||||
* xbps-rindex(8): added -v --verbose option.
|
* xbps-rindex(8): added -v --verbose option.
|
||||||
|
|
||||||
* xbps-rindex(8): -c --clean mode has been removed. Generating a local repository
|
|
||||||
is almost as fast as cleaning up the repository data.
|
|
||||||
|
|
||||||
* xbps-rkeys(8): new utility to manage RSA public keys from remote signed repositories.
|
* xbps-rkeys(8): new utility to manage RSA public keys from remote signed repositories.
|
||||||
|
|
||||||
* Support for RSA signed repositories. A repository can be signed with your
|
* Support for RSA signed repositories. A repository can be signed with your
|
||||||
|
@ -2,6 +2,6 @@ TOPDIR = ../..
|
|||||||
-include $(TOPDIR)/config.mk
|
-include $(TOPDIR)/config.mk
|
||||||
|
|
||||||
BIN = xbps-rindex
|
BIN = xbps-rindex
|
||||||
OBJS = main.o index-add.o remove-obsoletes.o repoflush.o sign.o
|
OBJS = main.o index-add.o index-clean.o remove-obsoletes.o repoflush.o sign.o
|
||||||
|
|
||||||
include $(TOPDIR)/mk/prog.mk
|
include $(TOPDIR)/mk/prog.mk
|
||||||
|
@ -67,6 +67,9 @@
|
|||||||
/* From index-add.c */
|
/* From index-add.c */
|
||||||
int index_add(struct xbps_handle *, int, char **, bool);
|
int index_add(struct xbps_handle *, int, char **, bool);
|
||||||
|
|
||||||
|
/* From index-clean.c */
|
||||||
|
int index_clean(struct xbps_handle *, const char *);
|
||||||
|
|
||||||
/* From remove-obsoletes.c */
|
/* From remove-obsoletes.c */
|
||||||
int remove_obsoletes(struct xbps_handle *, const char *);
|
int remove_obsoletes(struct xbps_handle *, const char *);
|
||||||
|
|
||||||
|
143
bin/xbps-rindex/index-clean.c
Normal file
143
bin/xbps-rindex/index-clean.c
Normal file
@ -0,0 +1,143 @@
|
|||||||
|
/*-
|
||||||
|
* Copyright (c) 2012-2013 Juan Romero Pardines.
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
||||||
|
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||||
|
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||||
|
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||||
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||||
|
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||||
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||||
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||||
|
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <sys/stat.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#include <dirent.h>
|
||||||
|
#include <libgen.h>
|
||||||
|
#include <assert.h>
|
||||||
|
#include <pthread.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
|
||||||
|
#include <xbps.h>
|
||||||
|
#include "defs.h"
|
||||||
|
|
||||||
|
static int
|
||||||
|
idx_cleaner_cb(struct xbps_handle *xhp,
|
||||||
|
xbps_object_t obj,
|
||||||
|
const char *key _unused,
|
||||||
|
void *arg,
|
||||||
|
bool *done _unused)
|
||||||
|
{
|
||||||
|
|
||||||
|
xbps_array_t result = arg;
|
||||||
|
const char *arch, *pkgver, *sha256, *repoloc;
|
||||||
|
char *filen;
|
||||||
|
|
||||||
|
xbps_dictionary_get_cstring_nocopy(obj, "architecture", &arch);
|
||||||
|
xbps_dictionary_get_cstring_nocopy(obj, "pkgver", &pkgver);
|
||||||
|
xbps_dictionary_get_cstring_nocopy(obj, "repository", &repoloc);
|
||||||
|
|
||||||
|
xbps_dbg_printf(xhp, "%s: checking %s [%s] ...", pkgver, arch);
|
||||||
|
|
||||||
|
filen = xbps_xasprintf("%s/%s.%s.xbps", repoloc, pkgver, arch);
|
||||||
|
if (access(filen, R_OK) == -1) {
|
||||||
|
/*
|
||||||
|
* File cannot be read, might be permissions,
|
||||||
|
* broken or simply unexistent; either way, remove it.
|
||||||
|
*/
|
||||||
|
xbps_array_add_cstring_nocopy(result, pkgver);
|
||||||
|
} else {
|
||||||
|
/*
|
||||||
|
* File can be read; check its hash.
|
||||||
|
*/
|
||||||
|
xbps_dictionary_get_cstring_nocopy(obj,
|
||||||
|
"filename-sha256", &sha256);
|
||||||
|
if (xbps_file_hash_check(filen, sha256) != 0)
|
||||||
|
xbps_array_add_cstring_nocopy(result, pkgver);
|
||||||
|
}
|
||||||
|
free(filen);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Removes stalled pkg entries in repository's XBPS_REPOIDX file, if any
|
||||||
|
* binary package cannot be read (unavailable, not enough perms, etc).
|
||||||
|
*/
|
||||||
|
int
|
||||||
|
index_clean(struct xbps_handle *xhp, const char *repodir)
|
||||||
|
{
|
||||||
|
struct xbps_repo *repo;
|
||||||
|
xbps_array_t result = NULL, allkeys;
|
||||||
|
xbps_dictionary_t idx, idxfiles;
|
||||||
|
const char *keyname;
|
||||||
|
char *pkgname;
|
||||||
|
int rv = 0;
|
||||||
|
bool flush = false;
|
||||||
|
|
||||||
|
repo = xbps_repo_open(xhp, repodir);
|
||||||
|
if (repo == NULL) {
|
||||||
|
if (errno == ENOENT)
|
||||||
|
return 0;
|
||||||
|
fprintf(stderr, "index: cannot read repository data: %s\n", strerror(errno));
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
xbps_repo_open_idxfiles(repo);
|
||||||
|
idx = xbps_dictionary_copy(repo->idx);
|
||||||
|
idxfiles = xbps_dictionary_copy(repo->idxfiles);
|
||||||
|
xbps_repo_close(repo);
|
||||||
|
if (idx == NULL || idxfiles == NULL) {
|
||||||
|
fprintf(stderr, "incomplete repository data file!");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
printf("Cleaning `%s' index, please wait...\n", repodir);
|
||||||
|
|
||||||
|
result = xbps_array_create();
|
||||||
|
allkeys = xbps_dictionary_all_keys(idx);
|
||||||
|
rv = xbps_array_foreach_cb(xhp, allkeys, idx, idx_cleaner_cb, result);
|
||||||
|
|
||||||
|
for (unsigned int x = 0; x < xbps_array_count(result); x++) {
|
||||||
|
xbps_array_get_cstring_nocopy(result, x, &keyname);
|
||||||
|
printf("index: removed entry %s\n", keyname);
|
||||||
|
pkgname = xbps_pkg_name(keyname);
|
||||||
|
xbps_dictionary_remove(idx, pkgname);
|
||||||
|
xbps_dictionary_remove(idxfiles, keyname);
|
||||||
|
free(pkgname);
|
||||||
|
flush = true;
|
||||||
|
}
|
||||||
|
xbps_object_release(result);
|
||||||
|
xbps_object_release(allkeys);
|
||||||
|
|
||||||
|
if (flush) {
|
||||||
|
if (!repodata_flush(xhp, repodir, idx, idxfiles, NULL)) {
|
||||||
|
fprintf(stderr, "failed to write repodata: %s\n",
|
||||||
|
strerror(errno));
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
printf("index: %u packages registered.\n",
|
||||||
|
xbps_dictionary_count(idx));
|
||||||
|
printf("index-files: %u packages registered.\n",
|
||||||
|
xbps_dictionary_count(idxfiles));
|
||||||
|
|
||||||
|
xbps_object_release(idx);
|
||||||
|
xbps_object_release(idxfiles);
|
||||||
|
|
||||||
|
return rv;
|
||||||
|
}
|
@ -45,6 +45,7 @@ usage(bool fail)
|
|||||||
" --signedby <string> Signature details, i.e \"name <email>\"\n\n"
|
" --signedby <string> Signature details, i.e \"name <email>\"\n\n"
|
||||||
"MODE\n"
|
"MODE\n"
|
||||||
" -a --add <repodir/pkg> ... Add package(s) to repository index\n"
|
" -a --add <repodir/pkg> ... Add package(s) to repository index\n"
|
||||||
|
" -c --clean <repodir> Clean repository index\n"
|
||||||
" -r --remove-obsoletes <repodir> Removes obsolete packages from repository\n"
|
" -r --remove-obsoletes <repodir> Removes obsolete packages from repository\n"
|
||||||
" -s --sign <repodir> Sign repository index\n\n");
|
" -s --sign <repodir> Sign repository index\n\n");
|
||||||
exit(fail ? EXIT_FAILURE : EXIT_SUCCESS);
|
exit(fail ? EXIT_FAILURE : EXIT_SUCCESS);
|
||||||
@ -53,9 +54,10 @@ usage(bool fail)
|
|||||||
int
|
int
|
||||||
main(int argc, char **argv)
|
main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
const char *shortopts = "afhrVv";
|
const char *shortopts = "acfhrVv";
|
||||||
struct option longopts[] = {
|
struct option longopts[] = {
|
||||||
{ "add", no_argument, NULL, 'a' },
|
{ "add", no_argument, NULL, 'a' },
|
||||||
|
{ "clean", no_argument, NULL, 'c' },
|
||||||
{ "force", no_argument, NULL, 'f' },
|
{ "force", no_argument, NULL, 'f' },
|
||||||
{ "help", no_argument, NULL, 'h' },
|
{ "help", no_argument, NULL, 'h' },
|
||||||
{ "remove-obsoletes", no_argument, NULL, 'r' },
|
{ "remove-obsoletes", no_argument, NULL, 'r' },
|
||||||
@ -69,9 +71,9 @@ main(int argc, char **argv)
|
|||||||
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, rm_mode, sign_mode, force;
|
bool add_mode, clean_mode, rm_mode, sign_mode, force;
|
||||||
|
|
||||||
add_mode = rm_mode = sign_mode = force = false;
|
add_mode = clean_mode = rm_mode = sign_mode = force = 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) {
|
||||||
@ -84,6 +86,9 @@ main(int argc, char **argv)
|
|||||||
case 'a':
|
case 'a':
|
||||||
add_mode = true;
|
add_mode = true;
|
||||||
break;
|
break;
|
||||||
|
case 'c':
|
||||||
|
clean_mode = true;
|
||||||
|
break;
|
||||||
case 'f':
|
case 'f':
|
||||||
force = true;
|
force = true;
|
||||||
break;
|
break;
|
||||||
@ -104,12 +109,13 @@ main(int argc, char **argv)
|
|||||||
exit(EXIT_SUCCESS);
|
exit(EXIT_SUCCESS);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ((argc == optind) || (!add_mode && !rm_mode && !sign_mode)) {
|
if ((argc == optind) || (!add_mode && !clean_mode && !rm_mode && !sign_mode)) {
|
||||||
usage(true);
|
usage(true);
|
||||||
} else if ((add_mode && (rm_mode || sign_mode)) ||
|
} else if ((add_mode && (clean_mode || rm_mode || sign_mode)) ||
|
||||||
(rm_mode && (add_mode || sign_mode)) ||
|
(clean_mode && (add_mode || rm_mode || sign_mode)) ||
|
||||||
(sign_mode && (add_mode || rm_mode))) {
|
(rm_mode && (add_mode || clean_mode || sign_mode)) ||
|
||||||
fprintf(stderr, "Only one mode can be specified: add, "
|
(sign_mode && (add_mode || clean_mode || rm_mode))) {
|
||||||
|
fprintf(stderr, "Only one mode can be specified: add, clean, "
|
||||||
"remove-obsoletes or sign.\n");
|
"remove-obsoletes or sign.\n");
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
@ -125,6 +131,8 @@ main(int argc, char **argv)
|
|||||||
|
|
||||||
if (add_mode)
|
if (add_mode)
|
||||||
rv = index_add(&xh, argc - optind, argv + optind, force);
|
rv = index_add(&xh, argc - optind, argv + optind, force);
|
||||||
|
else if (clean_mode)
|
||||||
|
rv = index_clean(&xh, argv[optind]);
|
||||||
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)
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
.Dd October 12, 2013
|
.Dd November 2, 2013
|
||||||
.Os Void Linux
|
.Os Void Linux
|
||||||
.Dt xbps-rindex 8
|
.Dt xbps-rindex 8
|
||||||
.Sh NAME
|
.Sh NAME
|
||||||
@ -37,6 +37,8 @@ Path to the private RSA key to sign the repository. If unset, defaults to
|
|||||||
Registers the binary package into the local repository. The specified binary
|
Registers the binary package into the local repository. The specified binary
|
||||||
package is only added to the index if its version is greater than the one
|
package is only added to the index if its version is greater than the one
|
||||||
currently stored. Multiple binary packages can be specified as arguments.
|
currently stored. Multiple binary packages can be specified as arguments.
|
||||||
|
.It Sy -c, --clean Ar repository
|
||||||
|
Removes obsolete entries found in the local repository.
|
||||||
.It Sy -r, --remove-obsoletes Ar repository
|
.It Sy -r, --remove-obsoletes Ar repository
|
||||||
Removes obsolete packages from
|
Removes obsolete packages from
|
||||||
.Ar repository .
|
.Ar repository .
|
||||||
|
Loading…
Reference in New Issue
Block a user