xbps-rindex: added -f --force flag to forcefully register a pkg with -a --add.

This commit is contained in:
Juan RP 2013-05-02 10:46:30 +02:00
parent 30747b1c8b
commit 53217fd51b
5 changed files with 22 additions and 9 deletions

2
NEWS
View File

@ -1,5 +1,7 @@
xbps-0.24 (???):
* xbps-rindex(8): added -f, --force flag to forcefully register a package even
if an entry of the same package already exists on the index.
xbps-0.23 (2013-04-19):

View File

@ -1,5 +1,5 @@
/*-
* Copyright (c) 2012 Juan Romero Pardines.
* Copyright (c) 2012-2013 Juan Romero Pardines.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@ -29,7 +29,7 @@
#include <xbps_api.h>
/* From index-add.c */
int index_add(struct xbps_handle *, int, char **);
int index_add(struct xbps_handle *, int, char **, bool);
/* From index-clean.c */
int index_clean(struct xbps_handle *, const char *);

View File

@ -41,7 +41,7 @@
* and entry when it's necessary.
*/
int
index_add(struct xbps_handle *xhp, int argc, char **argv)
index_add(struct xbps_handle *xhp, int argc, char **argv, bool force)
{
prop_array_t filespkgar, pkg_files, pkg_links, pkg_cffiles;
prop_dictionary_t idx, idxfiles, newpkgd, newpkgfilesd, curpkgd;
@ -134,7 +134,8 @@ index_add(struct xbps_handle *xhp, int argc, char **argv)
free(pkgname);
return errno;
}
} else {
} else if (!force) {
/* Only check version if !force */
prop_dictionary_get_cstring_nocopy(curpkgd,
"pkgver", &oldpkgver);
prop_dictionary_get_cstring_nocopy(curpkgd,

View File

@ -1,5 +1,5 @@
/*-
* Copyright (c) 2012 Juan Romero Pardines.
* Copyright (c) 2012-2013 Juan Romero Pardines.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@ -37,6 +37,7 @@ usage(bool fail)
fprintf(stdout,
"Usage: xbps-rindex [OPTIONS] MODE ARGUMENTS\n\n"
"OPTIONS\n"
" -f --force Force mode to overwrite entry in add mode\n"
" -h --help Show help usage\n"
" -V --version Show XBPS version\n\n"
"MODE\n"
@ -49,10 +50,11 @@ usage(bool fail)
int
main(int argc, char **argv)
{
const char *shortopts = "achrV";
const char *shortopts = "acfhrV";
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' },
{ "version", no_argument, NULL, 'V' },
@ -60,7 +62,7 @@ main(int argc, char **argv)
};
struct xbps_handle xh;
int rv, c;
bool clean_mode = false, add_mode = false, rm_mode = false;
bool clean_mode = false, add_mode = false, rm_mode = false, force = false;
while ((c = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1) {
switch (c) {
@ -70,6 +72,9 @@ main(int argc, char **argv)
case 'c':
clean_mode = true;
break;
case 'f':
force = true;
break;
case 'h':
usage(false);
/* NOTREACHED */
@ -100,7 +105,7 @@ main(int argc, char **argv)
}
if (add_mode)
rv = index_add(&xh, argc - optind, argv + optind);
rv = index_add(&xh, argc - optind, argv + optind, force);
else if (clean_mode)
rv = index_clean(&xh, argv[optind]);
else if (rm_mode)

View File

@ -1,4 +1,4 @@
.Dd February 20, 2013
.Dd May 2, 2013
.Os Void Linux
.Dt xbps-rindex 8
.Sh NAME
@ -16,6 +16,11 @@ utility creates, updates and removes obsolete binary packages stored
in local repositories.
.Sh OPTIONS
.Bl -tag -width -x
.It Fl f -force
Forcefully register binary package into the local repository, overwriting existing entry.
This flag is only useful with the
.Em add
mode.
.It Fl h -help
Show the help usage.
.It Fl V -version