From 769a997afbaba932d7fb65c93c465b1457b0e0a1 Mon Sep 17 00:00:00 2001 From: Juan RP Date: Thu, 28 May 2015 10:15:05 +0200 Subject: [PATCH] Introduce xbps_plist_{array,dictionary}_from_file(). Those are a wrapper around xbps_{array,dictionary}_internalize_from_zfile() that prints a debugging msg when the plist file cannot be internalized. Update xbps to use these wrappers. --- bin/xbps-dgraph/main.c | 2 +- bin/xbps-pkgdb/check.c | 2 +- include/xbps.h.in | 24 +++++++++++++++++++++++- lib/package_remove.c | 2 +- lib/pkgdb.c | 2 +- lib/pkgdb_conversion.c | 4 ++-- lib/proplib_wrapper.c | 29 ++++++++++++++++++++++++++++- lib/repo.c | 2 +- lib/verifysig.c | 2 +- 9 files changed, 59 insertions(+), 10 deletions(-) diff --git a/bin/xbps-dgraph/main.c b/bin/xbps-dgraph/main.c index eeb80fb5..633e4515 100644 --- a/bin/xbps-dgraph/main.c +++ b/bin/xbps-dgraph/main.c @@ -598,7 +598,7 @@ main(int argc, char **argv) if (conf_file == NULL) conf_file = _DGRAPH_CFFILE; - confd = xbps_dictionary_internalize_from_zfile(conf_file); + confd = xbps_plist_dictionary_from_file(&xh, conf_file); if (confd == NULL) { if (errno != ENOENT) die("cannot read conf file `%s'", conf_file); diff --git a/bin/xbps-pkgdb/check.c b/bin/xbps-pkgdb/check.c index 8477afbe..ed393398 100644 --- a/bin/xbps-pkgdb/check.c +++ b/bin/xbps-pkgdb/check.c @@ -95,7 +95,7 @@ check_pkg_integrity(struct xbps_handle *xhp, buf = xbps_xasprintf("%s/.%s-files.plist", xhp->metadir, pkgname); assert(buf); - filesd = xbps_dictionary_internalize_from_zfile(buf); + filesd = xbps_plist_dictionary_from_file(xhp, buf); if (filesd == NULL) { fprintf(stderr, "%s: cannot read %s, ignoring...\n", pkgname, buf); diff --git a/include/xbps.h.in b/include/xbps.h.in index d99179c7..d95a64bf 100644 --- a/include/xbps.h.in +++ b/include/xbps.h.in @@ -48,7 +48,7 @@ * * This header documents the full API for the XBPS Library. */ -#define XBPS_API_VERSION "20150413" +#define XBPS_API_VERSION "20150528" #ifndef XBPS_VERSION #define XBPS_VERSION "UNSET" @@ -1978,6 +1978,28 @@ char *xbps_sanitize_path(const char *src); char *xbps_symlink_target(struct xbps_handle *xhp, const char *path, const char *target); +/** + * Internalizes a plist file declared in \f and returns a proplib array. + * + * @param[in] xhp The pointer to an xbps_handle struct. + * @param[in] fname The file path. + * + * @return The internalized proplib array, NULL otherwise. + */ +xbps_array_t +xbps_plist_array_from_file(struct xbps_handle *xhp, const char *fname); + +/** + * Internalizes a plist file declared in \f and returns a proplib dictionary. + * + * @param[in] xhp The pointer to an xbps_handle struct. + * @param[in] fname The file path. + * + * @return The internalized proplib array, NULL otherwise. + */ +xbps_dictionary_t +xbps_plist_dictionary_from_file(struct xbps_handle *xhp, const char *fname); + /*@}*/ #ifdef __cplusplus diff --git a/lib/package_remove.c b/lib/package_remove.c index fff1c9d3..add657c1 100644 --- a/lib/package_remove.c +++ b/lib/package_remove.c @@ -293,7 +293,7 @@ xbps_remove_pkg(struct xbps_handle *xhp, const char *pkgver, bool update) /* internalize pkg files dictionary from metadir */ snprintf(metafile, sizeof(metafile), "%s/.%s-files.plist", xhp->metadir, pkgname); - pkgfilesd = xbps_dictionary_internalize_from_zfile(metafile); + pkgfilesd = xbps_plist_dictionary_from_file(xhp, metafile); if (pkgfilesd == NULL) xbps_dbg_printf(xhp, "WARNING: metaplist for %s " "doesn't exist!\n", pkgver); diff --git a/lib/pkgdb.c b/lib/pkgdb.c index d39664f6..af75fd6e 100644 --- a/lib/pkgdb.c +++ b/lib/pkgdb.c @@ -423,7 +423,7 @@ xbps_pkgdb_get_pkg_files(struct xbps_handle *xhp, const char *pkg) plist = xbps_xasprintf("%s/.%s-files.plist", xhp->metadir, pkgname); free(pkgname); - pkgfilesd = xbps_dictionary_internalize_from_zfile(plist); + pkgfilesd = xbps_plist_dictionary_from_file(xhp, plist); free(plist); if (pkgfilesd == NULL) { diff --git a/lib/pkgdb_conversion.c b/lib/pkgdb_conversion.c index 265bace8..c698d3db 100644 --- a/lib/pkgdb_conversion.c +++ b/lib/pkgdb_conversion.c @@ -50,7 +50,7 @@ pkgdb038(struct xbps_handle *xhp, const char *opkgdb_plist) * - /pkgdb-0.38.plist * - /.-files.plist */ - opkgdb = xbps_dictionary_internalize_from_zfile(opkgdb_plist); + opkgdb = xbps_plist_dictionary_from_file(xhp, opkgdb_plist); if (opkgdb == NULL) return EINVAL; @@ -93,7 +93,7 @@ pkgdb038(struct xbps_handle *xhp, const char *opkgdb_plist) * Copy pkg metadata objs to the new pkgdb. */ pkgmeta = xbps_xasprintf("%s/.%s.plist", xhp->metadir, pkgname); - pkgmetad = xbps_dictionary_internalize_from_zfile(pkgmeta); + pkgmetad = xbps_plist_dictionary_from_file(xhp, pkgmeta); if (pkgmetad == NULL) { rv = EINVAL; xbps_dbg_printf(xhp, "%s: cannot open %s: %s\n", diff --git a/lib/proplib_wrapper.c b/lib/proplib_wrapper.c index 3a8a8966..8aab0d7e 100644 --- a/lib/proplib_wrapper.c +++ b/lib/proplib_wrapper.c @@ -1,5 +1,5 @@ /*- - * Copyright (c) 2013 Juan Romero Pardines. + * Copyright (c) 2013-2015 Juan Romero Pardines. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -931,3 +931,30 @@ xbps_string_equals_cstring(xbps_string_t s, const char *ss) { return prop_string_equals_cstring(s, ss); } + +/* xbps specific helpers */ +xbps_array_t +xbps_plist_array_from_file(struct xbps_handle *xhp, const char *f) +{ + xbps_array_t a; + + a = xbps_array_internalize_from_zfile(f); + if (xbps_object_type(a) != XBPS_TYPE_ARRAY) { + xbps_dbg_printf(xhp, + "xbps: failed to internalize array from %s\n", f); + } + return a; +} + +xbps_dictionary_t +xbps_plist_dictionary_from_file(struct xbps_handle *xhp, const char *f) +{ + xbps_dictionary_t d; + + d = xbps_dictionary_internalize_from_zfile(f); + if (xbps_object_type(d) != XBPS_TYPE_DICTIONARY) { + xbps_dbg_printf(xhp, + "xbps: failed to internalize dict from %s\n", f); + } + return d; +} diff --git a/lib/repo.c b/lib/repo.c index a128e232..09ec2786 100644 --- a/lib/repo.c +++ b/lib/repo.c @@ -540,7 +540,7 @@ xbps_repo_key_import(struct xbps_repo *repo) * Check if the public key is alredy stored. */ rkeyfile = xbps_xasprintf("%s/keys/%s.plist", repo->xhp->metadir, hexfp); - repokeyd = xbps_dictionary_internalize_from_zfile(rkeyfile); + repokeyd = xbps_plist_dictionary_from_file(repo->xhp, rkeyfile); if (xbps_object_type(repokeyd) == XBPS_TYPE_DICTIONARY) { xbps_dbg_printf(repo->xhp, "[repo] `%s' public key already stored.\n", repo->uri); diff --git a/lib/verifysig.c b/lib/verifysig.c index 18699925..2fc56529 100644 --- a/lib/verifysig.c +++ b/lib/verifysig.c @@ -102,7 +102,7 @@ xbps_verify_file_signature(struct xbps_repo *repo, const char *fname) * Prepare repository RSA public key to verify fname signature. */ rkeyfile = xbps_xasprintf("%s/keys/%s.plist", repo->xhp->metadir, hexfp); - repokeyd = xbps_dictionary_internalize_from_zfile(rkeyfile); + repokeyd = xbps_plist_dictionary_from_file(repo->xhp, rkeyfile); if (xbps_object_type(repokeyd) != XBPS_TYPE_DICTIONARY) { xbps_dbg_printf(repo->xhp, "cannot read rkey data at %s: %s\n", rkeyfile, strerror(errno));