Simplify xbps_end() and don't continue if xbps_init() did not succeed.

This commit is contained in:
Juan RP
2012-01-17 16:56:17 +01:00
parent f2b05d6438
commit d0e1477eeb
6 changed files with 75 additions and 86 deletions

View File

@@ -39,11 +39,9 @@
#include "../xbps-bin/defs.h"
static void __attribute__((noreturn))
usage(struct xbps_handle *xhp)
usage(void)
{
if (xhp != NULL)
xbps_end(xhp);
xbps_end();
fprintf(stderr,
"Usage: xbps-repo [options] [action] [arguments]\n"
"See xbps-repo(8) for more information.\n");
@@ -86,7 +84,7 @@ main(int argc, char **argv)
exit(EXIT_SUCCESS);
case '?':
default:
usage(NULL);
usage();
}
}
@@ -94,7 +92,7 @@ main(int argc, char **argv)
argv += optind;
if (argc < 1)
usage(NULL);
usage();
/*
* Initialize XBPS subsystems.
@@ -117,7 +115,7 @@ main(int argc, char **argv)
if (strcasecmp(argv[0], "list") == 0) {
/* Lists all repositories registered in pool. */
if (argc != 1)
usage(&xh);
usage();
rv = xbps_repository_pool_foreach(repo_list_uri_cb, NULL);
if (rv == ENOTSUP)
@@ -131,7 +129,7 @@ main(int argc, char **argv)
* Only list packages for the target repository.
*/
if (argc < 1 || argc > 2)
usage(&xh);
usage();
rv = xbps_repository_pool_foreach(repo_pkg_list_cb, argv[1]);
if (rv == ENOTSUP)
@@ -146,7 +144,7 @@ main(int argc, char **argv)
* by using shell style match patterns (fnmatch(3)).
*/
if (argc < 2)
usage(&xh);
usage();
rsd = malloc(sizeof(*rsd));
if (rsd == NULL) {
@@ -166,7 +164,7 @@ main(int argc, char **argv)
} else if (strcasecmp(argv[0], "show") == 0) {
/* Shows info about a binary package. */
if (argc != 2)
usage(&xh);
usage();
rv = show_pkg_info_from_repolist(argv[1], option);
if (rv == ENOENT) {
@@ -182,7 +180,7 @@ main(int argc, char **argv)
} else if (strcasecmp(argv[0], "show-deps") == 0) {
/* Shows the required run dependencies for a package. */
if (argc != 2)
usage(&xh);
usage();
rv = show_pkg_deps_from_repolist(argv[1]);
if (rv == ENOENT) {
@@ -198,7 +196,7 @@ main(int argc, char **argv)
} else if (strcasecmp(argv[0], "show-files") == 0) {
/* Shows the package files in a binary package */
if (argc != 2)
usage(&xh);
usage();
pkgd = xbps_repository_pool_dictionary_metadata_plist(argv[1],
XBPS_PKGFILES);
@@ -222,7 +220,7 @@ main(int argc, char **argv)
} else if (strcasecmp(argv[0], "find-files") == 0) {
/* Finds files by patterns, exact matches and components. */
if (argc < 2)
usage(&xh);
usage();
rv = repo_find_files_in_packages(argc, argv);
if (rv == ENOTSUP) {
@@ -232,7 +230,7 @@ main(int argc, char **argv)
} else if (strcasecmp(argv[0], "genindex") == 0) {
/* Generates a package repository index plist file. */
if (argc != 2)
usage(&xh);
usage();
rv = repo_genindex(argv[1]);
if (rv == 0)
@@ -241,7 +239,7 @@ main(int argc, char **argv)
} else if (strcasecmp(argv[0], "sync") == 0) {
/* Syncs the pkg index for all registered remote repos */
if (argc != 1)
usage(&xh);
usage();
rv = xbps_repository_pool_sync(&xh);
if (rv == ENOTSUP) {
@@ -249,10 +247,10 @@ main(int argc, char **argv)
"currently registered!\n");
}
} else {
usage(&xh);
usage();
}
out:
xbps_end(&xh);
xbps_end();
exit(rv ? EXIT_FAILURE : EXIT_SUCCESS);
}