Ejemplo n.º 1
0
static xbps_array_t
merge_filelist(xbps_dictionary_t d)
{
	xbps_array_t a, result;
	xbps_dictionary_t filed;
	unsigned int i;

	result = xbps_array_create();
	assert(result);

	if ((a = xbps_dictionary_get(d, "files"))) {
		for (i = 0; i < xbps_array_count(a); i++) {
			filed = xbps_array_get(a, i);
			xbps_array_add(result, filed);
		}
	}
	if ((a = xbps_dictionary_get(d, "links"))) {
		for (i = 0; i < xbps_array_count(a); i++) {
			filed = xbps_array_get(a, i);
			xbps_array_add(result, filed);
		}
	}
	if ((a = xbps_dictionary_get(d, "conf_files"))) {
		for (i = 0; i < xbps_array_count(a); i++) {
			filed = xbps_array_get(a, i);
			xbps_array_add(result, filed);
		}
	}
	if ((a = xbps_dictionary_get(d, "dirs"))) {
		for (i = 0; i < xbps_array_count(a); i++) {
			filed = xbps_array_get(a, i);
			xbps_array_add(result, filed);
		}
	}

	return result;
}
Ejemplo n.º 2
0
int HIDDEN
xbps_transaction_package_replace(struct xbps_handle *xhp)
{
	xbps_array_t replaces, unsorted;
	xbps_dictionary_t instd, reppkgd, filesd;
	xbps_object_t obj, obj2;
	xbps_object_iterator_t iter;
	const char *pattern, *pkgver, *curpkgver;
	char *buf, *pkgname, *curpkgname;
	bool instd_auto, sr;
	unsigned int i;

	unsorted = xbps_dictionary_get(xhp->transd, "unsorted_deps");

	for (i = 0; i < xbps_array_count(unsorted); i++) {
		obj = xbps_array_get(unsorted, i);
		replaces = xbps_dictionary_get(obj, "replaces");
		if (replaces == NULL || xbps_array_count(replaces) == 0)
			continue;

		iter = xbps_array_iterator(replaces);
		assert(iter);

		while ((obj2 = xbps_object_iterator_next(iter)) != NULL) {
			pattern = xbps_string_cstring_nocopy(obj2);
			/*
			 * Find the installed package that matches the pattern
			 * to be replaced.
			 */
			if (((instd = xbps_pkgdb_get_pkg(xhp, pattern)) == NULL) &&
			    ((instd = xbps_pkgdb_get_virtualpkg(xhp, pattern)) == NULL))
				continue;

			xbps_dictionary_get_cstring_nocopy(obj,
			    "pkgver", &pkgver);
			xbps_dictionary_get_cstring_nocopy(instd,
			    "pkgver", &curpkgver);
			pkgname = xbps_pkg_name(pkgver);
			assert(pkgname);
			curpkgname = xbps_pkg_name(curpkgver);
			assert(curpkgver);
			/*
			 * Check that we are not replacing the same package,
			 * due to virtual packages.
			 */
			if (strcmp(pkgname, curpkgname) == 0) {
				free(pkgname);
				free(curpkgname);
				continue;
			}

			xbps_dbg_printf(xhp,
			    "Package `%s' will be replaced by `%s', "
			    "matched with `%s'\n", curpkgver, pkgver, pattern);
			instd_auto = false;
			xbps_dictionary_get_bool(instd,
			    "automatic-install", &instd_auto);
			/*
			 * Package contains replaces="pkgpattern", but the
			 * package that should be replaced is also in the
			 * transaction and it's going to be updated.
			 */
			if ((reppkgd = xbps_find_pkg_in_array(unsorted, curpkgname))) {
				xbps_dbg_printf(xhp,
				    "found replaced pkg "
				    "in transaction\n");
				xbps_dictionary_set_bool(instd,
				    "remove-and-update", true);
				xbps_dictionary_set_bool(reppkgd,
				    "automatic-install", instd_auto);
				xbps_dictionary_set_bool(reppkgd,
				    "skip-obsoletes", true);
				xbps_array_replace_dict_by_name(unsorted,
				   reppkgd, curpkgname);
			}
			/*
			 * If new package is providing a virtual package to the
			 * package that we want to replace we should respect
			 * the automatic-install object.
			 */
			if (xbps_match_virtual_pkg_in_dict(obj,
			    pattern, true) ||
			    xbps_match_virtual_pkg_in_dict(instd,
			    pkgname, false)) {
				xbps_dictionary_set_bool(obj,
				    "automatic-install", instd_auto);
			}
			sr = false;
			xbps_dictionary_get_bool(obj, "softreplace", &sr);
			if (sr) {
				xbps_dictionary_set_bool(obj,
				    "automatic-install", instd_auto);
				xbps_dictionary_set_bool(instd,
				    "softreplace", true);
				buf = xbps_xasprintf("%s/.%s.plist",
				    xhp->metadir, curpkgname);
				filesd = xbps_dictionary_internalize_from_file(buf);
				free(buf);
				assert(filesd != NULL);
				buf = xbps_xasprintf("%s/.%s.plist",
				    xhp->metadir, pkgname);
				if (!xbps_dictionary_externalize_to_file(filesd, buf)) {
					free(buf);
					xbps_object_release(filesd);
					xbps_object_iterator_release(iter);
					free(pkgname);
					free(curpkgname);
					return errno;
				}
				xbps_object_release(filesd);
				free(buf);
			}
			/*
			 * Add package dictionary into the transaction and mark
			 * it as to be "removed".
			 */
			xbps_dictionary_set_cstring_nocopy(instd,
			    "transaction", "remove");
			xbps_array_add(unsorted, instd);
			free(pkgname);
			free(curpkgname);
		}
		xbps_object_iterator_release(iter);
	}

	return 0;
}
Ejemplo n.º 3
0
int
xbps_transaction_prepare(struct xbps_handle *xhp)
{
	xbps_array_t array, pkgs, edges;
	unsigned int i, cnt;
	int rv = 0;

	if (xhp->transd == NULL)
		return ENXIO;

	/*
	 * Collect dependencies for pkgs in transaction.
	 */
	if ((edges = xbps_array_create()) == NULL)
		return ENOMEM;
	/*
	 * The edges are also appended after its dependencies have been
	 * collected; the edges at the original array are removed later.
	 */
	pkgs = xbps_dictionary_get(xhp->transd, "packages");
	assert(xbps_object_type(pkgs) == XBPS_TYPE_ARRAY);
	cnt = xbps_array_count(pkgs);
	for (i = 0; i < cnt; i++) {
		xbps_dictionary_t pkgd;
		xbps_string_t str;
		const char *tract = NULL;

		pkgd = xbps_array_get(pkgs, i);
		str = xbps_dictionary_get(pkgd, "pkgver");
		xbps_dictionary_get_cstring_nocopy(pkgd, "transaction", &tract);
		if ((strcmp(tract, "remove") == 0) || strcmp(tract, "hold") == 0)
			continue;

		assert(xbps_object_type(str) == XBPS_TYPE_STRING);

		if (!xbps_array_add(edges, str))
			return ENOMEM;

		if ((rv = xbps_repository_find_deps(xhp, pkgs, pkgd)) != 0)
			return rv;

		if (!xbps_array_add(pkgs, pkgd))
			return ENOMEM;
	}
	/* ... remove dup edges at head */
	for (i = 0; i < xbps_array_count(edges); i++) {
		const char *pkgver;
		xbps_array_get_cstring_nocopy(edges, i, &pkgver);
		xbps_remove_pkg_from_array_by_pkgver(pkgs, pkgver);
	}
	xbps_object_release(edges);

	/*
	 * Check for packages to be replaced.
	 */
	if ((rv = xbps_transaction_package_replace(xhp, pkgs)) != 0) {
		xbps_object_release(xhp->transd);
		xhp->transd = NULL;
		return rv;
	}
	/*
	 * If there are missing deps or revdeps bail out.
	 */
	xbps_transaction_revdeps(xhp, pkgs);
	array = xbps_dictionary_get(xhp->transd, "missing_deps");
	if (xbps_array_count(array)) {
		if (xhp->flags & XBPS_FLAG_FORCE_REMOVE_REVDEPS) {
			xbps_dbg_printf(xhp, "[trans] continuing with broken reverse dependencies!");
		} else {
			return ENODEV;
		}
	}
	/*
	 * If there are package conflicts bail out.
	 */
	xbps_transaction_conflicts(xhp, pkgs);
	array = xbps_dictionary_get(xhp->transd, "conflicts");
	if (xbps_array_count(array))
		return EAGAIN;
	/*
	 * Check for unresolved shared libraries.
	 */
	if (xbps_transaction_shlibs(xhp, pkgs,
	    xbps_dictionary_get(xhp->transd, "missing_shlibs"))) {
		if (xhp->flags & XBPS_FLAG_FORCE_REMOVE_REVDEPS) {
			xbps_dbg_printf(xhp, "[trans] continuing with unresolved shared libraries!");
		} else {
			return ENOEXEC;
		}
	}
	/*
	 * Add transaction stats for total download/installed size,
	 * number of packages to be installed, updated, configured
	 * and removed to the transaction dictionary.
	 */
	if ((rv = compute_transaction_stats(xhp)) != 0) {
		return rv;
	}
	/*
	 * Remove now unneeded objects.
	 */
	xbps_dictionary_remove(xhp->transd, "missing_shlibs");
	xbps_dictionary_remove(xhp->transd, "missing_deps");
	xbps_dictionary_remove(xhp->transd, "conflicts");
	xbps_dictionary_make_immutable(xhp->transd);

	return 0;
}