Added support for dynamic generation of revdeps for installed packages.

This commit is contained in:
Juan RP
2012-11-30 17:40:52 +01:00
parent 9ac3b60048
commit f45352dbf8
18 changed files with 165 additions and 479 deletions

View File

@@ -43,8 +43,7 @@ EXTOBJS += external/mkpath.o
# libxbps
OBJS = package_configure.o package_config_files.o package_orphans.o
OBJS += package_remove.o package_remove_obsoletes.o package_state.o
OBJS += package_unpack.o package_requiredby.o package_register.o
OBJS += package_script.o
OBJS += package_unpack.o package_register.o package_script.o
OBJS += transaction_commit.o transaction_package_replace.o
OBJS += transaction_dictionary.o transaction_sortdeps.o transaction_ops.o
OBJS += download.o initend.o pkgdb.o package_conflicts.o

View File

@@ -74,7 +74,7 @@ find_orphan_pkg(struct xbps_handle *xhp,
prop_array_t reqby;
prop_object_t obj2;
prop_object_iterator_t iter;
const char *pkgdep, *curpkgname;
const char *pkgdep, *curpkgname, *curpkgver;
char *pkgdepname;
unsigned int ndep = 0, cnt = 0;
bool automatic = false;
@@ -89,7 +89,8 @@ find_orphan_pkg(struct xbps_handle *xhp,
if (!automatic)
return 0;
reqby = prop_dictionary_get(obj, "requiredby");
prop_dictionary_get_cstring_nocopy(obj, "pkgver", &curpkgver);
reqby = xbps_pkgdb_get_pkg_revdeps(xhp, curpkgver);
if (reqby == NULL || ((cnt = prop_array_count(reqby)) == 0)) {
/*
* Add packages with empty or missing "requiredby" arrays.

View File

@@ -44,7 +44,7 @@ int
xbps_register_pkg(struct xbps_handle *xhp, prop_dictionary_t pkgrd, bool flush)
{
prop_dictionary_t pkgd;
prop_array_t provides, reqby;
prop_array_t provides, rundeps;
char outstr[64];
time_t t;
struct tm *tmp;
@@ -61,7 +61,7 @@ xbps_register_pkg(struct xbps_handle *xhp, prop_dictionary_t pkgrd, bool flush)
prop_dictionary_get_cstring_nocopy(pkgrd, "pkgver", &pkgver);
prop_dictionary_get_bool(pkgrd, "automatic-install", &autoinst);
provides = prop_dictionary_get(pkgrd, "provides");
reqby = prop_dictionary_get(pkgrd, "requiredby");
rundeps = prop_dictionary_get(pkgrd, "run_depends");
xbps_set_cb_state(xhp, XBPS_STATE_REGISTER, 0, pkgname, version, NULL);
@@ -96,12 +96,6 @@ xbps_register_pkg(struct xbps_handle *xhp, prop_dictionary_t pkgrd, bool flush)
rv = EINVAL;
goto out;
}
if (reqby && !prop_dictionary_set(pkgd, "requiredby", reqby)) {
xbps_dbg_printf(xhp, "%s: invalid requiredby for %s\n",
__func__, pkgname);
rv = EINVAL;
goto out;
}
prop_dictionary_get_bool(pkgd, "automatic-install", &autoinst);
if (xhp->flags & XBPS_FLAG_INSTALL_AUTO)
autoinst = true;
@@ -137,26 +131,22 @@ xbps_register_pkg(struct xbps_handle *xhp, prop_dictionary_t pkgrd, bool flush)
goto out;
}
if (provides) {
if (!prop_dictionary_set(pkgd, "provides", provides)) {
xbps_dbg_printf(xhp,
"%s: invalid provides for %s\n",
__func__, pkgname);
rv = EINVAL;
goto out;
}
if (provides && !prop_dictionary_set(pkgd, "provides", provides)) {
xbps_dbg_printf(xhp, "%s: failed to set provides for %s\n",
__func__, pkgname);
rv = EINVAL;
goto out;
}
/*
* Add the requiredby objects for dependent packages.
*/
if (pkgrd && xbps_pkg_has_rundeps(pkgrd)) {
if ((rv = xbps_requiredby_pkg_add(xhp, pkgrd)) != 0) {
xbps_dbg_printf(xhp,
"%s: requiredby add failed for %s\n",
__func__, pkgname);
goto out;
}
if (rundeps == NULL)
rundeps = prop_array_create();
if (!prop_dictionary_set(pkgd, "run_depends", rundeps)) {
xbps_dbg_printf(xhp, "%s: failed to set rundeps for %s\n",
__func__, pkgname);
rv = EINVAL;
goto out;
}
/*
* Create a hash for the pkg's metafile.
*/

View File

@@ -47,8 +47,6 @@
* XBPS_FLAG_FORCE_REMOVE_FILES flag is set via xbps_init::flags member.
* -# Its <b>post-remove</b> target specified in the REMOVE script
* will be executed.
* -# Its requiredby objects will be removed from the installed packages
* database.
* -# Its state will be changed to XBPS_PKG_STATE_HALF_REMOVED.
* -# Its <b>purge-remove</b> target specified in the REMOVE script
* will be executed.
@@ -274,14 +272,14 @@ xbps_remove_pkg(struct xbps_handle *xhp,
}
/*
* If updating a package, we just need to execute the current
* pre-remove action target, unregister its requiredby entries and
* continue. Its files will be overwritten later in unpack phase.
* pre-remove action target and we are done. Its files will be
* overwritten later in unpack phase.
*/
if (update) {
if (pkgd)
prop_object_release(pkgd);
free(pkgname);
return xbps_requiredby_pkg_remove(xhp, pkgname);
return 0;
} else if (soft_replace) {
/*
* Soft replace a package. Do not remove its files, but
@@ -317,16 +315,6 @@ xbps_remove_pkg(struct xbps_handle *xhp,
goto out;
}
}
/*
* Update the requiredby array of all required dependencies.
*/
if ((rv = xbps_requiredby_pkg_remove(xhp, pkgname)) != 0) {
xbps_set_cb_state(xhp, XBPS_STATE_REMOVE_FAIL,
rv, pkgname, version,
"%s: [remove] failed to remove requiredby entries: %s",
pkgver, strerror(rv));
goto out;
}
softreplace:
/*

View File

@@ -1,177 +0,0 @@
/*-
* Copyright (c) 2009-2012 Juan Romero Pardines.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <stdio.h>
#include <stdbool.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include "xbps_api_impl.h"
static int
add_pkg_into_reqby(struct xbps_handle *xhp,
prop_dictionary_t pkgd,
const char *pkgver)
{
prop_array_t reqby;
prop_string_t reqstr;
const char *curpkgver;
char *pkgname;
bool alloc = false;
assert(prop_object_type(pkgd) == PROP_TYPE_DICTIONARY);
if ((reqby = prop_dictionary_get(pkgd, "requiredby")) == NULL) {
alloc = true;
if ((reqby = prop_array_create()) == NULL)
return ENOMEM;
}
/*
* If the same entry already exist we are done.
*/
if (xbps_match_string_in_array(reqby, pkgver))
return 0;
/*
* If an existing entry matching pkgname exists remove it
* and add new pkgver object.
*/
pkgname = xbps_pkg_name(pkgver);
if (pkgname == NULL)
return ENOMEM;
if (xbps_match_pkgname_in_array(reqby, pkgname)) {
if (!xbps_remove_pkgname_from_array(reqby, pkgname)) {
xbps_dbg_printf(xhp, "%s: failed to remove %s reqby entry: "
"%s\n", __func__, pkgname, strerror(errno));
free(pkgname);
return EINVAL;
}
}
free(pkgname);
reqstr = prop_string_create_cstring(pkgver);
if (reqstr == NULL) {
if (alloc)
prop_object_release(reqby);
return ENOMEM;
}
prop_dictionary_get_cstring_nocopy(pkgd, "pkgver", &curpkgver);
xbps_dbg_printf(xhp, "%s: added reqby entry `%s'\n", curpkgver, pkgver);
if (!xbps_add_obj_to_array(reqby, reqstr)) {
if (alloc)
prop_object_release(reqby);
prop_object_release(reqstr);
return EINVAL;
}
if (!alloc)
return 0;
if (!xbps_add_obj_to_dict(pkgd, reqby, "requiredby")) {
if (alloc)
prop_object_release(reqby);
return EINVAL;
}
return 0;
}
static int
remove_pkg_from_reqby(struct xbps_handle *xhp,
prop_object_t obj,
void *arg,
bool *loop_done)
{
prop_array_t reqby;
const char *pkgname = arg;
(void)xhp;
(void)loop_done;
reqby = prop_dictionary_get(obj, "requiredby");
if (reqby == NULL || prop_array_count(reqby) == 0)
return 0;
if (xbps_match_pkgname_in_array(reqby, pkgname))
if (!xbps_remove_pkgname_from_array(reqby, pkgname))
return EINVAL;
return 0;
}
int HIDDEN
xbps_requiredby_pkg_remove(struct xbps_handle *xhp, const char *pkgname)
{
assert(pkgname != NULL);
return xbps_pkgdb_foreach_cb(xhp, 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, pkgdbd;
prop_object_iterator_t iter;
const char *pkgver, *str;
int rv = 0;
assert(prop_object_type(pkgd) == PROP_TYPE_DICTIONARY);
prop_dictionary_get_cstring_nocopy(pkgd, "pkgver", &pkgver);
pkg_rdeps = prop_dictionary_get(pkgd, "run_depends");
if (pkg_rdeps == NULL || prop_array_count(pkg_rdeps) == 0)
return EINVAL;
iter = prop_array_iterator(pkg_rdeps);
if (iter == NULL)
return ENOMEM;
while ((obj = prop_object_iterator_next(iter)) != NULL) {
str = prop_string_cstring_nocopy(obj);
if (str == NULL) {
rv = EINVAL;
break;
}
if (((pkgdbd = xbps_find_pkg_in_array(xhp->pkgdb, str)) == NULL) &&
((pkgdbd = xbps_find_virtualpkg_in_array(xhp, xhp->pkgdb, str)) == NULL)) {
rv = ENOENT;
xbps_dbg_printf(xhp, "%s: couldnt find `%s' "
"entry in pkgdb\n", __func__, str);
break;
}
rv = add_pkg_into_reqby(xhp, pkgdbd, pkgver);
if (rv != 0)
break;
}
prop_object_iterator_release(iter);
return rv;
}

View File

@@ -186,17 +186,13 @@ xbps_pkgdb_get_virtualpkg(struct xbps_handle *xhp, const char *vpkg)
return xbps_find_virtualpkg_in_array(xhp, xhp->pkgdb, vpkg);
}
prop_dictionary_t
xbps_pkgdb_get_pkg_metadata(struct xbps_handle *xhp, const char *pkg)
static prop_dictionary_t
get_pkg_metadata(struct xbps_handle *xhp, prop_dictionary_t pkgd)
{
prop_dictionary_t pkgd, pkg_metad;
prop_dictionary_t pkg_metad;
const char *pkgname;
char *plist;
pkgd = xbps_pkgdb_get_pkg(xhp, pkg);
if (pkgd == NULL)
return NULL;
prop_dictionary_get_cstring_nocopy(pkgd, "pkgname", &pkgname);
if ((pkg_metad = prop_dictionary_get(xhp->pkg_metad, pkgname)) != NULL)
@@ -221,6 +217,70 @@ xbps_pkgdb_get_pkg_metadata(struct xbps_handle *xhp, const char *pkg)
return pkg_metad;
}
prop_array_t
xbps_pkgdb_get_pkg_revdeps(struct xbps_handle *xhp, const char *pkg)
{
prop_array_t rundeps, provides, result = NULL;
prop_dictionary_t pkgd, pkgdep_metad;
prop_object_t obj;
prop_object_iterator_t iter;
const char *pkgver, *curpkgver;
if (xbps_pkgdb_init(xhp) != 0)
return NULL;
pkgd = xbps_find_pkg_in_array(xhp->pkgdb, pkg);
if (pkgd == NULL)
return NULL;
prop_dictionary_get_cstring_nocopy(pkgd, "pkgver", &pkgver);
provides = prop_dictionary_get(pkgd, "provides");
iter = prop_array_iterator(xhp->pkgdb);
assert(iter);
while ((obj = prop_object_iterator_next(iter))) {
prop_dictionary_get_cstring_nocopy(obj, "pkgver", &curpkgver);
/*
* If run_depends is in pkgdb use it, otherwise fallback to
* the slower pkg metadata method.
*/
rundeps = prop_dictionary_get(obj, "run_depends");
if (rundeps == NULL) {
pkgdep_metad = get_pkg_metadata(xhp, obj);
assert(pkgdep_metad);
rundeps = prop_dictionary_get(pkgdep_metad,
"run_depends");
}
if (rundeps == NULL || !prop_array_count(rundeps))
continue;
if (xbps_match_pkgdep_in_array(rundeps, pkgver) ||
(provides &&
xbps_match_any_virtualpkg_in_rundeps(rundeps, provides))) {
if (result == NULL)
result = prop_array_create();
prop_array_add_cstring_nocopy(result, curpkgver);
}
}
prop_object_iterator_release(iter);
return result;
}
prop_dictionary_t
xbps_pkgdb_get_pkg_metadata(struct xbps_handle *xhp, const char *pkg)
{
prop_dictionary_t pkgd;
pkgd = xbps_pkgdb_get_pkg(xhp, pkg);
if (pkgd == NULL)
return NULL;
return get_pkg_metadata(xhp, pkgd);
}
bool
xbps_pkgdb_remove_pkg(struct xbps_handle *xhp, const char *pkg, bool flush)
{

View File

@@ -304,7 +304,7 @@ rmpkg:
prop_dictionary_set_cstring_nocopy(pkgd, "transaction", "remove");
prop_array_add(unsorted, pkgd);
xbps_dbg_printf(xhp, "%s: added into transaction (remove).\n", pkgver);
reqby = prop_dictionary_get(pkgd, "requiredby");
reqby = xbps_pkgdb_get_pkg_revdeps(xhp, pkgver);
/*
* If target pkg is required by any installed pkg, the client must be aware
* of this to take appropiate action.

View File

@@ -36,7 +36,7 @@
int HIDDEN
xbps_transaction_package_replace(struct xbps_handle *xhp)
{
prop_array_t replaces, instd_reqby, unsorted;
prop_array_t replaces, unsorted;
prop_dictionary_t instd, reppkgd, filesd;
prop_object_t obj, obj2;
prop_object_iterator_t iter;
@@ -84,7 +84,6 @@ xbps_transaction_package_replace(struct xbps_handle *xhp)
xbps_dbg_printf(xhp,
"Package `%s' will be replaced by `%s', "
"matched with `%s'\n", curpkgver, pkgver, pattern);
instd_reqby = prop_dictionary_get(instd, "requiredby");
instd_auto = false;
prop_dictionary_get_bool(instd,
"automatic-install", &instd_auto);
@@ -100,11 +99,6 @@ xbps_transaction_package_replace(struct xbps_handle *xhp)
"in transaction\n");
prop_dictionary_set_bool(instd,
"remove-and-update", true);
if (instd_reqby &&
prop_array_count(instd_reqby)) {
prop_dictionary_set(reppkgd,
"requiredby", instd_reqby);
}
prop_dictionary_set_bool(reppkgd,
"automatic-install", instd_auto);
prop_dictionary_set_bool(reppkgd,
@@ -115,36 +109,18 @@ xbps_transaction_package_replace(struct xbps_handle *xhp)
/*
* If new package is providing a virtual package to the
* package that we want to replace we should respect
* its requiredby and automatic-install objects, so copy
* them to the pkg's dictionary in transaction.
* the automatic-install object.
*/
if (xbps_match_virtual_pkg_in_dict(obj,
pattern, true) ||
xbps_match_virtual_pkg_in_dict(instd,
pkgname, false)) {
if (instd_reqby &&
prop_array_count(instd_reqby)) {
prop_dictionary_set(obj,
"requiredby", instd_reqby);
}
prop_dictionary_set_bool(obj,
"automatic-install", instd_auto);
}
/*
* Copy requiredby and automatic-install objects
* from replaced package into pkg's dictionary
* for "softreplace" packages. Also externalize
* PKGFILES from package being replaced to remove
* obsolete files.
*/
sr = false;
prop_dictionary_get_bool(obj, "softreplace", &sr);
if (sr) {
if (instd_reqby &&
prop_array_count(instd_reqby)) {
prop_dictionary_set(obj,
"requiredby", instd_reqby);
}
prop_dictionary_set_bool(obj,
"automatic-install", instd_auto);
prop_dictionary_set_bool(instd,