Improved pkg best matching in rpool, and support for exact pkgver matches.
- xbps_repository_pool_find_pkg in best match case, now returns the newest package version available in rpool. - Added xbps_repository_pool_find_pkg_exact that returns a package by exact matching a pkgver. - Removed xbps_handle_alloc(), the user is free to use memory allocated from heap or stack. - Improved API documentation in preparation for 0.12. Bumped XBPS_API_VERSION again.
This commit is contained in:
+32
-36
@@ -62,7 +62,7 @@ cleanup(int signum)
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
struct xbps_handle *xhp;
|
||||
struct xbps_handle xh;
|
||||
struct xferstat xfer;
|
||||
struct list_pkgver_cb lpc;
|
||||
struct sigaction sa;
|
||||
@@ -147,27 +147,23 @@ main(int argc, char **argv)
|
||||
/*
|
||||
* Initialize libxbps.
|
||||
*/
|
||||
xhp = xbps_handle_alloc();
|
||||
if (xhp == NULL) {
|
||||
xbps_error_printf("xbps-bin: failed to allocate resources.\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
xhp->debug = debug;
|
||||
xhp->state_cb = state_cb;
|
||||
xhp->fetch_cb = fetch_file_progress_cb;
|
||||
xhp->fetch_cb_data = &xfer;
|
||||
xhp->rootdir = rootdir;
|
||||
xhp->cachedir = cachedir;
|
||||
xhp->conffile = conffile;
|
||||
xhp->flags = flags;
|
||||
xhp->install_reason_manual = install_manual;
|
||||
xhp->install_reason_auto = install_auto;
|
||||
memset(&xh, 0, sizeof(xh));
|
||||
xh.debug = debug;
|
||||
xh.state_cb = state_cb;
|
||||
xh.fetch_cb = fetch_file_progress_cb;
|
||||
xh.fetch_cb_data = &xfer;
|
||||
xh.rootdir = rootdir;
|
||||
xh.cachedir = cachedir;
|
||||
xh.conffile = conffile;
|
||||
xh.flags = flags;
|
||||
xh.install_reason_manual = install_manual;
|
||||
xh.install_reason_auto = install_auto;
|
||||
if (flags & XBPS_FLAG_VERBOSE)
|
||||
xhp->unpack_cb = unpack_progress_cb_verbose;
|
||||
xh.unpack_cb = unpack_progress_cb_verbose;
|
||||
else
|
||||
xhp->unpack_cb = unpack_progress_cb;
|
||||
xh.unpack_cb = unpack_progress_cb;
|
||||
|
||||
if ((rv = xbps_init(xhp)) != 0) {
|
||||
if ((rv = xbps_init(&xh)) != 0) {
|
||||
xbps_error_printf("xbps-bin: couldn't initialize library: %s\n",
|
||||
strerror(rv));
|
||||
exit(EXIT_FAILURE);
|
||||
@@ -184,7 +180,7 @@ main(int argc, char **argv)
|
||||
if (strcasecmp(argv[0], "list") == 0) {
|
||||
/* Lists packages currently registered in database. */
|
||||
if (argc < 1 || argc > 2)
|
||||
usage(xhp);
|
||||
usage(&xh);
|
||||
|
||||
lpc.check_state = true;
|
||||
lpc.state = 0;
|
||||
@@ -220,7 +216,7 @@ main(int argc, char **argv)
|
||||
} else if (strcasecmp(argv[0], "install") == 0) {
|
||||
/* Installs a binary package and required deps. */
|
||||
if (argc < 2)
|
||||
usage(xhp);
|
||||
usage(&xh);
|
||||
|
||||
for (i = 1; i < argc; i++)
|
||||
if ((rv = install_new_pkg(argv[i], reinstall)) != 0)
|
||||
@@ -231,7 +227,7 @@ main(int argc, char **argv)
|
||||
} else if (strcasecmp(argv[0], "update") == 0) {
|
||||
/* Update an installed package. */
|
||||
if (argc < 2)
|
||||
usage(xhp);
|
||||
usage(&xh);
|
||||
|
||||
for (i = 1; i < argc; i++)
|
||||
if ((rv = update_pkg(argv[i])) != 0)
|
||||
@@ -242,7 +238,7 @@ main(int argc, char **argv)
|
||||
} else if (strcasecmp(argv[0], "remove") == 0) {
|
||||
/* Removes a package. */
|
||||
if (argc < 2)
|
||||
usage(xhp);
|
||||
usage(&xh);
|
||||
|
||||
for (i = 1; i < argc; i++) {
|
||||
rv = remove_pkg(argv[i], recursive_rm);
|
||||
@@ -262,7 +258,7 @@ main(int argc, char **argv)
|
||||
} else if (strcasecmp(argv[0], "show") == 0) {
|
||||
/* Shows info about an installed binary package. */
|
||||
if (argc != 2)
|
||||
usage(xhp);
|
||||
usage(&xh);
|
||||
|
||||
rv = show_pkg_info_from_metadir(argv[1], option);
|
||||
if (rv != 0) {
|
||||
@@ -273,7 +269,7 @@ main(int argc, char **argv)
|
||||
} else if (strcasecmp(argv[0], "show-files") == 0) {
|
||||
/* Shows files installed by a binary package. */
|
||||
if (argc != 2)
|
||||
usage(xhp);
|
||||
usage(&xh);
|
||||
|
||||
rv = show_pkg_files_from_metadir(argv[1]);
|
||||
if (rv != 0) {
|
||||
@@ -284,7 +280,7 @@ main(int argc, char **argv)
|
||||
} else if (strcasecmp(argv[0], "check") == 0) {
|
||||
/* Checks the integrity of an installed package. */
|
||||
if (argc != 2)
|
||||
usage(xhp);
|
||||
usage(&xh);
|
||||
|
||||
if (strcasecmp(argv[1], "all") == 0)
|
||||
rv = check_pkg_integrity_all();
|
||||
@@ -296,7 +292,7 @@ main(int argc, char **argv)
|
||||
* To update all packages currently installed.
|
||||
*/
|
||||
if (argc != 1)
|
||||
usage(xhp);
|
||||
usage(&xh);
|
||||
|
||||
rv = autoupdate_pkgs(yes, show_download_pkglist_url);
|
||||
|
||||
@@ -306,7 +302,7 @@ main(int argc, char **argv)
|
||||
* orphans.
|
||||
*/
|
||||
if (argc != 1)
|
||||
usage(xhp);
|
||||
usage(&xh);
|
||||
|
||||
rv = show_orphans();
|
||||
|
||||
@@ -317,7 +313,7 @@ main(int argc, char **argv)
|
||||
* on it currently.
|
||||
*/
|
||||
if (argc != 1)
|
||||
usage(xhp);
|
||||
usage(&xh);
|
||||
|
||||
rv = autoremove_pkgs(yes);
|
||||
|
||||
@@ -326,7 +322,7 @@ main(int argc, char **argv)
|
||||
* Reconfigure a package.
|
||||
*/
|
||||
if (argc != 2)
|
||||
usage(xhp);
|
||||
usage(&xh);
|
||||
|
||||
if (strcasecmp(argv[1], "all") == 0)
|
||||
rv = xbps_configure_packages(true);
|
||||
@@ -338,7 +334,7 @@ main(int argc, char **argv)
|
||||
* Show dependencies for a package.
|
||||
*/
|
||||
if (argc != 2)
|
||||
usage(xhp);
|
||||
usage(&xh);
|
||||
|
||||
rv = show_pkg_deps(argv[1]);
|
||||
|
||||
@@ -348,7 +344,7 @@ main(int argc, char **argv)
|
||||
* dependencies.
|
||||
*/
|
||||
if (argc != 1)
|
||||
usage(xhp);
|
||||
usage(&xh);
|
||||
|
||||
rv = xbps_regpkgdb_foreach_pkg_cb(list_manual_pkgs, NULL);
|
||||
|
||||
@@ -357,7 +353,7 @@ main(int argc, char **argv)
|
||||
* Show reverse dependencies for a package.
|
||||
*/
|
||||
if (argc != 2)
|
||||
usage(xhp);
|
||||
usage(&xh);
|
||||
|
||||
rv = show_pkg_reverse_deps(argv[1]);
|
||||
|
||||
@@ -367,15 +363,15 @@ main(int argc, char **argv)
|
||||
* packages.
|
||||
*/
|
||||
if (argc < 2)
|
||||
usage(xhp);
|
||||
usage(&xh);
|
||||
|
||||
rv = find_files_in_packages(argc, argv);
|
||||
|
||||
} else {
|
||||
usage(xhp);
|
||||
usage(&xh);
|
||||
}
|
||||
|
||||
out:
|
||||
xbps_end(xhp);
|
||||
xbps_end(&xh);
|
||||
exit(rv);
|
||||
}
|
||||
|
||||
@@ -443,7 +443,7 @@ int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
prop_dictionary_t plistd, confd = NULL;
|
||||
struct xbps_handle *xhp;
|
||||
struct xbps_handle xh;
|
||||
FILE *f = NULL;
|
||||
char *outfile = NULL;
|
||||
const char *conf_file = NULL, *rootdir = NULL;
|
||||
@@ -485,11 +485,9 @@ main(int argc, char **argv)
|
||||
usage();
|
||||
|
||||
/* Initialize libxbps */
|
||||
xhp = xbps_handle_alloc();
|
||||
if (xhp == NULL)
|
||||
die("failed to allocate resources");
|
||||
xhp->rootdir = rootdir;
|
||||
if ((rv = xbps_init(xhp)) != 0)
|
||||
memset(&xh, 0, sizeof(xh));
|
||||
xh.rootdir = rootdir;
|
||||
if ((rv = xbps_init(&xh)) != 0)
|
||||
die("failed to initialize libxbps: %s", strerror(rv));
|
||||
|
||||
/*
|
||||
|
||||
+22
-26
@@ -53,7 +53,7 @@ usage(struct xbps_handle *xhp)
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
struct xbps_handle *xhp;
|
||||
struct xbps_handle xh;
|
||||
struct xferstat xfer;
|
||||
struct repo_search_data *rsd = NULL;
|
||||
prop_dictionary_t pkgd;
|
||||
@@ -99,20 +99,16 @@ main(int argc, char **argv)
|
||||
/*
|
||||
* Initialize XBPS subsystems.
|
||||
*/
|
||||
xhp = xbps_handle_alloc();
|
||||
if (xhp == NULL) {
|
||||
xbps_error_printf("xbps-repo: failed to allocate resources.\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
xhp->debug = debug;
|
||||
xhp->state_cb = state_cb;
|
||||
xhp->fetch_cb = fetch_file_progress_cb;
|
||||
xhp->fetch_cb_data = &xfer;
|
||||
xhp->rootdir = rootdir;
|
||||
xhp->cachedir = cachedir;
|
||||
xhp->conffile = conffile;
|
||||
memset(&xh, 0, sizeof(xh));
|
||||
xh.debug = debug;
|
||||
xh.state_cb = state_cb;
|
||||
xh.fetch_cb = fetch_file_progress_cb;
|
||||
xh.fetch_cb_data = &xfer;
|
||||
xh.rootdir = rootdir;
|
||||
xh.cachedir = cachedir;
|
||||
xh.conffile = conffile;
|
||||
|
||||
if ((rv = xbps_init(xhp)) != 0) {
|
||||
if ((rv = xbps_init(&xh)) != 0) {
|
||||
xbps_error_printf("xbps-repo: couldn't initialize library: %s\n",
|
||||
strerror(rv));
|
||||
exit(EXIT_FAILURE);
|
||||
@@ -121,7 +117,7 @@ main(int argc, char **argv)
|
||||
if (strcasecmp(argv[0], "list") == 0) {
|
||||
/* Lists all repositories registered in pool. */
|
||||
if (argc != 1)
|
||||
usage(xhp);
|
||||
usage(&xh);
|
||||
|
||||
rv = xbps_repository_pool_foreach(repo_list_uri_cb, NULL);
|
||||
if (rv == ENOTSUP)
|
||||
@@ -135,7 +131,7 @@ main(int argc, char **argv)
|
||||
* Only list packages for the target repository.
|
||||
*/
|
||||
if (argc < 1 || argc > 2)
|
||||
usage(xhp);
|
||||
usage(&xh);
|
||||
|
||||
rv = xbps_repository_pool_foreach(repo_pkg_list_cb, argv[1]);
|
||||
if (rv == ENOTSUP)
|
||||
@@ -150,7 +146,7 @@ main(int argc, char **argv)
|
||||
* by using shell style match patterns (fnmatch(3)).
|
||||
*/
|
||||
if (argc < 2)
|
||||
usage(xhp);
|
||||
usage(&xh);
|
||||
|
||||
rsd = malloc(sizeof(*rsd));
|
||||
if (rsd == NULL) {
|
||||
@@ -170,7 +166,7 @@ main(int argc, char **argv)
|
||||
} else if (strcasecmp(argv[0], "show") == 0) {
|
||||
/* Shows info about a binary package. */
|
||||
if (argc != 2)
|
||||
usage(xhp);
|
||||
usage(&xh);
|
||||
|
||||
rv = show_pkg_info_from_repolist(argv[1], option);
|
||||
if (rv == ENOENT) {
|
||||
@@ -186,7 +182,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(xhp);
|
||||
usage(&xh);
|
||||
|
||||
rv = show_pkg_deps_from_repolist(argv[1]);
|
||||
if (rv == ENOENT) {
|
||||
@@ -202,7 +198,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(xhp);
|
||||
usage(&xh);
|
||||
|
||||
pkgd = xbps_repository_pool_dictionary_metadata_plist(argv[1],
|
||||
XBPS_PKGFILES);
|
||||
@@ -226,7 +222,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(xhp);
|
||||
usage(&xh);
|
||||
|
||||
rv = repo_find_files_in_packages(argc, argv);
|
||||
if (rv == ENOTSUP) {
|
||||
@@ -236,7 +232,7 @@ main(int argc, char **argv)
|
||||
} else if (strcasecmp(argv[0], "genindex") == 0) {
|
||||
/* Generates a package repository index plist file. */
|
||||
if (argc != 2)
|
||||
usage(xhp);
|
||||
usage(&xh);
|
||||
|
||||
rv = repo_genindex(argv[1]);
|
||||
if (rv == 0)
|
||||
@@ -245,18 +241,18 @@ 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(xhp);
|
||||
usage(&xh);
|
||||
|
||||
rv = xbps_repository_pool_sync(xhp);
|
||||
rv = xbps_repository_pool_sync(&xh);
|
||||
if (rv == ENOTSUP) {
|
||||
xbps_error_printf("xbps-repo: no repositories "
|
||||
"currently registered!\n");
|
||||
}
|
||||
} else {
|
||||
usage(xhp);
|
||||
usage(&xh);
|
||||
}
|
||||
|
||||
out:
|
||||
xbps_end(xhp);
|
||||
xbps_end(&xh);
|
||||
exit(rv ? EXIT_FAILURE : EXIT_SUCCESS);
|
||||
}
|
||||
|
||||
+24
-29
@@ -1,5 +1,5 @@
|
||||
/*-
|
||||
* Copyright (c) 2008-2011 Juan Romero Pardines.
|
||||
* Copyright (c) 2008-2012 Juan Romero Pardines.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -110,7 +110,7 @@ usage(struct xbps_handle *xhp)
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
struct xbps_handle *xhp = NULL;
|
||||
struct xbps_handle xh;
|
||||
struct xferstat xfer;
|
||||
prop_dictionary_t dict, pkgd;
|
||||
const char *pkgn, *version, *rootdir = NULL, *confdir = NULL;
|
||||
@@ -152,18 +152,13 @@ main(int argc, char **argv)
|
||||
/*
|
||||
* Initialize libxbps.
|
||||
*/
|
||||
xhp = xbps_handle_alloc();
|
||||
if (xhp == NULL) {
|
||||
xbps_error_printf("xbps-uhelper: failed to allocate resources\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
xhp->debug = debug;
|
||||
xhp->fetch_cb = fetch_file_progress_cb;
|
||||
xhp->fetch_cb_data = &xfer;
|
||||
xhp->rootdir = rootdir;
|
||||
xhp->conffile = confdir;
|
||||
|
||||
if ((rv = xbps_init(xhp)) != 0) {
|
||||
memset(&xh, 0, sizeof(xh));
|
||||
xh.debug = debug;
|
||||
xh.fetch_cb = fetch_file_progress_cb;
|
||||
xh.fetch_cb_data = &xfer;
|
||||
xh.rootdir = rootdir;
|
||||
xh.conffile = confdir;
|
||||
if ((rv = xbps_init(&xh)) != 0) {
|
||||
xbps_error_printf("xbps-uhelper: failed to "
|
||||
"initialize libxbps: %s.\n", strerror(rv));
|
||||
exit(EXIT_FAILURE);
|
||||
@@ -177,7 +172,7 @@ main(int argc, char **argv)
|
||||
if (strcasecmp(argv[0], "register") == 0) {
|
||||
/* Registers a package into the database */
|
||||
if (argc != 4)
|
||||
usage(xhp);
|
||||
usage(&xh);
|
||||
|
||||
dict = prop_dictionary_create();
|
||||
if (dict == NULL) {
|
||||
@@ -230,7 +225,7 @@ main(int argc, char **argv)
|
||||
} else if (strcasecmp(argv[0], "unregister") == 0) {
|
||||
/* Unregisters a package from the database */
|
||||
if (argc != 3)
|
||||
usage(xhp);
|
||||
usage(&xh);
|
||||
|
||||
rv = xbps_unregister_pkg(argv[1], argv[2], true);
|
||||
if (rv == ENOENT) {
|
||||
@@ -249,7 +244,7 @@ main(int argc, char **argv)
|
||||
} else if (strcasecmp(argv[0], "version") == 0) {
|
||||
/* Prints version of an installed package */
|
||||
if (argc != 2)
|
||||
usage(xhp);
|
||||
usage(&xh);
|
||||
|
||||
dict = xbps_regpkgdb_get_pkgd(argv[1], false);
|
||||
if (dict == NULL) {
|
||||
@@ -263,7 +258,7 @@ main(int argc, char **argv)
|
||||
} else if (strcasecmp(argv[0], "sanitize-plist") == 0) {
|
||||
/* Sanitize a plist file (properly indent the file) */
|
||||
if (argc != 2)
|
||||
usage(xhp);
|
||||
usage(NULL);
|
||||
|
||||
dict = prop_dictionary_internalize_from_zfile(argv[1]);
|
||||
if (dict == NULL) {
|
||||
@@ -277,7 +272,7 @@ main(int argc, char **argv)
|
||||
} else if (strcasecmp(argv[0], "getpkgversion") == 0) {
|
||||
/* Returns the version of a pkg string */
|
||||
if (argc != 2)
|
||||
usage(xhp);
|
||||
usage(NULL);
|
||||
|
||||
version = xbps_pkg_version(argv[1]);
|
||||
if (version == NULL) {
|
||||
@@ -290,7 +285,7 @@ main(int argc, char **argv)
|
||||
} else if (strcasecmp(argv[0], "getpkgname") == 0) {
|
||||
/* Returns the name of a pkg string */
|
||||
if (argc != 2)
|
||||
usage(xhp);
|
||||
usage(NULL);
|
||||
|
||||
pkgname = xbps_pkg_name(argv[1]);
|
||||
if (pkgname == NULL) {
|
||||
@@ -304,7 +299,7 @@ main(int argc, char **argv)
|
||||
} else if (strcasecmp(argv[0], "getpkgrevision") == 0) {
|
||||
/* Returns the revision of a pkg string */
|
||||
if (argc != 2)
|
||||
usage(xhp);
|
||||
usage(NULL);
|
||||
|
||||
version = xbps_pkg_revision(argv[1]);
|
||||
if (version == NULL)
|
||||
@@ -315,7 +310,7 @@ main(int argc, char **argv)
|
||||
} else if (strcasecmp(argv[0], "getpkgdepname") == 0) {
|
||||
/* Returns the pkgname of a dependency */
|
||||
if (argc != 2)
|
||||
usage(xhp);
|
||||
usage(NULL);
|
||||
|
||||
pkgname = xbps_pkgpattern_name(argv[1]);
|
||||
if (pkgname == NULL)
|
||||
@@ -326,7 +321,7 @@ main(int argc, char **argv)
|
||||
} else if (strcasecmp(argv[0], "getpkgdepversion") == 0) {
|
||||
/* returns the version of a package pattern dependency */
|
||||
if (argc != 2)
|
||||
usage(xhp);
|
||||
usage(NULL);
|
||||
|
||||
version = xbps_pkgpattern_version(argv[1]);
|
||||
if (version == NULL)
|
||||
@@ -337,21 +332,21 @@ main(int argc, char **argv)
|
||||
} else if (strcasecmp(argv[0], "pkgmatch") == 0) {
|
||||
/* Matches a pkg with a pattern */
|
||||
if (argc != 3)
|
||||
usage(xhp);
|
||||
usage(NULL);
|
||||
|
||||
exit(xbps_pkgpattern_match(argv[1], argv[2]));
|
||||
|
||||
} else if (strcasecmp(argv[0], "cmpver") == 0) {
|
||||
/* Compare two version strings, installed vs required */
|
||||
if (argc != 3)
|
||||
usage(xhp);
|
||||
usage(NULL);
|
||||
|
||||
exit(xbps_cmpver(argv[1], argv[2]));
|
||||
|
||||
} else if (strcasecmp(argv[0], "digest") == 0) {
|
||||
/* Prints SHA256 hashes for specified files */
|
||||
if (argc < 2)
|
||||
usage(xhp);
|
||||
usage(NULL);
|
||||
|
||||
for (i = 1; i < argc; i++) {
|
||||
hash = xbps_file_hash(argv[i]);
|
||||
@@ -368,7 +363,7 @@ main(int argc, char **argv)
|
||||
} else if (strcasecmp(argv[0], "fetch") == 0) {
|
||||
/* Fetch a file from specified URL */
|
||||
if (argc != 2)
|
||||
usage(xhp);
|
||||
usage(&xh);
|
||||
|
||||
for (i = 1; i < argc; i++) {
|
||||
rv = xbps_fetch_file(argv[i], ".", false, "v");
|
||||
@@ -383,10 +378,10 @@ main(int argc, char **argv)
|
||||
}
|
||||
|
||||
} else {
|
||||
usage(xhp);
|
||||
usage(NULL);
|
||||
}
|
||||
|
||||
out:
|
||||
xbps_end(xhp);
|
||||
xbps_end(&xh);
|
||||
exit(rv ? EXIT_FAILURE : EXIT_SUCCESS);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user