From 5a1ab26972bf6a62e83c2e4b66f5b591787671b0 Mon Sep 17 00:00:00 2001 From: Juan RP Date: Sat, 24 Dec 2011 16:09:30 +0100 Subject: [PATCH] Introduce xbps_regpkgdb_remove_pkgd, and use regpkgdb funcs to make xbps-uhelper work. --- bin/xbps-uhelper/main.c | 14 +++----------- include/xbps_api.h | 12 +++++++++++- lib/regpkgdb_dictionary.c | 13 +++++++++++++ 3 files changed, 27 insertions(+), 12 deletions(-) diff --git a/bin/xbps-uhelper/main.c b/bin/xbps-uhelper/main.c index d061bdf5..976e27ad 100644 --- a/bin/xbps-uhelper/main.c +++ b/bin/xbps-uhelper/main.c @@ -114,7 +114,7 @@ main(int argc, char **argv) struct xferstat xfer; prop_dictionary_t dict; const char *version, *rootdir = NULL, *confdir = NULL; - char *plist = NULL, *pkgname, *pkgver, *in_chroot_env, *hash; + char *pkgname, *pkgver, *in_chroot_env, *hash; bool debug = false, in_chroot = false; int i, c, rv = 0; @@ -168,13 +168,6 @@ main(int argc, char **argv) "initialize libxbps: %s.\n", strerror(rv)); exit(EXIT_FAILURE); } - - plist = xbps_xasprintf("%s/%s/%s", rootdir, - XBPS_META_PATH, XBPS_REGPKGDB); - if (plist == NULL) { - xbps_end(xhp); - exit(EXIT_FAILURE); - } } in_chroot_env = getenv("in_chroot"); @@ -229,7 +222,7 @@ main(int argc, char **argv) if (argc != 3) usage(xhp); - if (!xbps_remove_pkg_dict_from_plist_by_name(argv[1], plist)) { + if (!xbps_regpkgdb_remove_pkgd(argv[1])) { if (errno == ENOENT) fprintf(stderr, "%s=> ERROR: %s not registered " "in database.%s\n", MSG_WARN, argv[1], MSG_RESET); @@ -250,8 +243,7 @@ main(int argc, char **argv) if (argc != 2) usage(xhp); - dict = xbps_find_pkg_dict_from_plist_by_name(plist, - "packages", argv[1]); + dict = xbps_regpkgdb_get_pkgd(argv[1], false); if (dict == NULL) exit(EXIT_FAILURE); diff --git a/include/xbps_api.h b/include/xbps_api.h index 4f8686d3..db628dbc 100644 --- a/include/xbps_api.h +++ b/include/xbps_api.h @@ -56,7 +56,7 @@ */ #define XBPS_PKGINDEX_VERSION "1.3" -#define XBPS_API_VERSION "20111224" +#define XBPS_API_VERSION "20111224-1" #define XBPS_VERSION "0.12" /** @@ -821,6 +821,16 @@ int xbps_regpkgdb_foreach_reverse_pkg_cb( */ prop_dictionary_t xbps_regpkgdb_get_pkgd(const char *pkg, bool bypattern); +/** + * Removes a package dictionary from regpkgdb plist matching the key + * \a pkgname. + * + * @param[in] pkgname Package name to match in a dictionary. + * + * @return true on success, false otherwise. + */ +bool xbps_regpkgdb_remove_pkgd(const char *pkgname); + /** * Updates the regpkgdb plist with new contents from disk to the cached copy * in memory. diff --git a/lib/regpkgdb_dictionary.c b/lib/regpkgdb_dictionary.c index 1d4351d2..dc933fee 100644 --- a/lib/regpkgdb_dictionary.c +++ b/lib/regpkgdb_dictionary.c @@ -201,3 +201,16 @@ xbps_regpkgdb_get_pkgd(const char *pkg, bool bypattern) return prop_dictionary_copy(pkgd); } + +bool +xbps_regpkgdb_remove_pkgd(const char *pkgname) +{ + + struct xbps_handle *xhp = xbps_handle_get(); + + if (xbps_regpkgdb_dictionary_init(xhp) != 0) + return false; + + return xbps_remove_pkg_from_dict_by_name(xhp->regpkgdb, + "packages", pkgname); +}