regpkgdb rototill: renamed to pkgdb, improve the public API.
This commit is contained in:
		| @@ -28,7 +28,6 @@ | ||||
| #include <stdlib.h> | ||||
| #include <string.h> | ||||
| #include <errno.h> | ||||
| #include <assert.h> | ||||
| #include <unistd.h> | ||||
| #include <sys/param.h> | ||||
|  | ||||
| @@ -38,6 +37,7 @@ | ||||
| struct checkpkg { | ||||
| 	size_t npkgs; | ||||
| 	size_t nbrokenpkgs; | ||||
| 	bool flush; | ||||
| }; | ||||
|  | ||||
| static int | ||||
| @@ -45,15 +45,17 @@ cb_pkg_integrity(prop_object_t obj, void *arg, bool *done) | ||||
| { | ||||
| 	struct checkpkg *cpkg = arg; | ||||
| 	const char *pkgname, *version; | ||||
| 	bool flush = false; | ||||
|  | ||||
| 	(void)done; | ||||
|  | ||||
| 	prop_dictionary_get_cstring_nocopy(obj, "pkgname", &pkgname); | ||||
| 	prop_dictionary_get_cstring_nocopy(obj, "version", &version); | ||||
| 	printf("Checking %s-%s ...\n", pkgname, version); | ||||
| 	if (check_pkg_integrity(obj, pkgname) != 0) | ||||
| 	if (check_pkg_integrity(obj, pkgname, false, &flush) != 0) | ||||
| 		cpkg->nbrokenpkgs++; | ||||
|  | ||||
| 	cpkg->flush = flush; | ||||
| 	cpkg->npkgs++; | ||||
| 	return 0; | ||||
| } | ||||
| @@ -61,26 +63,33 @@ cb_pkg_integrity(prop_object_t obj, void *arg, bool *done) | ||||
| int | ||||
| check_pkg_integrity_all(void) | ||||
| { | ||||
| 	struct checkpkg *cpkg; | ||||
|  | ||||
| 	cpkg = calloc(1, sizeof(*cpkg)); | ||||
| 	if (cpkg == NULL) | ||||
| 		return ENOMEM; | ||||
|  | ||||
| 	(void)xbps_regpkgdb_foreach_pkg_cb(cb_pkg_integrity, cpkg); | ||||
| 	printf("%zu package%s processed: %zu broken.\n", cpkg->npkgs, | ||||
| 	    cpkg->npkgs == 1 ? "" : "s", cpkg->nbrokenpkgs); | ||||
| 	free(cpkg); | ||||
| 	struct xbps_handle *xhp = xbps_handle_get(); | ||||
| 	struct checkpkg cpkg; | ||||
| 	int rv; | ||||
|  | ||||
| 	memset(&cpkg, 0, sizeof(cpkg)); | ||||
| 	(void)xbps_pkgdb_foreach_pkg_cb(cb_pkg_integrity, &cpkg); | ||||
| 	if (cpkg.flush) { | ||||
| 		if ((rv = xbps_pkgdb_update(xhp, true)) != 0) { | ||||
| 			xbps_error_printf("failed to write pkgdb: %s\n", | ||||
| 			    strerror(rv)); | ||||
| 			return rv; | ||||
| 		} | ||||
| 	} | ||||
| 	printf("%zu package%s processed: %zu broken.\n", cpkg.npkgs, | ||||
| 	    cpkg.npkgs == 1 ? "" : "s", cpkg.nbrokenpkgs); | ||||
| 	return 0; | ||||
| } | ||||
|  | ||||
| int | ||||
| check_pkg_integrity(prop_dictionary_t pkgd, const char *pkgname) | ||||
| check_pkg_integrity(prop_dictionary_t pkgd, | ||||
| 		    const char *pkgname, | ||||
| 		    bool flush, | ||||
| 		    bool *setflush) | ||||
| { | ||||
| 	prop_dictionary_t opkgd, propsd, filesd; | ||||
| 	int rv = 0; | ||||
| 	bool broken = false; | ||||
| 	bool pkgdb_update = false, broken = false; | ||||
|  | ||||
| 	propsd = filesd = opkgd = NULL; | ||||
|  | ||||
| @@ -101,7 +110,7 @@ check_pkg_integrity(prop_dictionary_t pkgd, const char *pkgname) | ||||
| 	 * Check for props.plist metadata file. | ||||
| 	 */ | ||||
| 	propsd = xbps_dictionary_from_metadata_plist(pkgname, XBPS_PKGPROPS); | ||||
| 	if (prop_object_type(propsd) != PROP_TYPE_DICTIONARY) { | ||||
| 	if (propsd == NULL) { | ||||
| 		xbps_error_printf("%s: unexistent %s or invalid metadata " | ||||
| 		    "file.\n", pkgname, XBPS_PKGPROPS); | ||||
| 		broken = true; | ||||
| @@ -116,7 +125,7 @@ check_pkg_integrity(prop_dictionary_t pkgd, const char *pkgname) | ||||
| 	 * Check for files.plist metadata file. | ||||
| 	 */ | ||||
| 	filesd = xbps_dictionary_from_metadata_plist(pkgname, XBPS_PKGFILES); | ||||
| 	if (prop_object_type(filesd) != PROP_TYPE_DICTIONARY) { | ||||
| 	if (filesd == NULL) { | ||||
| 		xbps_error_printf("%s: unexistent %s or invalid metadata " | ||||
| 		    "file.\n", pkgname, XBPS_PKGFILES); | ||||
| 		broken = true; | ||||
| @@ -128,9 +137,9 @@ check_pkg_integrity(prop_dictionary_t pkgd, const char *pkgname) | ||||
| 		goto out; | ||||
| 	} | ||||
|  | ||||
| #define RUN_PKG_CHECK(name, arg)				\ | ||||
| #define RUN_PKG_CHECK(name, arg, arg2)				\ | ||||
| do {								\ | ||||
| 	rv = check_pkg_##name(pkgname, arg);			\ | ||||
| 	rv = check_pkg_##name(pkgname, arg, arg2);		\ | ||||
| 	if (rv)							\ | ||||
| 		broken = true;					\ | ||||
| 	else if (rv == -1) {					\ | ||||
| @@ -141,11 +150,20 @@ do {								\ | ||||
| } while (0) | ||||
|  | ||||
| 	/* Execute pkg checks */ | ||||
| 	RUN_PKG_CHECK(requiredby, pkgd ? pkgd : opkgd); | ||||
| 	RUN_PKG_CHECK(autoinstall, pkgd ? pkgd : opkgd); | ||||
| 	RUN_PKG_CHECK(files, filesd); | ||||
| 	RUN_PKG_CHECK(symlinks, filesd); | ||||
| 	RUN_PKG_CHECK(rundeps, propsd); | ||||
| 	RUN_PKG_CHECK(requiredby, pkgd ? pkgd : opkgd, &pkgdb_update); | ||||
| 	RUN_PKG_CHECK(autoinstall, pkgd ? pkgd : opkgd, &pkgdb_update); | ||||
| 	RUN_PKG_CHECK(files, filesd, &pkgdb_update); | ||||
| 	RUN_PKG_CHECK(symlinks, filesd, &pkgdb_update); | ||||
| 	RUN_PKG_CHECK(rundeps, propsd, &pkgdb_update); | ||||
|  | ||||
| 	if (flush && pkgdb_update) { | ||||
| 		if (!xbps_pkgdb_replace_pkgd(opkgd, pkgname, false, true)) { | ||||
| 			rv = EINVAL; | ||||
| 			goto out; | ||||
| 		} | ||||
| 	} | ||||
| 	if (pkgdb_update && setflush != NULL) | ||||
| 		*setflush = true; | ||||
|  | ||||
| #undef RUN_PKG_CHECK | ||||
|  | ||||
|   | ||||
| @@ -1,5 +1,5 @@ | ||||
| /*- | ||||
|  * Copyright (c) 2011 Juan Romero Pardines. | ||||
|  * Copyright (c) 2011-2012 Juan Romero Pardines. | ||||
|  * All rights reserved. | ||||
|  * | ||||
|  * Redistribution and use in source and binary forms, with or without | ||||
| @@ -47,12 +47,10 @@ | ||||
|  * Returns 0 if test ran successfully, 1 otherwise and -1 on error. | ||||
|  */ | ||||
| int | ||||
| check_pkg_autoinstall(const char *pkgname, void *arg) | ||||
| check_pkg_autoinstall(const char *pkgname, void *arg, bool *pkgdb_update) | ||||
| { | ||||
| 	struct xbps_handle *xhp = xbps_handle_get(); | ||||
| 	prop_dictionary_t pkgd = arg; | ||||
| 	prop_array_t array, reqby; | ||||
| 	int rv = 0; | ||||
| 	prop_array_t reqby; | ||||
| 	bool autoinst = false; | ||||
|  | ||||
| 	/* | ||||
| @@ -62,39 +60,14 @@ check_pkg_autoinstall(const char *pkgname, void *arg) | ||||
| 	 */ | ||||
| 	if (prop_dictionary_get_bool(pkgd, "automatic-install", &autoinst)) { | ||||
| 		reqby = prop_dictionary_get(pkgd, "requiredby"); | ||||
| 		if (((prop_object_type(reqby) == PROP_TYPE_ARRAY)) && | ||||
| 		    ((prop_array_count(reqby) > 0) && !autoinst)) { | ||||
|  | ||||
| 		if (reqby != NULL && prop_array_count(reqby) && !autoinst) { | ||||
| 			/* pkg has reversedeps and was installed manually */ | ||||
| 			prop_dictionary_set_bool(pkgd, | ||||
| 			    "automatic-install", true); | ||||
|  | ||||
| 			array = prop_dictionary_get(xhp->regpkgdb, "packages"); | ||||
| 			rv = xbps_array_replace_dict_by_name(array, | ||||
| 			    pkgd, pkgname); | ||||
| 			if (rv != 0) { | ||||
| 				xbps_error_printf("%s: [1] failed to set " | ||||
| 				    "automatic mode (%s)\n", pkgname, | ||||
| 				    strerror(rv)); | ||||
| 				return -1; | ||||
| 			} | ||||
| 			if (!prop_dictionary_set(xhp->regpkgdb, | ||||
| 			    "packages", array)) { | ||||
| 				xbps_error_printf("%s: [2] failed to set " | ||||
| 				    "automatic mode (%s)\n", pkgname, | ||||
| 				    strerror(rv)); | ||||
| 				return -1; | ||||
| 			} | ||||
| 			if ((rv = xbps_regpkgdb_update(xhp, true)) != 0) { | ||||
| 				xbps_error_printf("%s: failed to write " | ||||
| 				    "regpkgdb plist: %s\n", pkgname, | ||||
| 				    strerror(rv)); | ||||
| 				return -1; | ||||
| 			} | ||||
| 			xbps_warn_printf("%s: was installed manually and has " | ||||
| 			    "reverse dependencies (FIXED)\n", pkgname); | ||||
| 			*pkgdb_update = true; | ||||
| 			printf("%s: changed to automatic install mode.\n", | ||||
| 			    pkgname); | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	return 0; | ||||
| } | ||||
|   | ||||
| @@ -1,5 +1,5 @@ | ||||
| /*- | ||||
|  * Copyright (c) 2011 Juan Romero Pardines. | ||||
|  * Copyright (c) 2011-2012 Juan Romero Pardines. | ||||
|  * All rights reserved. | ||||
|  * | ||||
|  * Redistribution and use in source and binary forms, with or without | ||||
| @@ -28,7 +28,6 @@ | ||||
| #include <stdlib.h> | ||||
| #include <string.h> | ||||
| #include <errno.h> | ||||
| #include <assert.h> | ||||
| #include <unistd.h> | ||||
| #include <sys/param.h> | ||||
|  | ||||
| @@ -47,7 +46,7 @@ | ||||
|  * Return 0 if test ran successfully, 1 otherwise and -1 on error. | ||||
|  */ | ||||
| int | ||||
| check_pkg_files(const char *pkgname, void *arg) | ||||
| check_pkg_files(const char *pkgname, void *arg, bool *pkgdb_update) | ||||
| { | ||||
| 	struct xbps_handle *xhp = xbps_handle_get(); | ||||
| 	prop_array_t array; | ||||
| @@ -59,9 +58,10 @@ check_pkg_files(const char *pkgname, void *arg) | ||||
| 	int rv = 0; | ||||
| 	bool broken = false, test_broken = false; | ||||
|  | ||||
| 	(void)pkgdb_update; | ||||
|  | ||||
| 	array = prop_dictionary_get(pkg_filesd, "files"); | ||||
| 	if ((prop_object_type(array) == PROP_TYPE_ARRAY) && | ||||
| 	     prop_array_count(array) > 0) { | ||||
| 	if (array != NULL && prop_array_count(array) > 0) { | ||||
| 		iter = xbps_array_iter_from_dict(pkg_filesd, "files"); | ||||
| 		if (iter == NULL) | ||||
| 			return -1; | ||||
| @@ -109,8 +109,7 @@ check_pkg_files(const char *pkgname, void *arg) | ||||
| 	 * Check for missing configuration files. | ||||
| 	 */ | ||||
| 	array = prop_dictionary_get(pkg_filesd, "conf_files"); | ||||
| 	if (array && prop_object_type(array) == PROP_TYPE_ARRAY && | ||||
| 	    prop_array_count(array) > 0) { | ||||
| 	if (array != NULL && prop_array_count(array) > 0) { | ||||
| 		iter = xbps_array_iter_from_dict(pkg_filesd, "conf_files"); | ||||
| 		if (iter == NULL) | ||||
| 			return -1; | ||||
|   | ||||
| @@ -28,135 +28,152 @@ | ||||
| #include <stdlib.h> | ||||
| #include <string.h> | ||||
| #include <errno.h> | ||||
| #include <assert.h> | ||||
| #include <unistd.h> | ||||
| #include <sys/param.h> | ||||
|  | ||||
| #include <xbps_api.h> | ||||
| #include "defs.h" | ||||
|  | ||||
| struct check_reqby_data { | ||||
| 	prop_dictionary_t pkgd; | ||||
| 	prop_array_t pkgd_reqby; | ||||
| 	const char *pkgname; | ||||
| 	const char *pkgver; | ||||
| 	bool pkgdb_update; | ||||
| 	bool pkgd_reqby_alloc; | ||||
| }; | ||||
|  | ||||
| static int | ||||
| check_reqby_pkg_cb(prop_object_t obj, void *arg, bool *done) | ||||
| { | ||||
| 	struct check_reqby_data *crd = arg; | ||||
| 	prop_array_t curpkg_rdeps, provides; | ||||
| 	prop_dictionary_t curpkg_propsd; | ||||
| 	prop_string_t curpkgver; | ||||
| 	const char *curpkgn; | ||||
|  | ||||
| 	(void)done; | ||||
|  | ||||
| 	prop_dictionary_get_cstring_nocopy(obj, "pkgname", &curpkgn); | ||||
| 	/* skip same pkg */ | ||||
| 	if (strcmp(curpkgn, crd->pkgname) == 0) | ||||
| 		return 0; | ||||
|  | ||||
| 	/* | ||||
| 	 * Internalize current pkg props dictionary from its | ||||
| 	 * installed metadata directory. | ||||
| 	 */ | ||||
| 	curpkg_propsd = | ||||
| 	    xbps_dictionary_from_metadata_plist(curpkgn, XBPS_PKGPROPS); | ||||
| 	if (curpkg_propsd == NULL) { | ||||
| 		xbps_error_printf("%s: missing %s metadata file!\n", | ||||
| 		    curpkgn, XBPS_PKGPROPS); | ||||
| 		return -1; | ||||
| 	} | ||||
| 	curpkg_rdeps = | ||||
| 	    prop_dictionary_get(curpkg_propsd, "run_depends"); | ||||
| 	if (curpkg_rdeps == NULL) { | ||||
| 		/* package has no rundeps, skip */ | ||||
| 		prop_object_release(curpkg_propsd); | ||||
| 		return 0; | ||||
| 	} | ||||
| 	/* | ||||
| 	 * Check for pkgpattern match with real packages... | ||||
| 	 */ | ||||
| 	if (!xbps_match_pkgdep_in_array(curpkg_rdeps, crd->pkgver)) { | ||||
| 		/* | ||||
| 		 * ... otherwise check if package provides any virtual | ||||
| 		 * package and is matched against any object in | ||||
| 		 * run_depends. | ||||
| 		 */ | ||||
| 		provides = prop_dictionary_get(obj, "provides"); | ||||
| 		if (provides == NULL) { | ||||
| 			/* doesn't provide any virtual pkg */ | ||||
| 			prop_object_release(curpkg_propsd); | ||||
| 			return 0; | ||||
| 		} | ||||
| 		if (!xbps_match_any_virtualpkg_in_rundeps(curpkg_rdeps, | ||||
| 		    provides)) { | ||||
| 			/* doesn't match any virtual pkg */ | ||||
| 			prop_object_release(curpkg_propsd); | ||||
| 			return 0; | ||||
| 		} | ||||
| 	} | ||||
| 	crd->pkgd_reqby = prop_dictionary_get(crd->pkgd, "requiredby"); | ||||
| 	curpkgver = prop_dictionary_get(curpkg_propsd, "pkgver"); | ||||
| 	if (crd->pkgd_reqby != NULL) { | ||||
| 		/* | ||||
| 		 * Now check that current pkgver has been registered into | ||||
| 		 * its requiredby array. | ||||
| 		 */ | ||||
| 		if (xbps_match_string_in_array(crd->pkgd_reqby, | ||||
| 		    prop_string_cstring_nocopy(curpkgver))) { | ||||
| 			/* | ||||
| 			 * Current package already requires our package, | ||||
| 			 * this is good so skip it. | ||||
| 			 */ | ||||
| 			prop_object_release(curpkg_propsd); | ||||
| 			return 0; | ||||
| 		} | ||||
| 	} else { | ||||
| 		/* | ||||
| 		 * Missing requiredby array object, create it. | ||||
| 		 */ | ||||
| 		crd->pkgd_reqby = prop_array_create(); | ||||
| 		if (crd->pkgd_reqby == NULL) { | ||||
| 			prop_object_release(curpkg_propsd); | ||||
| 			return -1; | ||||
| 		} | ||||
| 		crd->pkgd_reqby_alloc = true; | ||||
| 	} | ||||
| 	/* | ||||
| 	 * Added pkgdep into pkg's requiredby array. | ||||
| 	 */ | ||||
| 	if (!prop_array_add(crd->pkgd_reqby, curpkgver)) { | ||||
| 		prop_object_release(curpkg_propsd); | ||||
| 		return -1; | ||||
| 	} | ||||
| 	printf("%s: added missing requiredby entry for %s.\n", | ||||
| 	    crd->pkgname, prop_string_cstring_nocopy(curpkgver)); | ||||
| 	prop_object_release(curpkg_propsd); | ||||
| 	crd->pkgdb_update = true; | ||||
|  | ||||
| 	return 0; | ||||
| } | ||||
|  | ||||
| /* | ||||
|  * Checks package integrity of an installed package. | ||||
|  * The following task is accomplished in this file: | ||||
|  * | ||||
|  * 	o Check for missing reverse dependencies (aka requiredby) | ||||
|  * 	  entries in pkg's regpkgdb dictionary. | ||||
|  * 	  entries in pkg's pkgdb dictionary. | ||||
|  * | ||||
|  * Returns 0 if test ran successfully, 1 otherwise and -1 on error. | ||||
|  */ | ||||
| int | ||||
| check_pkg_requiredby(const char *pkgname, void *arg) | ||||
| check_pkg_requiredby(const char *pkgname, void *arg, bool *pkgdb_update) | ||||
| { | ||||
| 	prop_array_t regpkgs, reqby, curpkg_rdeps, provides; | ||||
| 	prop_dictionary_t curpkg_propsd, pkgd = arg; | ||||
| 	prop_object_t obj; | ||||
| 	prop_string_t curpkgver; | ||||
| 	struct xbps_handle *xhp = xbps_handle_get(); | ||||
| 	const char *curpkgn, *pkgver; | ||||
| 	size_t i; | ||||
| 	struct check_reqby_data crd; | ||||
| 	int rv; | ||||
|  | ||||
| 	prop_dictionary_get_cstring_nocopy(pkgd, "pkgver", &pkgver); | ||||
| 	crd.pkgd = arg; | ||||
| 	crd.pkgd_reqby = NULL; | ||||
| 	crd.pkgd_reqby_alloc = false; | ||||
| 	crd.pkgname = pkgname; | ||||
| 	crd.pkgdb_update = false; | ||||
| 	prop_dictionary_get_cstring_nocopy(crd.pkgd, "pkgver", &crd.pkgver); | ||||
|  | ||||
| 	regpkgs = prop_dictionary_get(xhp->regpkgdb, "packages"); | ||||
| 	rv = xbps_pkgdb_foreach_pkg_cb(check_reqby_pkg_cb, &crd); | ||||
| 	*pkgdb_update = crd.pkgdb_update; | ||||
|  | ||||
| 	for (i = 0; i < prop_array_count(regpkgs); i++) { | ||||
| 		obj = prop_array_get(regpkgs, i); | ||||
| 		prop_dictionary_get_cstring_nocopy(obj, "pkgname", &curpkgn); | ||||
| 		/* skip same pkg */ | ||||
| 		if (strcmp(curpkgn, pkgname) == 0) | ||||
| 			continue; | ||||
| 		/* | ||||
| 		 * Internalize current pkg props dictionary from its | ||||
| 		 * installed metadata directory. | ||||
| 		 */ | ||||
| 		curpkg_propsd = | ||||
| 		    xbps_dictionary_from_metadata_plist(curpkgn, XBPS_PKGPROPS); | ||||
| 		if (curpkg_propsd == NULL) { | ||||
| 			xbps_error_printf("%s: missing %s metadata file!\n", | ||||
| 			    curpkgn, XBPS_PKGPROPS); | ||||
| 			return -1; | ||||
| 		} | ||||
| 		curpkg_rdeps = | ||||
| 		    prop_dictionary_get(curpkg_propsd, "run_depends"); | ||||
| 		if (prop_object_type(curpkg_rdeps) != PROP_TYPE_ARRAY) { | ||||
| 			/* package has no rundeps, skip */ | ||||
| 			prop_object_release(curpkg_propsd); | ||||
| 			continue; | ||||
| 		} | ||||
| 		/* | ||||
| 		 * Check for pkgpattern match with real packages... | ||||
| 		 */ | ||||
| 		if (!xbps_match_pkgdep_in_array(curpkg_rdeps, pkgver)) { | ||||
| 			/* | ||||
| 			 * ... otherwise check if package provides any virtual | ||||
| 			 * package and is matched against any object in | ||||
| 			 * run_depends. | ||||
| 			 */ | ||||
| 			provides = prop_dictionary_get(pkgd, "provides"); | ||||
| 			if (prop_object_type(provides) != PROP_TYPE_ARRAY) { | ||||
| 				/* doesn't provide any virtual pkg */ | ||||
| 				prop_object_release(curpkg_propsd); | ||||
| 				continue; | ||||
| 			} | ||||
| 			if (!xbps_match_any_virtualpkg_in_rundeps(curpkg_rdeps, | ||||
| 			    provides)) { | ||||
| 				/* doesn't match any virtual pkg */ | ||||
| 				prop_object_release(curpkg_propsd); | ||||
| 				continue; | ||||
| 			} | ||||
| 		} | ||||
| 		reqby = prop_dictionary_get(pkgd, "requiredby"); | ||||
| 		curpkgver = prop_dictionary_get(curpkg_propsd, "pkgver"); | ||||
| 		if (prop_object_type(reqby) == PROP_TYPE_ARRAY) { | ||||
| 			/* | ||||
| 			 * Now check that current pkgver has been registered into | ||||
| 			 * its requiredby array. | ||||
| 			 */ | ||||
| 			if (xbps_match_string_in_array(reqby, | ||||
| 			    prop_string_cstring_nocopy(curpkgver))) { | ||||
| 				/* | ||||
| 				 * Current package already requires our package, | ||||
| 				 * this is good so skip it. | ||||
| 				 */ | ||||
| 				prop_object_release(curpkg_propsd); | ||||
| 				continue; | ||||
| 			} | ||||
| 		} else { | ||||
| 			/* | ||||
| 			 * Missing requiredby array object, create it. | ||||
| 			 */ | ||||
| 			reqby = prop_array_create(); | ||||
| 			if (reqby == NULL) { | ||||
| 				prop_object_release(curpkg_propsd); | ||||
| 				return -1; | ||||
| 			} | ||||
| 		} | ||||
| 		/* | ||||
| 		 * Replace current obj in regpkgdb and write new plist | ||||
| 		 * file to disk. | ||||
| 		 */ | ||||
| 		prop_array_add(reqby, curpkgver); | ||||
| 		prop_dictionary_set(pkgd, "requiredby", reqby); | ||||
| 		rv = xbps_array_replace_dict_by_name(regpkgs, obj, curpkgn); | ||||
| 		if (rv != 0) { | ||||
| 			xbps_error_printf("%s: failed to replace pkgd: %s\n", | ||||
| 			    curpkgn, strerror(rv)); | ||||
| 			return -1; | ||||
| 		} | ||||
| 		if (!prop_dictionary_set(xhp->regpkgdb, "packages", regpkgs)) { | ||||
| 			xbps_error_printf("%s: failed to set new regpkgdb " | ||||
| 			    "packages array: %s", curpkgn, strerror(errno)); | ||||
| 			return -1; | ||||
| 		} | ||||
| 		if ((rv = xbps_regpkgdb_update(xhp, true)) != 0) { | ||||
| 			xbps_error_printf("failed to write regpkgdb plist: " | ||||
| 			    " %s\n", strerror(rv)); | ||||
| 			return rv; | ||||
| 		} | ||||
| 		printf("%s: added requiredby entry for %s.\n", | ||||
| 		    pkgver, prop_string_cstring_nocopy(curpkgver)); | ||||
| 		prop_object_release(curpkg_propsd); | ||||
| 	if (crd.pkgdb_update) { | ||||
| 		if (!prop_dictionary_set(crd.pkgd, "requiredby", crd.pkgd_reqby)) | ||||
| 			rv = -1; | ||||
| 		if (crd.pkgd_reqby_alloc) | ||||
| 			prop_object_release(crd.pkgd_reqby); | ||||
| 	} | ||||
| 	if (rv != 0) | ||||
| 		*pkgdb_update = false; | ||||
|  | ||||
| 	return rv; | ||||
| } | ||||
|   | ||||
| @@ -1,5 +1,5 @@ | ||||
| /*- | ||||
|  * Copyright (c) 2011 Juan Romero Pardines. | ||||
|  * Copyright (c) 2011-2012 Juan Romero Pardines. | ||||
|  * All rights reserved. | ||||
|  * | ||||
|  * Redistribution and use in source and binary forms, with or without | ||||
| @@ -45,7 +45,7 @@ | ||||
|  */ | ||||
|  | ||||
| int | ||||
| check_pkg_rundeps(const char *pkgname, void *arg) | ||||
| check_pkg_rundeps(const char *pkgname, void *arg, bool *pkgdb_update) | ||||
| { | ||||
| 	prop_dictionary_t pkg_propsd = arg; | ||||
| 	prop_object_t obj; | ||||
| @@ -53,6 +53,8 @@ check_pkg_rundeps(const char *pkgname, void *arg) | ||||
| 	const char *reqpkg; | ||||
| 	bool test_broken = false; | ||||
|  | ||||
| 	(void)pkgdb_update; | ||||
|  | ||||
| 	if (!xbps_pkg_has_rundeps(pkg_propsd)) | ||||
| 		return 0; | ||||
|  | ||||
|   | ||||
| @@ -1,5 +1,5 @@ | ||||
| /*- | ||||
|  * Copyright (c) 2011 Juan Romero Pardines. | ||||
|  * Copyright (c) 2011-2012 Juan Romero Pardines. | ||||
|  * All rights reserved. | ||||
|  * | ||||
|  * Redistribution and use in source and binary forms, with or without | ||||
| @@ -45,7 +45,7 @@ | ||||
|  * returns 0 if test ran successfully, 1 otherwise and -1 on error. | ||||
|  */ | ||||
| int | ||||
| check_pkg_symlinks(const char *pkgname, void *arg) | ||||
| check_pkg_symlinks(const char *pkgname, void *arg, bool *pkgdb_update) | ||||
| { | ||||
| 	const struct xbps_handle *xhp = xbps_handle_get(); | ||||
| 	prop_array_t array; | ||||
| @@ -56,6 +56,8 @@ check_pkg_symlinks(const char *pkgname, void *arg) | ||||
| 	char *path, buf[PATH_MAX]; | ||||
| 	bool broken = false, test_broken = false; | ||||
|  | ||||
| 	(void)pkgdb_update; | ||||
|  | ||||
| 	array = prop_dictionary_get(pkg_filesd, "links"); | ||||
| 	if ((prop_object_type(array) == PROP_TYPE_ARRAY) && | ||||
| 	     prop_array_count(array) > 0) { | ||||
|   | ||||
| @@ -56,11 +56,11 @@ int	exec_transaction(bool, bool); | ||||
| int	remove_installed_pkgs(int, char **, bool, bool, bool, bool); | ||||
|  | ||||
| /* from check.c */ | ||||
| int	check_pkg_integrity(prop_dictionary_t, const char *); | ||||
| int	check_pkg_integrity(prop_dictionary_t, const char *, bool, bool *); | ||||
| int	check_pkg_integrity_all(void); | ||||
|  | ||||
| #define CHECK_PKG_DECL(type)			\ | ||||
| int check_pkg_##type (const char *, void *) | ||||
| int check_pkg_##type (const char *, void *, bool *) | ||||
|  | ||||
| CHECK_PKG_DECL(autoinstall); | ||||
| CHECK_PKG_DECL(files); | ||||
|   | ||||
| @@ -203,7 +203,7 @@ main(int argc, char **argv) | ||||
| 		 * Find the longest pkgver string to pretty print the output. | ||||
| 		 */ | ||||
| 		lpc.pkgver_len = find_longest_pkgver(NULL); | ||||
| 		rv = xbps_regpkgdb_foreach_pkg_cb(list_pkgs_in_dict, &lpc); | ||||
| 		rv = xbps_pkgdb_foreach_pkg_cb(list_pkgs_in_dict, &lpc); | ||||
| 		if (rv == ENOENT) { | ||||
| 			printf("No packages currently registered.\n"); | ||||
| 			rv = 0; | ||||
| @@ -281,7 +281,7 @@ main(int argc, char **argv) | ||||
| 		if (strcasecmp(argv[1], "all") == 0) | ||||
| 			rv = check_pkg_integrity_all(); | ||||
| 		else | ||||
| 			rv = check_pkg_integrity(NULL, argv[1]); | ||||
| 			rv = check_pkg_integrity(NULL, argv[1], true, NULL); | ||||
|  | ||||
| 	} else if (strcasecmp(argv[0], "autoupdate") == 0) { | ||||
| 		/* | ||||
| @@ -342,7 +342,7 @@ main(int argc, char **argv) | ||||
| 		if (argc != 1) | ||||
| 			usage(); | ||||
|  | ||||
| 		rv = xbps_regpkgdb_foreach_pkg_cb(list_manual_pkgs, NULL); | ||||
| 		rv = xbps_pkgdb_foreach_pkg_cb(list_manual_pkgs, NULL); | ||||
|  | ||||
| 	} else if (strcasecmp(argv[0], "show-revdeps") == 0) { | ||||
| 		/* | ||||
|   | ||||
| @@ -28,7 +28,6 @@ | ||||
| #include <stdlib.h> | ||||
| #include <errno.h> | ||||
| #include <fnmatch.h> | ||||
| #include <assert.h> | ||||
| #include <string.h> | ||||
| #include <strings.h> | ||||
|  | ||||
| @@ -88,9 +87,6 @@ show_pkg_info_one(prop_dictionary_t d, const char *keys) | ||||
| 	prop_object_t obj; | ||||
| 	char *key, *p, *saveptr; | ||||
|  | ||||
| 	assert(prop_object_type(d) == PROP_TYPE_DICTIONARY); | ||||
| 	assert(keys != NULL); | ||||
|  | ||||
| 	if (strchr(keys, ',') == NULL) { | ||||
| 		obj = prop_dictionary_get(d, keys); | ||||
| 		if (obj == NULL) | ||||
| @@ -99,7 +95,8 @@ show_pkg_info_one(prop_dictionary_t d, const char *keys) | ||||
| 		return; | ||||
| 	} | ||||
| 	key = strdup(keys); | ||||
| 	assert(key != NULL); | ||||
| 	if (key == NULL) | ||||
| 		abort(); | ||||
| 	for ((p = strtok_r(key, ",", &saveptr)); p; | ||||
| 	    (p = strtok_r(NULL, ",", &saveptr))) { | ||||
| 		obj = prop_dictionary_get(d, p); | ||||
| @@ -118,9 +115,6 @@ show_pkg_info(prop_dictionary_t dict) | ||||
| 	const char *keyname; | ||||
| 	size_t i; | ||||
|  | ||||
| 	assert(prop_object_type(dict) == PROP_TYPE_DICTIONARY); | ||||
| 	assert(prop_dictionary_count(dict) != 0); | ||||
|  | ||||
| 	all_keys = prop_dictionary_all_keys(dict); | ||||
| 	for (i = 0; i < prop_array_count(all_keys); i++) { | ||||
| 		keysym = prop_array_get(all_keys, i); | ||||
| @@ -151,8 +145,7 @@ show_pkg_files(prop_dictionary_t filesd) | ||||
| 			continue; | ||||
|  | ||||
| 		array = prop_dictionary_get(filesd, keyname); | ||||
| 		if (prop_object_type(array) != PROP_TYPE_ARRAY || | ||||
| 		    prop_array_count(array) == 0) | ||||
| 		if (array == NULL || prop_array_count(array) == 0) | ||||
| 			continue; | ||||
|  | ||||
| 		for (x = 0; x < prop_array_count(array); x++) { | ||||
| @@ -194,7 +187,7 @@ find_longest_pkgver(prop_object_t o) | ||||
| 		(void)xbps_callback_array_iter(o, | ||||
| 		    _find_longest_pkgver_cb, &len); | ||||
| 	else | ||||
| 		(void)xbps_regpkgdb_foreach_pkg_cb( | ||||
| 		(void)xbps_pkgdb_foreach_pkg_cb( | ||||
| 		    _find_longest_pkgver_cb, &len); | ||||
|  | ||||
| 	return len; | ||||
| @@ -206,7 +199,6 @@ list_strings_in_array(prop_object_t obj, void *arg, bool *loop_done) | ||||
| 	(void)arg; | ||||
| 	(void)loop_done; | ||||
|  | ||||
| 	assert(prop_object_type(obj) == PROP_TYPE_STRING); | ||||
| 	print_package_line(prop_string_cstring_nocopy(obj), false); | ||||
|  | ||||
| 	return 0; | ||||
| @@ -219,7 +211,6 @@ list_strings_sep_in_array(prop_object_t obj, void *arg, bool *loop_done) | ||||
|  | ||||
| 	(void)loop_done; | ||||
|  | ||||
| 	assert(prop_object_type(obj) == PROP_TYPE_STRING); | ||||
| 	printf("%s%s\n", sep ? sep : "", prop_string_cstring_nocopy(obj)); | ||||
|  | ||||
| 	return 0; | ||||
|   | ||||
| @@ -1,4 +1,4 @@ | ||||
| .Dd January 5, 2012 | ||||
| .Dd January 19, 2012 | ||||
| .Os Void GNU/Linux | ||||
| .Dt xbps-bin 8 | ||||
| .Sh NAME | ||||
| @@ -254,8 +254,8 @@ XBPS global metadata directory. | ||||
| Installed package metadata list of files. | ||||
| .It Pa /var/db/xbps/metadata/<pkgname>/props.plist | ||||
| Installed package metadata properties. | ||||
| .It Pa /var/db/xbps/regpkgdb.plist | ||||
| XBPS master packages/properties database plist file. | ||||
| .It Pa /var/db/xbps/pkgdb.plist | ||||
| XBPS master package database plist file. | ||||
| .It Pa /var/cache/xbps | ||||
| XBPS cache directory for downloaded binary packages. | ||||
| .Sh EXAMPLES | ||||
|   | ||||
| @@ -235,7 +235,7 @@ static void | ||||
| parse_array_in_pkg_dictionary(FILE *f, prop_dictionary_t plistd, | ||||
| 			      prop_dictionary_t sub_confd, | ||||
| 			      prop_array_t allkeys, | ||||
| 			      bool parse_regpkgdb) | ||||
| 			      bool parse_pkgdb) | ||||
| { | ||||
| 	prop_dictionary_keysym_t dksym; | ||||
| 	prop_object_t keyobj, sub_keyobj; | ||||
| @@ -248,11 +248,11 @@ parse_array_in_pkg_dictionary(FILE *f, prop_dictionary_t plistd, | ||||
| 		tmpkeyname = prop_dictionary_keysym_cstring_nocopy(dksym); | ||||
|  | ||||
| 		/* | ||||
| 		 * While parsing package's dictionary from regpkgdb, we are | ||||
| 		 * While parsing package's dictionary from pkgdb, we are | ||||
| 		 * only interested in the "automatic-install" and "requiredby" | ||||
| 		 * objects. | ||||
| 		 */ | ||||
| 		if (parse_regpkgdb && | ||||
| 		if (parse_pkgdb && | ||||
| 		    (strcmp(tmpkeyname, "automatic-install")) && | ||||
| 		    (strcmp(tmpkeyname, "requiredby"))) | ||||
| 			continue; | ||||
| @@ -418,14 +418,14 @@ create_dot_graph(FILE *f, | ||||
| 	parse_array_in_pkg_dictionary(f, plistd, sub_confd, allkeys, false); | ||||
|  | ||||
| 	/* | ||||
| 	 * Process all objects in package's dictionary from regpkgdb property | ||||
| 	 * list file, aka XBPS_META_PATH/XBPS_REGPKGDB. | ||||
| 	 * Process all objects in package's dictionary from pkgdb property | ||||
| 	 * list file, aka XBPS_META_PATH/XBPS_PKGDB. | ||||
| 	 */ | ||||
| 	if (revdeps) { | ||||
| 		regpkgd = xbps_find_pkg_dict_installed(pkgn, false); | ||||
| 		if (regpkgd == NULL) | ||||
| 			die("cannot find '%s' dictionary on %s!", | ||||
| 			    pkgn, XBPS_REGPKGDB); | ||||
| 			    pkgn, XBPS_PKGDB); | ||||
|  | ||||
| 		allkeys = prop_dictionary_all_keys(regpkgd); | ||||
| 		parse_array_in_pkg_dictionary(f, regpkgd, sub_confd, | ||||
|   | ||||
| @@ -38,7 +38,6 @@ | ||||
| #include <errno.h> | ||||
| #include <limits.h> | ||||
| #include <libgen.h> | ||||
| #include <assert.h> | ||||
|  | ||||
| #include <xbps_api.h> | ||||
| #include "../xbps-bin/defs.h" | ||||
| @@ -100,9 +99,6 @@ show_pkg_namedesc(prop_object_t obj, void *arg, bool *loop_done) | ||||
|  | ||||
| 	(void)loop_done; | ||||
|  | ||||
| 	assert(prop_object_type(obj) == PROP_TYPE_DICTIONARY); | ||||
| 	assert(rsd->patterns != NULL); | ||||
|  | ||||
| 	prop_dictionary_get_cstring_nocopy(obj, "pkgname", &pkgname); | ||||
| 	prop_dictionary_get_cstring_nocopy(obj, "pkgver", &pkgver); | ||||
| 	prop_dictionary_get_cstring_nocopy(obj, "short_desc", &desc); | ||||
|   | ||||
| @@ -188,7 +188,7 @@ main(int argc, char **argv) | ||||
| 		prop_dictionary_set_cstring(dict, "pkgver", pkgver); | ||||
| 		prop_dictionary_set_bool(dict, "automatic-install", false); | ||||
|  | ||||
| 		pkgd = xbps_regpkgdb_get_pkgd(argv[1], false); | ||||
| 		pkgd = xbps_pkgdb_get_pkgd(argv[1], false); | ||||
| 		if (pkgd != NULL) { | ||||
| 			prop_dictionary_get_cstring_nocopy(pkgd, | ||||
| 			    "pkgname", &pkgn); | ||||
| @@ -244,7 +244,7 @@ main(int argc, char **argv) | ||||
| 		if (argc != 2) | ||||
| 			usage(); | ||||
|  | ||||
| 		dict = xbps_regpkgdb_get_pkgd(argv[1], false); | ||||
| 		dict = xbps_pkgdb_get_pkgd(argv[1], false); | ||||
| 		if (dict == NULL) { | ||||
| 			rv = errno; | ||||
| 			goto out; | ||||
|   | ||||
| @@ -1,13 +1,12 @@ | ||||
| digraph regpkgdb_dictionary { | ||||
| digraph pkgdb_array { | ||||
| 	graph [rankdir=LR,rank=same,ranksep=".10"]; | ||||
| 	edge [arrowhead="vee",arrowsize="0.2",fontname="DejaVuSansCondensed",fontsize="9"]; | ||||
| 	node [height=".1",shape=box,fontname="DejaVuSansCondensed",fontsize="9"]; | ||||
| 	regpkgdb_plist -> main; | ||||
| 	regpkgdb_plist [style=filled,fillcolor="darksalmon",label="regpkgdb.plist"]; | ||||
| 	main [label="Main dictionary"]; | ||||
| 	main -> packages [label="array"]; | ||||
| 	packages -> pkgdict [label="dictionary"]; | ||||
| 	packages -> pkgdict2 [label="dictionary"]; | ||||
| 	pkgdb_plist -> main; | ||||
| 	pkgdb_plist [style=filled,fillcolor="darksalmon",label="pkgdb.plist"]; | ||||
| 	main [label="Main array"]; | ||||
| 	main -> pkgdict [label="dictionary"]; | ||||
| 	main -> pkgdict2 [label="dictionary"]; | ||||
| 	pkgdict [style=filled,label="Package[0]"]; | ||||
| 	pkgdict2 [style=filled,label="Package[N+1]"]; | ||||
| 	pkgdict2 -> pkgdict2_objs [label="objects"]; | ||||
|   | ||||
| @@ -56,7 +56,7 @@ | ||||
|  */ | ||||
| #define XBPS_PKGINDEX_VERSION	"1.4" | ||||
|  | ||||
| #define XBPS_API_VERSION	"20120119" | ||||
| #define XBPS_API_VERSION	"20120120" | ||||
| #define XBPS_VERSION		"0.12" | ||||
|  | ||||
| /** | ||||
| @@ -80,10 +80,10 @@ | ||||
| #define XBPS_CACHE_PATH		"var/cache/xbps" | ||||
|  | ||||
| /**  | ||||
|  * @def XBPS_REGPKGDB | ||||
|  * Filename for the global package register database. | ||||
|  * @def XBPS_PKGDB | ||||
|  * Filename for the master package database. | ||||
|  */ | ||||
| #define XBPS_REGPKGDB		"regpkgdb.plist" | ||||
| #define XBPS_PKGDB		"pkgdb.plist" | ||||
|  | ||||
| /**  | ||||
|  * @def XBPS_PKGPROPS | ||||
| @@ -428,19 +428,19 @@ struct xbps_handle { | ||||
| 	 * @private | ||||
| 	 */ | ||||
| 	cfg_t *cfg; | ||||
| 	/** | ||||
| 	 * @private regpkgdb. | ||||
| 	 * | ||||
| 	 * Internalized proplib dictionary with the registed package database | ||||
| 	 * stored in XBPS_META_PATH/XBPS_REGPKGDB. | ||||
| 	 */ | ||||
| 	prop_dictionary_t regpkgdb; | ||||
| 	/** | ||||
| 	 * @private | ||||
| 	 * | ||||
| 	 * Array of dictionaries with all registered repositories. | ||||
| 	 */ | ||||
| 	prop_array_t repo_pool; | ||||
| 	/** | ||||
| 	 * @private pkgdb. | ||||
| 	 * | ||||
| 	 * Internalized proplib array with the master package database | ||||
| 	 * stored in XBPS_META_PATH/XBPS_PKGDB. | ||||
| 	 */ | ||||
| 	prop_array_t pkgdb; | ||||
| 	/** | ||||
| 	 * @var xbps_state_cb | ||||
| 	 * | ||||
| @@ -601,7 +601,7 @@ struct xbps_handle *xbps_handle_get(void); | ||||
|  * @param[in] check_state Set it to true to check that package is | ||||
|  * in unpacked state. | ||||
|  * @param[in] update Set it to true if this package is being updated. | ||||
|  * @param[in] flush Set it to true to flush state to regpkgdb. | ||||
|  * @param[in] flush Set it to true to flush state to pkgdb. | ||||
|  * | ||||
|  * @return 0 on success, otherwise an errno value. | ||||
|  */ | ||||
| @@ -613,7 +613,7 @@ int xbps_configure_pkg(const char *pkgname, | ||||
|  | ||||
| /** | ||||
|  * Configure (or force reconfiguration of) all packages. | ||||
|  * @param[in] flush Set it to true to flush state to regpkgdb. | ||||
|  * @param[in] flush Set it to true to flush state to pkgdb. | ||||
|  * | ||||
|  * @return 0 on success, otherwise an errno value. | ||||
|  */ | ||||
| @@ -739,6 +739,23 @@ int xbps_callback_array_iter(prop_array_t array, | ||||
| 			     int (*fn)(prop_object_t, void *, bool *), | ||||
| 			     void *arg); | ||||
|  | ||||
| /** | ||||
|  * Executes a function callback specified in \a fn with \a arg passed | ||||
|  * as its argument into they array \a array in reverse order (upwards). | ||||
|  * | ||||
|  * @param[in] array Proplib array to iterate. | ||||
|  * @param[in] fn Function callback to run on every object in the array. | ||||
|  * While running the function callback, the hird parameter (a pointer to | ||||
|  * a boolean) can be set to true to stop immediately the loop. | ||||
|  * @param[in] arg Argument to be passed to the function callback. | ||||
|  * | ||||
|  * @return 0 on success, otherwise the value returned by the function | ||||
|  * callback. | ||||
|  */ | ||||
| int xbps_callback_array_iter_reverse(prop_array_t array, | ||||
| 				     int (*fn)(prop_object_t, void *, bool *), | ||||
| 				     void *arg); | ||||
|  | ||||
| /** | ||||
|  * Executes a function callback into the array associated with key \a key, | ||||
|  * contained in a proplib dictionary. | ||||
| @@ -781,7 +798,7 @@ int xbps_callback_array_iter_reverse_in_dict(prop_dictionary_t dict, | ||||
|  | ||||
| /** | ||||
|  * Executes a function callback per a package dictionary registered | ||||
|  * in "regpkgdb" plist (downwards). | ||||
|  * in master package database (pkgdb) plist (downwards). | ||||
|  * | ||||
|  * @param[in] fn Function callback to run for any pkg dictionary. | ||||
|  * @param[in] arg Argument to be passed to the function callback. | ||||
| @@ -789,12 +806,12 @@ int xbps_callback_array_iter_reverse_in_dict(prop_dictionary_t dict, | ||||
|  * @return 0 on success (all objects were processed), otherwise | ||||
|  * the value returned by the function callback. | ||||
|  */ | ||||
| int xbps_regpkgdb_foreach_pkg_cb(int (*fn)(prop_object_t, void *, bool *), | ||||
| 				 void *arg); | ||||
| int xbps_pkgdb_foreach_pkg_cb(int (*fn)(prop_object_t, void *, bool *), | ||||
| 			      void *arg); | ||||
|  | ||||
| /** | ||||
|  * Executes a function callback per a package dictionary registered | ||||
|  * in "regpkgdb" plist, in reverse order (upwards). | ||||
|  * in master package database (pkgdb) plist, in reverse order (upwards). | ||||
|  * | ||||
|  * @param[in] fn Function callback to run for any pkg dictionary. | ||||
|  * @param[in] arg Argument to be passed to the function callback. | ||||
| @@ -802,46 +819,68 @@ int xbps_regpkgdb_foreach_pkg_cb(int (*fn)(prop_object_t, void *, bool *), | ||||
|  * @return 0 on success (all objects were processed), otherwise | ||||
|  * the value returned by the funcion callback. | ||||
|  */ | ||||
| int xbps_regpkgdb_foreach_reverse_pkg_cb( | ||||
| int xbps_pkgdb_foreach_reverse_pkg_cb( | ||||
| 		int (*fn)(prop_object_t, void *, bool *), | ||||
| 		void *arg); | ||||
|  | ||||
| /** | ||||
|  * Returns a package dictionary from regpkgdb plist, matching pkgname or | ||||
|  * pkgver specified in \a pkg. | ||||
|  * Returns a package dictionary from master package database (pkgdb) plist, | ||||
|  * matching pkgname or pkgver object in \a pkg. | ||||
|  * | ||||
|  * @param[in] pkg Package name or name-version to match. | ||||
|  * @param[in] bypattern If false \a pkg must be a pkgname, otherwise a | ||||
|  * package pattern, i.e `foo>=0' or `foo<1'. | ||||
|  * | ||||
|  * @return The matching proplib package dictionary from regpkgdb copied | ||||
|  * @return The matching proplib package dictionary from kgdb copied | ||||
|  * with \a prop_dictionary_copy() so it must be released when not required | ||||
|  * anymore with prop_object_release(). NULL otherwise. | ||||
|  */ | ||||
| prop_dictionary_t xbps_regpkgdb_get_pkgd(const char *pkg, bool bypattern); | ||||
| prop_dictionary_t xbps_pkgdb_get_pkgd(const char *pkg, bool bypattern); | ||||
|  | ||||
| /** | ||||
|  * Removes a package dictionary from regpkgdb plist matching the key | ||||
|  * \a pkgname. | ||||
|  * Removes a package dictionary from master package database (pkgdb) plist, | ||||
|  * matching pkgname or pkgver object in \a pkg. | ||||
|  * | ||||
|  * @param[in] pkgname Package name to match in a dictionary. | ||||
|  * @param[in] pkg Package name or pattern to match in a package dictionary. | ||||
|  * @param[in] bypattern If false \a pkg must be a pkgname, otherwise a | ||||
|  * package pattern, i.e `foo>=0' or `foo<1'. | ||||
|  * @param[in] flush If true, after successful replace the pkgdb contents | ||||
|  * in memory will be flushed atomically to storage. | ||||
|  * | ||||
|  * @return true on success, false otherwise. | ||||
|  */ | ||||
| bool xbps_regpkgdb_remove_pkgd(const char *pkgname); | ||||
| bool xbps_pkgdb_remove_pkgd(const char *pkg, bool bypattern, bool flush); | ||||
|  | ||||
| /** | ||||
|  * Updates the regpkgdb plist with new contents from disk to the cached copy | ||||
|  * in memory. | ||||
|  * Replaces a package dictionary with \a dict in the master package database | ||||
|  * (pkgdb) plist, matching pkgname or pkgver object. | ||||
|  * | ||||
|  * @param[in] dict Proplib dictionary to be added into pkgdb. | ||||
|  * @param[in] pkg Package name or pattern to match in a package dictionary. | ||||
|  * @param[in] bypattern If false \a pkg must be a pkgname, otherwise a | ||||
|  * package pattern, i.e `foo>=0' or `foo<1'. | ||||
|  * @param[in] flush If true, after successful replace the pkgdb contents in | ||||
|  * memory will be flushed atomically to storage. | ||||
|  * | ||||
|  * @return true on success, false otherwise. | ||||
|  */ | ||||
| bool xbps_pkgdb_replace_pkgd(prop_dictionary_t pkgd, | ||||
| 			     const char *pkg, | ||||
| 			     bool bypattern, | ||||
| 			     bool flush); | ||||
|  | ||||
| /** | ||||
|  * Updates the master package database (pkgdb) plist with new contents from | ||||
|  * disk to the cached copy in memory. | ||||
|  * | ||||
|  * @param[in] xhp Pointer to our xbps_handle struct, as returned by | ||||
|  * \a xbps_handle_get(). | ||||
|  * @param[in] flush If true the regpkgdb plist contents in memory will | ||||
|  * be flushed atomically to disk. | ||||
|  * @param[in] flush If true the pkgdb plist contents in memory will | ||||
|  * be flushed atomically to storage. | ||||
|  * | ||||
|  * @return 0 on success, otherwise an errno value. | ||||
|  */ | ||||
| int xbps_regpkgdb_update(struct xbps_handle *xhp, bool flush); | ||||
| int xbps_pkgdb_update(struct xbps_handle *xhp, bool flush); | ||||
|  | ||||
| /** | ||||
|  * Finds the proplib's dictionary associated with a package, by looking | ||||
| @@ -1133,6 +1172,18 @@ bool xbps_remove_pkg_dict_from_plist_by_name(const char *pkgname, | ||||
|  */ | ||||
| bool xbps_remove_pkg_from_array_by_name(prop_array_t array, const char *name); | ||||
|  | ||||
| /** | ||||
|  * Removes the package's proplib dictionary matching the pkgver object | ||||
|  * with a package pattern from \a pattern in a proplib array. | ||||
|  * | ||||
|  * @param[in] array Proplib array where to look for. | ||||
|  * @param[in] pattern Package pattern to match, i.e `foo>=0' or `foo<1'. | ||||
|  * | ||||
|  * @return true on success, false otherwise and errno is set appropiately. | ||||
|  */ | ||||
| bool xbps_remove_pkg_from_array_by_pattern(prop_array_t array, | ||||
| 					   const char *pattern); | ||||
|  | ||||
| /** | ||||
|  * Removes the package's proplib dictionary matching the \a pkgver | ||||
|  * object in a proplib array of dictionaries. | ||||
| @@ -1142,7 +1193,8 @@ bool xbps_remove_pkg_from_array_by_name(prop_array_t array, const char *name); | ||||
|  * | ||||
|  * @return true on success, false otherwise and errno is set appropiately. | ||||
|  */ | ||||
| bool xbps_remove_pkg_from_array_by_pkgver(prop_array_t array, const char *pkgver); | ||||
| bool xbps_remove_pkg_from_array_by_pkgver(prop_array_t array, | ||||
| 					  const char *pkgver); | ||||
|  | ||||
| /** | ||||
|  * Removes the package's proplib dictionary matching \a pkgname, | ||||
| @@ -1193,6 +1245,22 @@ int xbps_array_replace_dict_by_name(prop_array_t array, | ||||
| 				    prop_dictionary_t dict, | ||||
| 				    const char *pkgname); | ||||
|  | ||||
| /** | ||||
|  * Replaces a dictionary with another dictionary in \a dict, in | ||||
|  * the array \a array by matching its pkgver object with a package pattern, | ||||
|  * i.e `foo>=0' or `foo<1'. | ||||
|  * | ||||
|  * @param[in] array Proplib array where to look for. | ||||
|  * @param[in] dict Proplib dictionary to be added in \a array. | ||||
|  * @param[in] pattern Package pattern to be matched, i.e `foo>=0'. | ||||
|  * | ||||
|  * @return 0 on success, EINVAL id dictionary couldn't be set in the array | ||||
|  * or ENOENT if no match. | ||||
|  */ | ||||
| int xbps_array_replace_dict_by_pattern(prop_array_t array, | ||||
| 				       prop_dictionary_t dict, | ||||
| 				       const char *pattern); | ||||
|  | ||||
| /*@}*/ | ||||
|  | ||||
| /** @addtogroup pkg_register */ | ||||
| @@ -1204,7 +1272,7 @@ int xbps_array_replace_dict_by_name(prop_array_t array, | ||||
|  * @param[in] pkg_dict A dictionary with the following objects: | ||||
|  * \a pkgname, \a version, \a pkgver, \a short_desc (string), | ||||
|  * \a automatic-install (bool) and optionally \a provides (array of strings). | ||||
|  * @param[in] flush Set to true to make sure that regpkgdb plist | ||||
|  * @param[in] flush Set to true to make sure that pkgdb plist | ||||
|  * is written to storage on success. | ||||
|  * | ||||
|  * @return 0 on success, otherwise an errno value. | ||||
| @@ -1216,7 +1284,7 @@ int xbps_register_pkg(prop_dictionary_t pkg_dict, bool flush); | ||||
|  * | ||||
|  * @param[in] pkgname Package name. | ||||
|  * @param[in] version Package version. | ||||
|  * @param[in] flush Set to true to make sure that regpkgdb plist | ||||
|  * @param[in] flush Set to true to make sure that pkgdb plist | ||||
|  * is written to storage on success. | ||||
|  * | ||||
|  * @return 0 on success, otherwise an errno value. | ||||
|   | ||||
| @@ -69,10 +69,10 @@ int HIDDEN dewey_match(const char *, const char *); | ||||
|  | ||||
| /** | ||||
|  * @private | ||||
|  * From lib/regpkgdb_dictionary.c | ||||
|  * From lib/pkgdb.c | ||||
|  */ | ||||
| int HIDDEN xbps_regpkgdb_dictionary_init(struct xbps_handle *); | ||||
| void HIDDEN xbps_regpkgdb_dictionary_release(struct xbps_handle *); | ||||
| int HIDDEN xbps_pkgdb_init(struct xbps_handle *); | ||||
| void HIDDEN xbps_pkgdb_release(struct xbps_handle *); | ||||
|  | ||||
| /** | ||||
|  * @private | ||||
|   | ||||
| @@ -196,7 +196,7 @@ xbps_end(void) | ||||
| 	if (!xbps_initialized) | ||||
| 		return; | ||||
|  | ||||
| 	xbps_regpkgdb_dictionary_release(xhp); | ||||
| 	xbps_pkgdb_release(xhp); | ||||
| 	xbps_repository_pool_release(xhp); | ||||
| 	xbps_fetch_unset_cache_connection(); | ||||
|  | ||||
|   | ||||
| @@ -65,9 +65,9 @@ xbps_configure_packages(bool flush) | ||||
| 	struct xbps_handle *xhp = xbps_handle_get(); | ||||
| 	int rv; | ||||
|  | ||||
| 	rv = xbps_regpkgdb_foreach_pkg_cb(configure_pkgs_cb, NULL); | ||||
| 	rv = xbps_pkgdb_foreach_pkg_cb(configure_pkgs_cb, NULL); | ||||
| 	if (rv == 0 && flush) | ||||
| 		rv = xbps_regpkgdb_update(xhp, true); | ||||
| 		rv = xbps_pkgdb_update(xhp, true); | ||||
|  | ||||
| 	return rv; | ||||
| } | ||||
| @@ -109,7 +109,7 @@ xbps_configure_pkg(const char *pkgname, | ||||
| 		} else if (state != XBPS_PKG_STATE_UNPACKED) | ||||
| 			return EINVAL; | ||||
| 	 | ||||
| 		pkgd = xbps_regpkgdb_get_pkgd(pkgname, false); | ||||
| 		pkgd = xbps_pkgdb_get_pkgd(pkgname, false); | ||||
| 		prop_dictionary_get_cstring_nocopy(pkgd, "version", &lver); | ||||
| 		prop_object_release(pkgd); | ||||
| 	} else { | ||||
| @@ -169,7 +169,7 @@ xbps_configure_pkg(const char *pkgname, | ||||
| 	} | ||||
| 	free(pkgver); | ||||
| 	if (flush) | ||||
| 		rv = xbps_regpkgdb_update(xhp, true); | ||||
| 		rv = xbps_pkgdb_update(xhp, true); | ||||
|  | ||||
| 	return rv; | ||||
| } | ||||
|   | ||||
| @@ -1,5 +1,5 @@ | ||||
| /*- | ||||
|  * Copyright (c) 2009-2011 Juan Romero Pardines. | ||||
|  * Copyright (c) 2009-2012 Juan Romero Pardines. | ||||
|  * All rights reserved. | ||||
|  * | ||||
|  * Redistribution and use in source and binary forms, with or without | ||||
| @@ -176,12 +176,11 @@ xbps_find_pkg_orphans(prop_array_t orphans_user) | ||||
| 	if ((od.array = prop_array_create()) == NULL) | ||||
| 		return NULL; | ||||
| 	/* | ||||
| 	 * Find out all orphans by looking at the | ||||
| 	 * regpkgdb dictionary and iterate in reverse order | ||||
| 	 * in which packages were installed. | ||||
| 	 * Find out all orphans by looking at pkgdb and iterating in reverse | ||||
| 	 * order in which packages were installed. | ||||
| 	 */ | ||||
| 	od.orphans_user = orphans_user; | ||||
| 	rv = xbps_regpkgdb_foreach_reverse_pkg_cb(find_orphan_pkg, &od); | ||||
| 	rv = xbps_pkgdb_foreach_reverse_pkg_cb(find_orphan_pkg, &od); | ||||
| 	if (rv != 0) { | ||||
| 		errno = rv; | ||||
| 		prop_object_release(od.array); | ||||
|   | ||||
| @@ -43,7 +43,6 @@ int | ||||
| xbps_register_pkg(prop_dictionary_t pkgrd, bool flush) | ||||
| { | ||||
| 	struct xbps_handle *xhp; | ||||
| 	prop_array_t array; | ||||
| 	prop_dictionary_t pkgd = NULL; | ||||
| 	prop_array_t provides, reqby; | ||||
| 	const char *pkgname, *version, *desc, *pkgver; | ||||
| @@ -69,7 +68,7 @@ xbps_register_pkg(prop_dictionary_t pkgrd, bool flush) | ||||
| 	assert(desc != NULL); | ||||
| 	assert(pkgver != NULL); | ||||
|  | ||||
| 	pkgd = xbps_regpkgdb_get_pkgd(pkgname, false); | ||||
| 	pkgd = xbps_pkgdb_get_pkgd(pkgname, false); | ||||
| 	if (pkgd == NULL) { | ||||
| 		rv = ENOENT; | ||||
| 		goto out; | ||||
| @@ -127,16 +126,11 @@ xbps_register_pkg(prop_dictionary_t pkgrd, bool flush) | ||||
| 			goto out; | ||||
| 		} | ||||
| 	} | ||||
| 	array = prop_dictionary_get(xhp->regpkgdb, "packages"); | ||||
| 	rv = xbps_array_replace_dict_by_name(array, pkgd, pkgname); | ||||
| 	if (rv != 0) { | ||||
| 	if (!xbps_pkgdb_replace_pkgd(pkgd, pkgname, false, flush)) { | ||||
| 		xbps_dbg_printf("%s: failed to replace pkgd dict for %s\n", | ||||
| 		    __func__, pkgname); | ||||
| 		goto out; | ||||
| 	} | ||||
| 	if (flush) | ||||
| 		rv = xbps_regpkgdb_update(xhp, true); | ||||
|  | ||||
| out: | ||||
| 	if (pkgd != NULL) | ||||
| 		prop_object_release(pkgd); | ||||
| @@ -154,23 +148,16 @@ out: | ||||
| int | ||||
| xbps_unregister_pkg(const char *pkgname, const char *version, bool flush) | ||||
| { | ||||
| 	struct xbps_handle *xhp; | ||||
|  | ||||
| 	assert(pkgname != NULL); | ||||
|  | ||||
| 	xbps_set_cb_state(XBPS_STATE_UNREGISTER, 0, pkgname, version, NULL); | ||||
|  | ||||
| 	if (!xbps_regpkgdb_remove_pkgd(pkgname)) { | ||||
| 	if (!xbps_pkgdb_remove_pkgd(pkgname, false, flush)) { | ||||
| 		xbps_set_cb_state(XBPS_STATE_UNREGISTER_FAIL, | ||||
| 		    errno, pkgname, version, | ||||
| 		    "%s: failed to unregister package: %s", | ||||
| 		    pkgname, strerror(errno)); | ||||
| 		return errno; | ||||
| 	} | ||||
| 	if (flush) { | ||||
| 		xhp = xbps_handle_get(); | ||||
| 		return xbps_regpkgdb_update(xhp, true); | ||||
| 	} | ||||
|  | ||||
| 	return 0; | ||||
| } | ||||
|   | ||||
| @@ -1,5 +1,5 @@ | ||||
| /*- | ||||
|  * Copyright (c) 2009-2011 Juan Romero Pardines. | ||||
|  * Copyright (c) 2009-2012 Juan Romero Pardines. | ||||
|  * All rights reserved. | ||||
|  * | ||||
|  * Redistribution and use in source and binary forms, with or without | ||||
| @@ -413,7 +413,7 @@ purge: | ||||
| 			goto out; | ||||
| 	} | ||||
| 	/* | ||||
| 	 * Unregister package from regpkgdb. | ||||
| 	 * Unregister package from pkgdb. | ||||
| 	 */ | ||||
| 	if ((rv = xbps_unregister_pkg(pkgname, version, false)) != 0) | ||||
| 		goto out; | ||||
|   | ||||
| @@ -103,14 +103,14 @@ int HIDDEN | ||||
| xbps_requiredby_pkg_remove(const char *pkgname) | ||||
| { | ||||
| 	assert(pkgname != NULL); | ||||
| 	return xbps_regpkgdb_foreach_pkg_cb(remove_pkg_from_reqby, __UNCONST(pkgname)); | ||||
| 	return xbps_pkgdb_foreach_pkg_cb(remove_pkg_from_reqby, __UNCONST(pkgname)); | ||||
| } | ||||
|  | ||||
| int HIDDEN | ||||
| xbps_requiredby_pkg_add(struct xbps_handle *xhp, prop_dictionary_t pkgd) | ||||
| { | ||||
| 	prop_array_t pkg_rdeps; | ||||
| 	prop_object_t obj, pkgd_regpkgdb; | ||||
| 	prop_object_t obj, pkgd_pkgdb; | ||||
| 	prop_object_iterator_t iter; | ||||
| 	const char *pkgver, *str; | ||||
| 	int rv = 0; | ||||
| @@ -134,20 +134,20 @@ xbps_requiredby_pkg_add(struct xbps_handle *xhp, prop_dictionary_t pkgd) | ||||
| 		} | ||||
| 		xbps_dbg_printf("%s: adding reqby entry for %s\n", __func__, str); | ||||
|  | ||||
| 		pkgd_regpkgdb = xbps_find_virtualpkg_conf_in_dict_by_pattern( | ||||
| 		    xhp->regpkgdb, "packages", str); | ||||
| 		if (pkgd_regpkgdb == NULL) { | ||||
| 			pkgd_regpkgdb = | ||||
| 			    xbps_find_virtualpkg_in_dict_by_pattern( | ||||
| 			    xhp->regpkgdb, "packages", str); | ||||
| 			if (pkgd_regpkgdb == NULL) { | ||||
| 		pkgd_pkgdb = xbps_find_virtualpkg_conf_in_array_by_pattern( | ||||
| 		    xhp->pkgdb, str); | ||||
| 		if (pkgd_pkgdb == NULL) { | ||||
| 			pkgd_pkgdb = | ||||
| 			    xbps_find_virtualpkg_in_array_by_pattern( | ||||
| 			    xhp->pkgdb, str); | ||||
| 			if (pkgd_pkgdb == NULL) { | ||||
| 				rv = ENOENT; | ||||
| 				xbps_dbg_printf("%s: couldnt find `%s' " | ||||
| 				     "entry in regpkgdb\n", __func__, str); | ||||
| 				     "entry in pkgdb\n", __func__, str); | ||||
| 				break; | ||||
| 			} | ||||
| 		} | ||||
| 		rv = add_pkg_into_reqby(pkgd_regpkgdb, pkgver); | ||||
| 		rv = add_pkg_into_reqby(pkgd_pkgdb, pkgver); | ||||
| 		if (rv != 0) | ||||
| 			break; | ||||
| 	} | ||||
|   | ||||
| @@ -1,5 +1,5 @@ | ||||
| /*- | ||||
|  * Copyright (c) 2009-2011 Juan Romero Pardines. | ||||
|  * Copyright (c) 2009-2012 Juan Romero Pardines. | ||||
|  * All rights reserved. | ||||
|  * | ||||
|  * Redistribution and use in source and binary forms, with or without | ||||
| @@ -100,7 +100,7 @@ xbps_pkg_state_installed(const char *pkgname, pkg_state_t *state) | ||||
| 	assert(pkgname != NULL); | ||||
| 	assert(state != NULL); | ||||
|  | ||||
| 	pkgd = xbps_regpkgdb_get_pkgd(pkgname, false); | ||||
| 	pkgd = xbps_pkgdb_get_pkgd(pkgname, false); | ||||
| 	if (pkgd == NULL) | ||||
| 		return ENOENT; | ||||
|  | ||||
| @@ -161,49 +161,43 @@ xbps_set_pkg_state_installed(const char *pkgname, | ||||
| { | ||||
| 	struct xbps_handle *xhp; | ||||
| 	prop_dictionary_t pkgd; | ||||
| 	prop_array_t array; | ||||
| 	bool newpkg = false; | ||||
| 	int rv; | ||||
|  | ||||
| 	assert(pkgname != NULL); | ||||
| 	xhp = xbps_handle_get(); | ||||
|  | ||||
| 	if (xhp->regpkgdb == NULL) { | ||||
| 		xhp->regpkgdb = prop_dictionary_create(); | ||||
| 		if (xhp->regpkgdb == NULL) | ||||
| 			return ENOMEM; | ||||
|  | ||||
| 		array = prop_array_create(); | ||||
| 		if (array == NULL) | ||||
| 	if (xhp->pkgdb == NULL) { | ||||
| 		xhp->pkgdb = prop_array_create(); | ||||
| 		if (xhp->pkgdb == NULL) | ||||
| 			return ENOMEM; | ||||
|  | ||||
| 		pkgd = prop_dictionary_create(); | ||||
| 		if (pkgd == NULL) { | ||||
| 			prop_object_release(array); | ||||
| 			prop_object_release(xhp->pkgdb); | ||||
| 			xhp->pkgdb = NULL; | ||||
| 			return ENOMEM; | ||||
| 		} | ||||
| 		if ((rv = set_pkg_objs(pkgd, pkgname, version, pkgver)) != 0) { | ||||
| 			prop_object_release(array); | ||||
| 			prop_object_release(xhp->pkgdb); | ||||
| 			prop_object_release(pkgd); | ||||
| 			xhp->pkgdb = NULL; | ||||
| 			return rv; | ||||
| 		} | ||||
| 		if ((rv = set_new_state(pkgd, state)) != 0) { | ||||
| 			prop_object_release(array); | ||||
| 			prop_object_release(xhp->pkgdb); | ||||
| 			prop_object_release(pkgd); | ||||
| 			xhp->pkgdb = NULL; | ||||
| 			return rv; | ||||
| 		} | ||||
| 		if (!xbps_add_obj_to_array(array, pkgd)) { | ||||
| 			prop_object_release(array); | ||||
| 		if (!xbps_add_obj_to_array(xhp->pkgdb, pkgd)) { | ||||
| 			prop_object_release(xhp->pkgdb); | ||||
| 			prop_object_release(pkgd); | ||||
| 			xhp->pkgdb = NULL; | ||||
| 			return EINVAL; | ||||
| 		} | ||||
| 		if (!xbps_add_obj_to_dict(xhp->regpkgdb, array, "packages")) { | ||||
| 			prop_object_release(array); | ||||
| 			return EINVAL; | ||||
| 		} | ||||
|  | ||||
| 	} else { | ||||
| 		pkgd = xbps_regpkgdb_get_pkgd(pkgname, false); | ||||
| 		pkgd = xbps_pkgdb_get_pkgd(pkgname, false); | ||||
| 		if (pkgd == NULL) { | ||||
| 			newpkg = true; | ||||
| 			pkgd = prop_dictionary_create(); | ||||
| @@ -218,21 +212,18 @@ xbps_set_pkg_state_installed(const char *pkgname, | ||||
| 				prop_object_release(pkgd); | ||||
| 			return rv; | ||||
| 		} | ||||
| 		array = prop_dictionary_get(xhp->regpkgdb, "packages"); | ||||
| 		if (newpkg) { | ||||
| 			if (!xbps_add_obj_to_array(array, pkgd)) { | ||||
| 			if (!xbps_add_obj_to_array(xhp->pkgdb, pkgd)) { | ||||
| 				prop_object_release(pkgd); | ||||
| 				return EINVAL; | ||||
| 			} | ||||
| 		} else { | ||||
| 			if ((rv = xbps_array_replace_dict_by_name(array, | ||||
| 			if ((rv = xbps_array_replace_dict_by_name(xhp->pkgdb, | ||||
| 			    pkgd, pkgname)) != 0) | ||||
| 				return rv; | ||||
|  | ||||
| 			prop_object_release(pkgd); | ||||
| 		} | ||||
| 		if (!prop_dictionary_set(xhp->regpkgdb, "packages", array)) | ||||
| 			return EINVAL; | ||||
| 	} | ||||
|  | ||||
| 	return rv; | ||||
|   | ||||
| @@ -136,10 +136,12 @@ extract_metafile(struct archive *ar, | ||||
| 		    rv, pkgname, version, | ||||
| 		    "%s: [unpack] failed to extract metafile `%s': %s", | ||||
| 		    pkgver, file, strerror(rv)); | ||||
| 		free(dirc); | ||||
| 		free(pkgname); | ||||
| 		return rv; | ||||
| 	} | ||||
| 	free(pkgname); | ||||
| 	free(dirc); | ||||
|  | ||||
| 	return 0; | ||||
| } | ||||
|   | ||||
							
								
								
									
										102
									
								
								lib/plist.c
									
									
									
									
									
								
							
							
						
						
									
										102
									
								
								lib/plist.c
									
									
									
									
									
								
							| @@ -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 | ||||
| @@ -122,6 +122,8 @@ xbps_callback_array_iter_in_dict(prop_dictionary_t dict, | ||||
|  | ||||
| 	for (i = 0; i < prop_array_count(array); i++) { | ||||
| 		obj = prop_array_get(array, i); | ||||
| 		if (obj == NULL) | ||||
| 			continue; | ||||
| 		rv = (*fn)(obj, arg, &cbloop_done); | ||||
| 		if (rv != 0 || cbloop_done) | ||||
| 			break; | ||||
| @@ -130,6 +132,34 @@ xbps_callback_array_iter_in_dict(prop_dictionary_t dict, | ||||
| 	return rv; | ||||
| } | ||||
|  | ||||
| int | ||||
| xbps_callback_array_iter_reverse(prop_array_t array, | ||||
| 				 int (*fn)(prop_object_t, void *, bool *), | ||||
| 				 void *arg) | ||||
| { | ||||
| 	prop_object_t obj; | ||||
| 	unsigned int cnt; | ||||
| 	int rv; | ||||
| 	bool loop_done = false; | ||||
|  | ||||
| 	assert(prop_object_type(array) == PROP_TYPE_ARRAY); | ||||
| 	assert(fn != NULL); | ||||
|  | ||||
| 	if ((cnt = prop_array_count(array)) == 0) | ||||
| 		return 0; | ||||
|  | ||||
| 	while (cnt--) { | ||||
| 		obj = prop_array_get(array, cnt); | ||||
| 		if (obj == NULL) | ||||
| 			continue; | ||||
| 		rv = (*fn)(obj, arg, &loop_done); | ||||
| 		if (rv != 0 || loop_done) | ||||
| 			break; | ||||
| 	} | ||||
|  | ||||
| 	return rv; | ||||
| } | ||||
|  | ||||
| int | ||||
| xbps_callback_array_iter_reverse_in_dict(prop_dictionary_t dict, | ||||
| 			const char *key, | ||||
| @@ -137,10 +167,6 @@ xbps_callback_array_iter_reverse_in_dict(prop_dictionary_t dict, | ||||
| 			void *arg) | ||||
| { | ||||
| 	prop_array_t array; | ||||
| 	prop_object_t obj; | ||||
| 	int rv = 0; | ||||
| 	bool cbloop_done = false; | ||||
| 	unsigned int cnt = 0; | ||||
|  | ||||
| 	assert(prop_object_type(dict) == PROP_TYPE_DICTIONARY); | ||||
| 	assert(key != NULL); | ||||
| @@ -152,17 +178,7 @@ xbps_callback_array_iter_reverse_in_dict(prop_dictionary_t dict, | ||||
| 		return EINVAL; | ||||
| 	} | ||||
|  | ||||
| 	if ((cnt = prop_array_count(array)) == 0) | ||||
| 		return 0; | ||||
|  | ||||
| 	while (cnt--) { | ||||
| 		obj = prop_array_get(array, cnt); | ||||
| 		rv = (*fn)(obj, arg, &cbloop_done); | ||||
| 		if (rv != 0 || cbloop_done) | ||||
| 			break; | ||||
| 	} | ||||
|  | ||||
| 	return rv; | ||||
| 	return xbps_callback_array_iter_reverse(array, fn, arg); | ||||
| } | ||||
|  | ||||
| prop_object_iterator_t | ||||
| @@ -182,10 +198,11 @@ xbps_array_iter_from_dict(prop_dictionary_t dict, const char *key) | ||||
| 	return prop_array_iterator(array); | ||||
| } | ||||
|  | ||||
| int | ||||
| xbps_array_replace_dict_by_name(prop_array_t array, | ||||
| 				prop_dictionary_t dict, | ||||
| 				const char *pkgname) | ||||
| static int | ||||
| array_replace_dict(prop_array_t array, | ||||
| 		   prop_dictionary_t dict, | ||||
| 		   const char *str, | ||||
| 		   bool bypattern) | ||||
| { | ||||
| 	prop_object_t obj; | ||||
| 	size_t i; | ||||
| @@ -193,23 +210,54 @@ xbps_array_replace_dict_by_name(prop_array_t array, | ||||
|  | ||||
| 	assert(prop_object_type(array) == PROP_TYPE_ARRAY); | ||||
| 	assert(prop_object_type(dict) == PROP_TYPE_DICTIONARY); | ||||
| 	assert(pkgname != NULL); | ||||
| 	assert(str != NULL); | ||||
|  | ||||
| 	for (i = 0; i < prop_array_count(array); i++) { | ||||
| 		obj = prop_array_get(array, i); | ||||
| 		prop_dictionary_get_cstring_nocopy(obj, "pkgname", &curpkgname); | ||||
| 		if (strcmp(curpkgname, pkgname) == 0) { | ||||
| 			/* pkgname match, we know the index */ | ||||
| 			if (!prop_array_set(array, i, dict)) | ||||
| 				return EINVAL; | ||||
| 		if (obj == NULL) | ||||
| 			continue; | ||||
| 		if (bypattern) { | ||||
| 			/* pkgpattern match */ | ||||
| 			prop_dictionary_get_cstring_nocopy(obj, | ||||
| 			    "pkgver", &curpkgname); | ||||
| 			if (xbps_pkgpattern_match(curpkgname, str)) { | ||||
| 				if (!prop_array_set(array, i, dict)) | ||||
| 					return EINVAL; | ||||
|  | ||||
| 			return 0; | ||||
| 				return 0; | ||||
| 			} | ||||
| 		} else { | ||||
| 			/* pkgname match */ | ||||
| 			prop_dictionary_get_cstring_nocopy(obj, | ||||
| 			    "pkgname", &curpkgname); | ||||
| 			if (strcmp(curpkgname, str) == 0) { | ||||
| 				if (!prop_array_set(array, i, dict)) | ||||
| 					return EINVAL; | ||||
|  | ||||
| 				return 0; | ||||
| 			} | ||||
| 		} | ||||
| 	} | ||||
| 	/* no match */ | ||||
| 	return ENOENT; | ||||
| } | ||||
|  | ||||
| int | ||||
| xbps_array_replace_dict_by_name(prop_array_t array, | ||||
| 				prop_dictionary_t dict, | ||||
| 				const char *pkgname) | ||||
| { | ||||
| 	return array_replace_dict(array, dict, pkgname, false); | ||||
| } | ||||
|  | ||||
| int | ||||
| xbps_array_replace_dict_by_pattern(prop_array_t array, | ||||
| 				   prop_dictionary_t dict, | ||||
| 				   const char *pattern) | ||||
| { | ||||
| 	return array_replace_dict(array, dict, pattern, true); | ||||
| } | ||||
|  | ||||
| prop_dictionary_t | ||||
| xbps_dictionary_from_metadata_plist(const char *pkgname, | ||||
| 				    const char *plist) | ||||
|   | ||||
| @@ -386,10 +386,10 @@ find_pkgd_installed(const char *str, bool bypattern, bool virtual) | ||||
| 	assert(str != NULL); | ||||
|  | ||||
| 	xhp = xbps_handle_get(); | ||||
| 	if ((rv = xbps_regpkgdb_dictionary_init(xhp)) != 0) { | ||||
| 	if ((rv = xbps_pkgdb_init(xhp)) != 0) { | ||||
| 		if (rv != ENOENT) { | ||||
| 			xbps_dbg_printf("%s: couldn't initialize " | ||||
| 			    "regpkgdb: %s\n", strerror(rv)); | ||||
| 			    "pkgdb: %s\n", strerror(rv)); | ||||
| 			return NULL; | ||||
| 		} else if (rv == ENOENT) | ||||
| 			return NULL; | ||||
| @@ -397,16 +397,15 @@ find_pkgd_installed(const char *str, bool bypattern, bool virtual) | ||||
|  | ||||
| 	/* try normal pkg */ | ||||
| 	if (virtual == false) { | ||||
| 		pkgd = find_pkg_in_dict(xhp->regpkgdb, | ||||
| 		    "packages", str, bypattern, false); | ||||
| 		pkgd = find_pkg_in_array(xhp->pkgdb, str, bypattern, false); | ||||
| 	} else { | ||||
| 		/* virtual pkg set by user in conf */ | ||||
| 		pkgd = find_virtualpkg_user_in_dict(xhp->regpkgdb, | ||||
| 		    "packages", str, bypattern); | ||||
| 		pkgd = find_virtualpkg_user_in_array(xhp->pkgdb, | ||||
| 		    str, bypattern); | ||||
| 		if (pkgd == NULL) { | ||||
| 			/* any virtual pkg in dictionary matching pattern */ | ||||
| 			pkgd = find_pkg_in_dict(xhp->regpkgdb, | ||||
| 			    "packages", str, bypattern, true); | ||||
| 			/* any virtual pkg in array matching pattern */ | ||||
| 			pkgd = find_pkg_in_array(xhp->pkgdb, | ||||
| 			    str, bypattern, true); | ||||
| 		} | ||||
| 	} | ||||
| 	/* pkg not found */ | ||||
|   | ||||
| @@ -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 | ||||
| @@ -40,7 +40,7 @@ | ||||
|  * all library functions. | ||||
|  */ | ||||
| static bool | ||||
| remove_string_from_array(prop_array_t array, const char *str, int mode) | ||||
| remove_obj_from_array(prop_array_t array, const char *str, int mode) | ||||
| { | ||||
| 	prop_object_iterator_t iter; | ||||
| 	prop_object_t obj; | ||||
| @@ -90,6 +90,14 @@ remove_string_from_array(prop_array_t array, const char *str, int mode) | ||||
| 				found = true; | ||||
| 				break; | ||||
| 			} | ||||
| 		} else if (mode == 4) { | ||||
| 			/* match by pattern, obj is a dictionary */ | ||||
| 			prop_dictionary_get_cstring_nocopy(obj, | ||||
| 			    "pkgver", &curname); | ||||
| 			if (xbps_pkgpattern_match(curname, str)) { | ||||
| 				found = true; | ||||
| 				break; | ||||
| 			} | ||||
| 		} | ||||
| 		idx++; | ||||
| 	} | ||||
| @@ -107,25 +115,31 @@ remove_string_from_array(prop_array_t array, const char *str, int mode) | ||||
| bool | ||||
| xbps_remove_string_from_array(prop_array_t array, const char *str) | ||||
| { | ||||
| 	return remove_string_from_array(array, str, 0); | ||||
| 	return remove_obj_from_array(array, str, 0); | ||||
| } | ||||
|  | ||||
| bool | ||||
| xbps_remove_pkgname_from_array(prop_array_t array, const char *name) | ||||
| { | ||||
| 	return remove_string_from_array(array, name, 1); | ||||
| 	return remove_obj_from_array(array, name, 1); | ||||
| } | ||||
|  | ||||
| bool | ||||
| xbps_remove_pkg_from_array_by_name(prop_array_t array, const char *name) | ||||
| { | ||||
| 	return remove_string_from_array(array, name, 2); | ||||
| 	return remove_obj_from_array(array, name, 2); | ||||
| } | ||||
|  | ||||
| bool | ||||
| xbps_remove_pkg_from_array_by_pkgver(prop_array_t array, const char *pkgver) | ||||
| { | ||||
| 	return remove_string_from_array(array, pkgver, 3); | ||||
| 	return remove_obj_from_array(array, pkgver, 3); | ||||
| } | ||||
|  | ||||
| bool | ||||
| xbps_remove_pkg_from_array_by_pattern(prop_array_t array, const char *p) | ||||
| { | ||||
| 	return remove_obj_from_array(array, p, 4); | ||||
| } | ||||
|  | ||||
| bool | ||||
|   | ||||
| @@ -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 | ||||
| @@ -31,66 +31,41 @@ | ||||
|  | ||||
| #include "xbps_api_impl.h" | ||||
|  | ||||
| /** | ||||
|  * @file lib/regpkgdb_dictionary.c | ||||
|  * @brief Package register database routines | ||||
|  * @defgroup regpkgdb Package register database functions | ||||
|  * | ||||
|  * These functions will initialize and release (resources of) | ||||
|  * the registered packages database plist file (defined by XBPS_REGPKGDB). | ||||
|  * | ||||
|  * The returned dictionary by xbps_regpkgs_dictionary_init() uses | ||||
|  * the structure as shown in the next graph: | ||||
|  * | ||||
|  * @image html images/xbps_regpkgdb_dictionary.png | ||||
|  * | ||||
|  * Legend: | ||||
|  *  - <b>Salmon filled box</b>: \a XBPS_REGPKGDB_PLIST file internalized. | ||||
|  *  - <b>White filled box</b>: mandatory objects. | ||||
|  *  - <b>Grey filled box</b>: optional objects. | ||||
|  *  - <b>Green filled box</b>: possible value set in the object, only one | ||||
|  *    of them is set. | ||||
|  * | ||||
|  * Text inside of white boxes are the key associated with the object, its | ||||
|  * data type is specified on its edge, i.e array, bool, integer, string, | ||||
|  * dictionary. | ||||
|  */ | ||||
|  | ||||
| int HIDDEN | ||||
| xbps_regpkgdb_dictionary_init(struct xbps_handle *xhp) | ||||
| xbps_pkgdb_init(struct xbps_handle *xhp) | ||||
| { | ||||
| 	int rv; | ||||
|  | ||||
| 	assert(xhp != NULL); | ||||
|  | ||||
| 	if (xhp->regpkgdb != NULL) | ||||
| 	if (xhp->pkgdb != NULL) | ||||
| 		return 0; | ||||
|  | ||||
| 	rv = xbps_regpkgdb_update(xhp, false); | ||||
| 	rv = xbps_pkgdb_update(xhp, false); | ||||
| 	if (rv != 0) { | ||||
| 		if (rv != ENOENT) | ||||
| 			xbps_dbg_printf("[regpkgdb] cannot internalize " | ||||
| 			    "regpkgdb dictionary: %s\n", strerror(rv)); | ||||
| 			xbps_dbg_printf("[pkgdb] cannot internalize " | ||||
| 			    "pkgdb array: %s\n", strerror(rv)); | ||||
|  | ||||
| 		return rv; | ||||
| 	} | ||||
| 	xbps_dbg_printf("[regpkgdb] initialized ok.\n"); | ||||
| 	xbps_dbg_printf("[pkgdb] initialized ok.\n"); | ||||
|  | ||||
| 	return 0; | ||||
| } | ||||
|  | ||||
| int | ||||
| xbps_regpkgdb_update(struct xbps_handle *xhp, bool flush) | ||||
| xbps_pkgdb_update(struct xbps_handle *xhp, bool flush) | ||||
| { | ||||
| 	char *plist, *metadir; | ||||
| 	int rv = 0; | ||||
|  | ||||
| 	plist = xbps_xasprintf("%s/%s/%s", xhp->rootdir, | ||||
| 	    XBPS_META_PATH, XBPS_REGPKGDB); | ||||
| 	    XBPS_META_PATH, XBPS_PKGDB); | ||||
| 	if (plist == NULL) | ||||
| 		return ENOMEM; | ||||
|  | ||||
| 	if (xhp->regpkgdb != NULL && flush) { | ||||
| 	if (xhp->pkgdb != NULL && flush) { | ||||
| 		metadir = xbps_xasprintf("%s/%s", xhp->rootdir, | ||||
| 		    XBPS_META_PATH); | ||||
| 		if (metadir == NULL) { | ||||
| @@ -101,7 +76,7 @@ xbps_regpkgdb_update(struct xbps_handle *xhp, bool flush) | ||||
| 		if (access(metadir, X_OK) == -1) { | ||||
| 			if (errno == ENOENT) { | ||||
| 				if (xbps_mkpath(metadir, 0755) != 0) { | ||||
| 					xbps_dbg_printf("[regpkgdb] failed to " | ||||
| 					xbps_dbg_printf("[pkgdb] failed to " | ||||
| 					    "create metadir %s: %s\n", metadir, | ||||
| 					    strerror(errno)); | ||||
| 					rv = errno; | ||||
| @@ -116,17 +91,16 @@ xbps_regpkgdb_update(struct xbps_handle *xhp, bool flush) | ||||
| 		} | ||||
| 		free(metadir); | ||||
| 		/* flush dictionary to storage */ | ||||
| 		if (!prop_dictionary_externalize_to_zfile(xhp->regpkgdb, | ||||
| 		    plist)) { | ||||
| 		if (!prop_array_externalize_to_zfile(xhp->pkgdb, plist)) { | ||||
| 			free(plist); | ||||
| 			return errno; | ||||
| 		} | ||||
| 		prop_object_release(xhp->regpkgdb); | ||||
| 		xhp->regpkgdb = NULL; | ||||
| 		prop_object_release(xhp->pkgdb); | ||||
| 		xhp->pkgdb = NULL; | ||||
| 	} | ||||
| 	/* update copy in memory */ | ||||
| 	xhp->regpkgdb = prop_dictionary_internalize_from_zfile(plist); | ||||
| 	if (xhp->regpkgdb == NULL) | ||||
| 	xhp->pkgdb = prop_array_internalize_from_zfile(plist); | ||||
| 	if (xhp->pkgdb == NULL) | ||||
| 		rv = errno; | ||||
|  | ||||
| 	free(plist); | ||||
| @@ -135,16 +109,16 @@ xbps_regpkgdb_update(struct xbps_handle *xhp, bool flush) | ||||
| } | ||||
|  | ||||
| void HIDDEN | ||||
| xbps_regpkgdb_dictionary_release(struct xbps_handle *xhp) | ||||
| xbps_pkgdb_release(struct xbps_handle *xhp) | ||||
| { | ||||
| 	assert(xhp != NULL); | ||||
|  | ||||
| 	if (xhp->regpkgdb == NULL) | ||||
| 	if (xhp->pkgdb == NULL) | ||||
| 		return; | ||||
|  | ||||
| 	prop_object_release(xhp->regpkgdb); | ||||
| 	xhp->regpkgdb = NULL; | ||||
| 	xbps_dbg_printf("[regpkgdb] released ok.\n"); | ||||
| 	prop_object_release(xhp->pkgdb); | ||||
| 	xhp->pkgdb = NULL; | ||||
| 	xbps_dbg_printf("[pkgdb] released ok.\n"); | ||||
| } | ||||
|  | ||||
| static int | ||||
| @@ -155,62 +129,96 @@ foreach_pkg_cb(int (*fn)(prop_object_t, void *, bool *), | ||||
| 	struct xbps_handle *xhp = xbps_handle_get(); | ||||
| 	int rv; | ||||
|  | ||||
| 	/* initialize regpkgdb */ | ||||
| 	if ((rv = xbps_regpkgdb_dictionary_init(xhp)) != 0) | ||||
| 	if ((rv = xbps_pkgdb_init(xhp)) != 0) | ||||
| 		return rv; | ||||
|  | ||||
| 	if (reverse) { | ||||
| 		rv = xbps_callback_array_iter_reverse_in_dict( | ||||
| 		    xhp->regpkgdb, "packages", fn, arg); | ||||
| 	} else { | ||||
| 		rv = xbps_callback_array_iter_in_dict( | ||||
| 		    xhp->regpkgdb, "packages", fn, arg); | ||||
| 	} | ||||
| 	if (reverse) | ||||
| 		rv = xbps_callback_array_iter_reverse(xhp->pkgdb, fn, arg); | ||||
| 	else | ||||
| 		rv = xbps_callback_array_iter(xhp->pkgdb, fn, arg); | ||||
|  | ||||
| 	return rv; | ||||
| } | ||||
|  | ||||
| int | ||||
| xbps_regpkgdb_foreach_reverse_pkg_cb(int (*fn)(prop_object_t, void *, bool *), | ||||
| 				     void *arg) | ||||
| xbps_pkgdb_foreach_reverse_pkg_cb(int (*fn)(prop_object_t, void *, bool *), | ||||
| 				  void *arg) | ||||
| { | ||||
| 	return foreach_pkg_cb(fn, arg, true); | ||||
| } | ||||
|  | ||||
| int | ||||
| xbps_regpkgdb_foreach_pkg_cb(int (*fn)(prop_object_t, void *, bool *), | ||||
| 			     void *arg) | ||||
| xbps_pkgdb_foreach_pkg_cb(int (*fn)(prop_object_t, void *, bool *), | ||||
| 			  void *arg) | ||||
| { | ||||
| 	return foreach_pkg_cb(fn, arg, false); | ||||
| } | ||||
|  | ||||
| prop_dictionary_t | ||||
| xbps_regpkgdb_get_pkgd(const char *pkg, bool bypattern) | ||||
| xbps_pkgdb_get_pkgd(const char *pkg, bool bypattern) | ||||
| { | ||||
| 	struct xbps_handle *xhp = xbps_handle_get(); | ||||
| 	prop_dictionary_t pkgd = NULL; | ||||
|  | ||||
| 	if (xbps_regpkgdb_dictionary_init(xhp) != 0) | ||||
| 	if (xbps_pkgdb_init(xhp) != 0) | ||||
| 		return NULL; | ||||
|  | ||||
| 	if (bypattern) | ||||
| 		pkgd = xbps_find_pkg_in_dict_by_pattern(xhp->regpkgdb, | ||||
| 		    "packages", pkg); | ||||
| 		pkgd = xbps_find_pkg_in_array_by_pattern(xhp->pkgdb, pkg); | ||||
| 	else | ||||
| 		pkgd = xbps_find_pkg_in_dict_by_name(xhp->regpkgdb, | ||||
| 		    "packages", pkg); | ||||
| 		pkgd = xbps_find_pkg_in_array_by_name(xhp->pkgdb, pkg); | ||||
|  | ||||
| 	return prop_dictionary_copy(pkgd); | ||||
| 	if (pkgd != NULL) | ||||
| 		return prop_dictionary_copy(pkgd); | ||||
|  | ||||
| 	return NULL; | ||||
| } | ||||
|  | ||||
| bool | ||||
| xbps_regpkgdb_remove_pkgd(const char *pkgname) | ||||
| xbps_pkgdb_remove_pkgd(const char *pkg, bool bypattern, bool flush) | ||||
| { | ||||
|  | ||||
| 	struct xbps_handle *xhp = xbps_handle_get(); | ||||
| 	bool rv = false; | ||||
|  | ||||
| 	if (xbps_regpkgdb_dictionary_init(xhp) != 0) | ||||
| 	if (xbps_pkgdb_init(xhp) != 0) | ||||
| 		return false; | ||||
|  | ||||
| 	return xbps_remove_pkg_from_dict_by_name(xhp->regpkgdb, | ||||
| 	    "packages", pkgname); | ||||
| 	if (bypattern) | ||||
| 		rv = xbps_remove_pkg_from_array_by_pattern(xhp->pkgdb, pkg); | ||||
| 	else | ||||
| 		rv = xbps_remove_pkg_from_array_by_name(xhp->pkgdb, pkg); | ||||
|  | ||||
| 	if (!flush || !rv) | ||||
| 		return rv; | ||||
|  | ||||
| 	if ((xbps_pkgdb_update(xhp, true)) != 0) | ||||
| 		return false; | ||||
|  | ||||
| 	return true; | ||||
| } | ||||
|  | ||||
| bool | ||||
| xbps_pkgdb_replace_pkgd(prop_dictionary_t pkgd, | ||||
| 			const char *pkg, | ||||
| 			bool bypattern, | ||||
| 			bool flush) | ||||
| { | ||||
| 	struct xbps_handle *xhp = xbps_handle_get(); | ||||
| 	int rv; | ||||
|  | ||||
| 	if (xbps_pkgdb_init(xhp) != 0) | ||||
| 		return false; | ||||
|  | ||||
| 	if (bypattern) | ||||
| 		rv = xbps_array_replace_dict_by_pattern(xhp->pkgdb, pkgd, pkg); | ||||
| 	else | ||||
| 		rv = xbps_array_replace_dict_by_name(xhp->pkgdb, pkgd, pkg); | ||||
|  | ||||
| 	if (!flush || rv != 0) | ||||
| 		return rv; | ||||
|  | ||||
| 	if ((xbps_pkgdb_update(xhp, true)) != 0) | ||||
| 		return false; | ||||
|  | ||||
| 	return true; | ||||
| } | ||||
|   | ||||
| @@ -54,10 +54,11 @@ check_repo_arch(const char *uri) | ||||
|  | ||||
| 	uname(&un); | ||||
| 	b = basename(p); | ||||
| 	free(p); | ||||
| 	if ((strcmp(b, "noarch")) && (strcmp(b, un.machine))) | ||||
| 	if ((strcmp(b, "noarch")) && (strcmp(b, un.machine))) { | ||||
| 		free(p); | ||||
| 		return false; | ||||
|  | ||||
| 	} | ||||
| 	free(p); | ||||
| 	return true; | ||||
| } | ||||
|  | ||||
|   | ||||
| @@ -198,7 +198,7 @@ xbps_transaction_commit(prop_dictionary_t transd) | ||||
| 	while ((obj = prop_object_iterator_next(iter)) != NULL) { | ||||
| 		if ((xhp->transaction_frequency_flush > 0) && | ||||
| 		    (++i >= xhp->transaction_frequency_flush)) { | ||||
| 			rv = xbps_regpkgdb_update(xhp, true); | ||||
| 			rv = xbps_pkgdb_update(xhp, true); | ||||
| 			if (rv != 0 && rv != ENOENT) | ||||
| 				goto out; | ||||
|  | ||||
| @@ -274,7 +274,7 @@ xbps_transaction_commit(prop_dictionary_t transd) | ||||
| 	prop_object_iterator_reset(iter); | ||||
|  | ||||
| 	/* force a flush now packages were removed/unpacked */ | ||||
| 	if ((rv = xbps_regpkgdb_update(xhp, true)) != 0) | ||||
| 	if ((rv = xbps_pkgdb_update(xhp, true)) != 0) | ||||
| 		goto out; | ||||
|  | ||||
| 	/* if there are no packages to install or update we are done */ | ||||
| @@ -289,7 +289,7 @@ xbps_transaction_commit(prop_dictionary_t transd) | ||||
| 	while ((obj = prop_object_iterator_next(iter)) != NULL) { | ||||
| 		if (xhp->transaction_frequency_flush > 0 && | ||||
| 		    ++i >= xhp->transaction_frequency_flush) { | ||||
| 			if ((rv = xbps_regpkgdb_update(xhp, true)) != 0) | ||||
| 			if ((rv = xbps_pkgdb_update(xhp, true)) != 0) | ||||
| 				goto out; | ||||
|  | ||||
| 			i = 0; | ||||
| @@ -323,7 +323,7 @@ xbps_transaction_commit(prop_dictionary_t transd) | ||||
| 	} | ||||
|  | ||||
| 	/* Force a flush now that packages are configured */ | ||||
| 	rv = xbps_regpkgdb_update(xhp, true); | ||||
| 	rv = xbps_pkgdb_update(xhp, true); | ||||
| out: | ||||
| 	prop_object_iterator_release(iter); | ||||
|  | ||||
|   | ||||
| @@ -59,7 +59,7 @@ enum { | ||||
| static int | ||||
| transaction_find_pkg(const char *pattern, int action) | ||||
| { | ||||
| 	prop_dictionary_t pkg_regpkgdb, pkg_repod = NULL; | ||||
| 	prop_dictionary_t pkg_pkgdb, pkg_repod = NULL; | ||||
| 	prop_dictionary_t transd; | ||||
| 	prop_array_t mdeps, unsorted; | ||||
| 	const char *pkgname, *pkgver, *repoloc, *repover, *instver, *reason; | ||||
| @@ -76,8 +76,8 @@ transaction_find_pkg(const char *pattern, int action) | ||||
| 		reason = "install"; | ||||
| 	} else { | ||||
| 		/* update */ | ||||
| 		pkg_regpkgdb = xbps_find_pkg_dict_installed(pattern, false); | ||||
| 		if (pkg_regpkgdb == NULL) { | ||||
| 		pkg_pkgdb = xbps_find_pkg_dict_installed(pattern, false); | ||||
| 		if (pkg_pkgdb == NULL) { | ||||
| 			rv = ENODEV; | ||||
| 			goto out; | ||||
| 		} | ||||
| @@ -109,11 +109,11 @@ transaction_find_pkg(const char *pattern, int action) | ||||
| 		/* | ||||
| 		 * Compare installed version vs best pkg available in repos. | ||||
| 		 */ | ||||
| 		prop_dictionary_get_cstring_nocopy(pkg_regpkgdb, | ||||
| 		prop_dictionary_get_cstring_nocopy(pkg_pkgdb, | ||||
| 		    "version", &instver); | ||||
| 		prop_dictionary_get_cstring_nocopy(pkg_repod, | ||||
| 		    "version", &repover); | ||||
| 		prop_object_release(pkg_regpkgdb); | ||||
| 		prop_object_release(pkg_pkgdb); | ||||
| 		if (xbps_cmpver(repover, instver) <= 0) { | ||||
| 			xbps_dbg_printf("[rpool] Skipping `%s' " | ||||
| 			    "(installed: %s) from repository `%s'\n", | ||||
| @@ -227,7 +227,7 @@ xbps_transaction_update_packages(void) | ||||
| 	bool newpkg_found = false; | ||||
| 	int rv; | ||||
|  | ||||
| 	rv = xbps_regpkgdb_foreach_pkg_cb(update_pkgs_cb, &newpkg_found); | ||||
| 	rv = xbps_pkgdb_foreach_pkg_cb(update_pkgs_cb, &newpkg_found); | ||||
| 	if (!newpkg_found) | ||||
| 		rv = EEXIST; | ||||
|  | ||||
| @@ -258,7 +258,7 @@ xbps_transaction_remove_pkg(const char *pkgname, bool recursive) | ||||
|  | ||||
| 	assert(pkgname != NULL); | ||||
|  | ||||
| 	if ((pkgd = xbps_regpkgdb_get_pkgd(pkgname, false)) == NULL) { | ||||
| 	if ((pkgd = xbps_pkgdb_get_pkgd(pkgname, false)) == NULL) { | ||||
| 		/* pkg not installed */ | ||||
| 		return ENOENT; | ||||
| 	} | ||||
|   | ||||
		Reference in New Issue
	
	Block a user