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.
			
			
This commit is contained in:
		| @@ -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); | ||||
|   | ||||
| @@ -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); | ||||
|   | ||||
| @@ -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 | ||||
|   | ||||
| @@ -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); | ||||
|   | ||||
| @@ -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) { | ||||
|   | ||||
| @@ -50,7 +50,7 @@ pkgdb038(struct xbps_handle *xhp, const char *opkgdb_plist) | ||||
| 	 * 	- <metadir>/pkgdb-0.38.plist | ||||
| 	 * 	- <metadir>/.<pkgname>-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", | ||||
|   | ||||
| @@ -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; | ||||
| } | ||||
|   | ||||
| @@ -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); | ||||
|   | ||||
| @@ -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)); | ||||
|   | ||||
		Reference in New Issue
	
	Block a user