xbps-checkvers: misc changes to fix issues I've found.
- Clear completely the rcv struct. - Remove unapplicable free()a before assignment (wtf) - Fix usage, -C expects a path to a directory not a filename. - Remove obsolete xbps.conf handling, this is unnecessary (xbps.d(5)). - Random tweaks after a quick inspection.
This commit is contained in:
parent
cbf1cfe0f5
commit
d519ed3d15
@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
|
* Copyright (c) 2014-2015 Juan Romero Pardines
|
||||||
* Copyright (c) 2012-2014 Dave Elusive <davehome@redthumb.info.tm>
|
* Copyright (c) 2012-2014 Dave Elusive <davehome@redthumb.info.tm>
|
||||||
* Copyright (c) 2014 Juan Romero Pardines
|
|
||||||
* All rights reserved
|
* All rights reserved
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
@ -35,6 +35,7 @@
|
|||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
#include <dirent.h>
|
#include <dirent.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
|
#include <assert.h>
|
||||||
|
|
||||||
#include <xbps.h>
|
#include <xbps.h>
|
||||||
|
|
||||||
@ -101,6 +102,7 @@ map_create(void)
|
|||||||
map->size = 16;
|
map->size = 16;
|
||||||
map->len = 0;
|
map->len = 0;
|
||||||
map->items = calloc(map->size, sizeof(map_item_t));
|
map->items = calloc(map->size, sizeof(map_item_t));
|
||||||
|
assert(map->items);
|
||||||
for (; i < map->size; i++) {
|
for (; i < map->size; i++) {
|
||||||
map->items[i] = map_new_item();
|
map->items[i] = map_new_item();
|
||||||
}
|
}
|
||||||
@ -188,8 +190,7 @@ show_usage(const char *prog)
|
|||||||
"Usage: %s [OPTIONS] [FILES...]\n\n"
|
"Usage: %s [OPTIONS] [FILES...]\n\n"
|
||||||
" Options:\n"
|
" Options:\n"
|
||||||
" -h,--help Show this helpful help-message for help.\n"
|
" -h,--help Show this helpful help-message for help.\n"
|
||||||
" -C,--config=FILENAME Set (or override) the `xbps.conf' (which may\n"
|
" -C,--config=DIRECTORY Set path to xbps.d\n"
|
||||||
" have automatically been detected).\n"
|
|
||||||
" -D,--distdir=DIRECTORY Set (or override) the path to void-packages\n"
|
" -D,--distdir=DIRECTORY Set (or override) the path to void-packages\n"
|
||||||
" (defaults to ~/void-packages).\n"
|
" (defaults to ~/void-packages).\n"
|
||||||
" -d,--debug Enable debug output to stderr.\n"
|
" -d,--debug Enable debug output to stderr.\n"
|
||||||
@ -478,32 +479,6 @@ rcv_set_distdir(rcv_t *rcv, const char *distdir)
|
|||||||
rcv->pkgdir = strcat(rcv->pkgdir, "/srcpkgs");
|
rcv->pkgdir = strcat(rcv->pkgdir, "/srcpkgs");
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
|
||||||
rcv_find_conf(rcv_t *rcv)
|
|
||||||
{
|
|
||||||
FILE *fp;
|
|
||||||
const char **lp, *conf;
|
|
||||||
|
|
||||||
const char *xbps_locs[] = {
|
|
||||||
XBPS_SYSCONF_PATH "/xbps.conf",
|
|
||||||
"/etc/xbps/xbps.conf",
|
|
||||||
"/usr/local/etc/xbps/xbps.conf", NULL
|
|
||||||
};
|
|
||||||
|
|
||||||
if (!rcv->xbps_conf) {
|
|
||||||
for (lp = xbps_locs; (conf = *lp++);) {
|
|
||||||
if ((fp = fopen(conf, "r")) != NULL) {
|
|
||||||
fclose(fp);
|
|
||||||
rcv->xbps_conf = calloc(strlen(conf) + 1,
|
|
||||||
sizeof(char));
|
|
||||||
rcv->xbps_conf = strcpy(rcv->xbps_conf, conf);
|
|
||||||
rcv->xbps_conf[strlen(conf)] = '\0';
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
check_reverts(const char *repover, const map_item_t reverts)
|
check_reverts(const char *repover, const map_item_t reverts)
|
||||||
{
|
{
|
||||||
@ -669,19 +644,16 @@ main(int argc, char **argv)
|
|||||||
{ NULL, 0, NULL, 0 }
|
{ NULL, 0, NULL, 0 }
|
||||||
};
|
};
|
||||||
|
|
||||||
memset(&rcv, 0, sizeof(rcv));
|
memset(&rcv, 0, sizeof(rcv_t));
|
||||||
|
|
||||||
while ((c = getopt_long(argc, argv, sopts, lopts, NULL)) != -1) {
|
while ((c = getopt_long(argc, argv, sopts, lopts, NULL)) != -1) {
|
||||||
switch (c) {
|
switch (c) {
|
||||||
case 'h':
|
case 'h':
|
||||||
return show_usage(prog);
|
return show_usage(prog);
|
||||||
case 'C':
|
case 'C':
|
||||||
free(rcv.xbps_conf);
|
|
||||||
rcv.xbps_conf = strdup(optarg);
|
rcv.xbps_conf = strdup(optarg);
|
||||||
break;
|
break;
|
||||||
case 'D':
|
case 'D':
|
||||||
free(rcv.distdir); rcv.distdir = NULL;
|
|
||||||
free(rcv.pkgdir); rcv.pkgdir = NULL;
|
|
||||||
rcv_set_distdir(&rcv, optarg);
|
rcv_set_distdir(&rcv, optarg);
|
||||||
break;
|
break;
|
||||||
case 'd':
|
case 'd':
|
||||||
@ -720,21 +692,16 @@ main(int argc, char **argv)
|
|||||||
argc -= optind;
|
argc -= optind;
|
||||||
argv += optind;
|
argv += optind;
|
||||||
|
|
||||||
rcv_find_conf(&rcv);
|
|
||||||
rcv_init(&rcv, prog);
|
rcv_init(&rcv, prog);
|
||||||
rcv.manual = false;
|
rcv.manual = false;
|
||||||
rcv_process_dir(&rcv, rcv.pkgdir, rcv_process_file);
|
rcv_process_dir(&rcv, rcv.pkgdir, rcv_process_file);
|
||||||
rcv.manual = true;
|
rcv.manual = true;
|
||||||
if (argc > 0) {
|
|
||||||
for (i = 0; i < argc; i++) {
|
for (i = 0; i < argc; i++) {
|
||||||
tmpl = argv[i] + (strlen(argv[i]) - strlen("template"));
|
tmpl = argv[i] + (strlen(argv[i]) - strlen("template"));
|
||||||
if ((strcmp("template", tmpl)) == 0) {
|
if ((strcmp("template", tmpl)) == 0) {
|
||||||
rcv_process_file(&rcv, argv[i],
|
rcv_process_file(&rcv, argv[i], rcv_check_version);
|
||||||
rcv_check_version);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
rcv_end(&rcv);
|
rcv_end(&rcv);
|
||||||
|
exit(EXIT_SUCCESS);
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user