xbps-rindex(8): fix #19. An ATF test-case will be imported later.

This commit is contained in:
Juan RP
2013-11-02 11:34:55 +01:00
parent 2b40d8ad54
commit 616d4420d2
6 changed files with 168 additions and 13 deletions

View File

@ -45,6 +45,7 @@ usage(bool fail)
" --signedby <string> Signature details, i.e \"name <email>\"\n\n"
"MODE\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"
" -s --sign <repodir> Sign repository index\n\n");
exit(fail ? EXIT_FAILURE : EXIT_SUCCESS);
@ -53,9 +54,10 @@ usage(bool fail)
int
main(int argc, char **argv)
{
const char *shortopts = "afhrVv";
const char *shortopts = "acfhrVv";
struct option longopts[] = {
{ "add", no_argument, NULL, 'a' },
{ "clean", no_argument, NULL, 'c' },
{ "force", no_argument, NULL, 'f' },
{ "help", no_argument, NULL, 'h' },
{ "remove-obsoletes", no_argument, NULL, 'r' },
@ -69,9 +71,9 @@ main(int argc, char **argv)
struct xbps_handle xh;
const char *privkey = NULL, *signedby = NULL;
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) {
switch (c) {
@ -84,6 +86,9 @@ main(int argc, char **argv)
case 'a':
add_mode = true;
break;
case 'c':
clean_mode = true;
break;
case 'f':
force = true;
break;
@ -104,12 +109,13 @@ main(int argc, char **argv)
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);
} else if ((add_mode && (rm_mode || sign_mode)) ||
(rm_mode && (add_mode || sign_mode)) ||
(sign_mode && (add_mode || rm_mode))) {
fprintf(stderr, "Only one mode can be specified: add, "
} else if ((add_mode && (clean_mode || rm_mode || sign_mode)) ||
(clean_mode && (add_mode || rm_mode || sign_mode)) ||
(rm_mode && (add_mode || clean_mode || sign_mode)) ||
(sign_mode && (add_mode || clean_mode || rm_mode))) {
fprintf(stderr, "Only one mode can be specified: add, clean, "
"remove-obsoletes or sign.\n");
exit(EXIT_FAILURE);
}
@ -125,6 +131,8 @@ main(int argc, char **argv)
if (add_mode)
rv = index_add(&xh, argc - optind, argv + optind, force);
else if (clean_mode)
rv = index_clean(&xh, argv[optind]);
else if (rm_mode)
rv = remove_obsoletes(&xh, argv[optind]);
else if (sign_mode)