Added support to keep track of reverse depends on installed packages.
--HG-- extra : convert_revision : 9e3e46f726ef28843dc52b95ce818637c2a18de5
This commit is contained in:
parent
e32d15605b
commit
939a63036e
6 changed files with 189 additions and 26 deletions
|
@ -1,5 +1,5 @@
|
||||||
/*-
|
/*-
|
||||||
* Copyright (c) 2008 Juan Romero Pardines.
|
* Copyright (c) 2008-2009 Juan Romero Pardines.
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
@ -113,7 +113,7 @@ main(int argc, char **argv)
|
||||||
if (argc != 4)
|
if (argc != 4)
|
||||||
usage();
|
usage();
|
||||||
|
|
||||||
rv = xbps_register_pkg(argv[1], argv[2], argv[3]);
|
rv = xbps_register_pkg(NULL, argv[1], argv[2], argv[3]);
|
||||||
if (rv == EEXIST) {
|
if (rv == EEXIST) {
|
||||||
printf("%s=> %s-%s already registered.\n",
|
printf("%s=> %s-%s already registered.\n",
|
||||||
in_chroot ? "[chroot] " : "", argv[1], argv[2]);
|
in_chroot ? "[chroot] " : "", argv[1], argv[2]);
|
||||||
|
|
|
@ -31,10 +31,12 @@ int xbps_install_pkg_deps(prop_dictionary_t, const char *);
|
||||||
int xbps_install_binary_pkg(const char *, const char *);
|
int xbps_install_binary_pkg(const char *, const char *);
|
||||||
int xbps_install_binary_pkg_fini(prop_dictionary_t, prop_dictionary_t,
|
int xbps_install_binary_pkg_fini(prop_dictionary_t, prop_dictionary_t,
|
||||||
const char *);
|
const char *);
|
||||||
int xbps_register_pkg(const char *, const char *, const char *);
|
int xbps_register_pkg(prop_dictionary_t, const char *, const char *,
|
||||||
|
const char *);
|
||||||
int xbps_unpack_binary_pkg(prop_dictionary_t, prop_dictionary_t,
|
int xbps_unpack_binary_pkg(prop_dictionary_t, prop_dictionary_t,
|
||||||
const char *,
|
const char *,
|
||||||
void (*cb_print)(prop_dictionary_t));
|
void (*cb_print)(prop_dictionary_t));
|
||||||
|
int xbps_update_pkg_requiredby(prop_array_t, prop_dictionary_t);
|
||||||
int xbps_find_deps_in_pkg(prop_dictionary_t, prop_dictionary_t);
|
int xbps_find_deps_in_pkg(prop_dictionary_t, prop_dictionary_t);
|
||||||
|
|
||||||
#endif /* !_XBPS_INSTALL_H_ */
|
#endif /* !_XBPS_INSTALL_H_ */
|
||||||
|
|
|
@ -8,8 +8,9 @@ LIBXBPS_SO = $(LIBXBPS).$(MAJOR).$(MINOR).$(MICRO)
|
||||||
LIBXBPS = libxbps.so
|
LIBXBPS = libxbps.so
|
||||||
LIBXBPS_LDFLAGS = -larchive -lprop -shared -Wl,-soname,$(LIBXBPS).$(MAJOR)
|
LIBXBPS_LDFLAGS = -larchive -lprop -shared -Wl,-soname,$(LIBXBPS).$(MAJOR)
|
||||||
|
|
||||||
OBJECTS = cmpver.o depends.o humanize_number.o install.o plist.o
|
OBJECTS = cmpver.o depends.o fexec.o humanize_number.o install.o
|
||||||
OBJECTS += sha256.o util.o repository.o fexec.o remove.o unpack.o
|
OBJECTS += plist.o remove.o repository.o requiredby.o sha256.o
|
||||||
|
OBJECTS += unpack.o util.o
|
||||||
|
|
||||||
all: $(LIBXBPS)
|
all: $(LIBXBPS)
|
||||||
.PHONY: all
|
.PHONY: all
|
||||||
|
|
|
@ -112,7 +112,7 @@ store_dependency(prop_dictionary_t origind, prop_dictionary_t depd,
|
||||||
prop_dictionary_t repod)
|
prop_dictionary_t repod)
|
||||||
{
|
{
|
||||||
prop_dictionary_t dict, curpkgdir, curpkgindir;
|
prop_dictionary_t dict, curpkgdir, curpkgindir;
|
||||||
prop_array_t array;
|
prop_array_t array, rundeps_array;
|
||||||
uint32_t prio = 0;
|
uint32_t prio = 0;
|
||||||
size_t len = 0;
|
size_t len = 0;
|
||||||
const char *pkgname, *version, *reqbyname, *reqbyver;
|
const char *pkgname, *version, *reqbyname, *reqbyver;
|
||||||
|
@ -216,6 +216,9 @@ store_dependency(prop_dictionary_t origind, prop_dictionary_t depd,
|
||||||
prop_dictionary_set_cstring(dict, "pkgname", pkgname);
|
prop_dictionary_set_cstring(dict, "pkgname", pkgname);
|
||||||
prop_dictionary_set_cstring(dict, "version", version);
|
prop_dictionary_set_cstring(dict, "version", version);
|
||||||
prop_dictionary_set_cstring(dict, "requiredby", reqby);
|
prop_dictionary_set_cstring(dict, "requiredby", reqby);
|
||||||
|
rundeps_array = prop_dictionary_get(depd, "run_depends");
|
||||||
|
if (rundeps_array && prop_array_count(rundeps_array) > 0)
|
||||||
|
prop_dictionary_set(dict, "run_depends", rundeps_array);
|
||||||
|
|
||||||
if ((strcmp(array_key, "direct_deps") == 0) ||
|
if ((strcmp(array_key, "direct_deps") == 0) ||
|
||||||
(strcmp(array_key, "indirect_deps") == 0)) {
|
(strcmp(array_key, "indirect_deps") == 0)) {
|
||||||
|
|
|
@ -51,7 +51,7 @@ xbps_install_binary_pkg_fini(prop_dictionary_t repo, prop_dictionary_t pkg,
|
||||||
|
|
||||||
rv = xbps_unpack_binary_pkg(repo, pkg, destdir, NULL);
|
rv = xbps_unpack_binary_pkg(repo, pkg, destdir, NULL);
|
||||||
if (rv == 0) {
|
if (rv == 0) {
|
||||||
rv = xbps_register_pkg(pkgname, version, desc);
|
rv = xbps_register_pkg(pkg, pkgname, version, desc);
|
||||||
if (rv == EEXIST)
|
if (rv == EEXIST)
|
||||||
rv = 0;
|
rv = 0;
|
||||||
}
|
}
|
||||||
|
@ -189,7 +189,8 @@ make_dict_from_pkg(const char *name, const char *ver, const char *desc)
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
xbps_register_pkg(const char *pkgname, const char *version, const char *desc)
|
xbps_register_pkg(prop_dictionary_t pkgrd, const char *pkgname,
|
||||||
|
const char *version, const char *desc)
|
||||||
{
|
{
|
||||||
prop_dictionary_t dict, pkgd;
|
prop_dictionary_t dict, pkgd;
|
||||||
prop_array_t array;
|
prop_array_t array;
|
||||||
|
@ -215,52 +216,58 @@ xbps_register_pkg(const char *pkgname, const char *version, const char *desc)
|
||||||
|
|
||||||
array = prop_array_create();
|
array = prop_array_create();
|
||||||
if (array == NULL) {
|
if (array == NULL) {
|
||||||
free(plist);
|
rv = ENOMEM;
|
||||||
prop_object_release(dict);
|
goto out;
|
||||||
return ENOMEM;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pkgd = make_dict_from_pkg(pkgname, version, desc);
|
pkgd = make_dict_from_pkg(pkgname, version, desc);
|
||||||
|
|
||||||
if (!xbps_add_obj_to_array(array, pkgd)) {
|
if (!xbps_add_obj_to_array(array, pkgd)) {
|
||||||
prop_object_release(array);
|
prop_object_release(array);
|
||||||
prop_object_release(dict);
|
rv = EINVAL;
|
||||||
prop_object_release(pkgd);
|
goto out;
|
||||||
free(plist);
|
|
||||||
return EINVAL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!xbps_add_obj_to_dict(dict, array, "packages")) {
|
if (!xbps_add_obj_to_dict(dict, array, "packages")) {
|
||||||
prop_object_release(array);
|
prop_object_release(array);
|
||||||
prop_object_release(dict);
|
rv = EINVAL;
|
||||||
free(plist);
|
goto out;
|
||||||
return EINVAL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
/* Check if package is already registered. */
|
/* Check if package is already registered. */
|
||||||
pkgd = xbps_find_pkg_in_dict(dict, "packages", pkgname);
|
pkgd = xbps_find_pkg_in_dict(dict, "packages", pkgname);
|
||||||
if (pkgd != NULL) {
|
if (pkgd != NULL) {
|
||||||
prop_object_release(dict);
|
rv = EEXIST;
|
||||||
free(plist);
|
goto out;
|
||||||
return EEXIST;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pkgd = make_dict_from_pkg(pkgname, version, desc);
|
pkgd = make_dict_from_pkg(pkgname, version, desc);
|
||||||
array = prop_dictionary_get(dict, "packages");
|
array = prop_dictionary_get(dict, "packages");
|
||||||
assert(array != NULL);
|
if (array == NULL) {
|
||||||
|
prop_object_release(pkgd);
|
||||||
|
rv = ENOENT;
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (xbps_pkg_has_rundeps(pkgrd)) {
|
||||||
|
rv = xbps_update_pkg_requiredby(array, pkgrd);
|
||||||
|
if (rv != 0) {
|
||||||
|
prop_object_release(pkgd);
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!xbps_add_obj_to_array(array, pkgd)) {
|
if (!xbps_add_obj_to_array(array, pkgd)) {
|
||||||
prop_object_release(pkgd);
|
prop_object_release(pkgd);
|
||||||
prop_object_release(dict);
|
rv = EINVAL;
|
||||||
free(plist);
|
goto out;
|
||||||
return EINVAL;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!prop_dictionary_externalize_to_file(dict, plist))
|
if (!prop_dictionary_externalize_to_file(dict, plist))
|
||||||
rv = errno;
|
rv = errno;
|
||||||
|
|
||||||
|
out:
|
||||||
prop_object_release(dict);
|
prop_object_release(dict);
|
||||||
free(plist);
|
free(plist);
|
||||||
|
|
||||||
|
|
150
lib/requiredby.c
Normal file
150
lib/requiredby.c
Normal file
|
@ -0,0 +1,150 @@
|
||||||
|
/*-
|
||||||
|
* Copyright (c) 2009 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 <limits.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
|
||||||
|
#include <xbps_api.h>
|
||||||
|
|
||||||
|
static int
|
||||||
|
add_pkg_into_requiredby(prop_dictionary_t pkgd, const char *reqname)
|
||||||
|
{
|
||||||
|
prop_array_t array;
|
||||||
|
prop_string_t reqstr;
|
||||||
|
bool alloc = false;
|
||||||
|
|
||||||
|
array = prop_dictionary_get(pkgd, "requiredby");
|
||||||
|
if (array == NULL) {
|
||||||
|
alloc = true;
|
||||||
|
array = prop_array_create();
|
||||||
|
if (array == NULL)
|
||||||
|
return ENOMEM;
|
||||||
|
}
|
||||||
|
|
||||||
|
reqstr = prop_string_create_cstring(reqname);
|
||||||
|
if (reqstr == NULL) {
|
||||||
|
if (alloc)
|
||||||
|
prop_object_release(array);
|
||||||
|
return errno;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!xbps_add_obj_to_array(array, reqstr)) {
|
||||||
|
if (alloc)
|
||||||
|
prop_object_release(array);
|
||||||
|
|
||||||
|
prop_object_release(reqstr);
|
||||||
|
return EINVAL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!alloc)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
if (!xbps_add_obj_to_dict(pkgd, array, "requiredby")) {
|
||||||
|
if (alloc)
|
||||||
|
prop_object_release(array);
|
||||||
|
|
||||||
|
return EINVAL;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
xbps_update_pkg_requiredby(prop_array_t regar, prop_dictionary_t pkg)
|
||||||
|
{
|
||||||
|
prop_array_t rdeps;
|
||||||
|
prop_object_t obj, obj2;
|
||||||
|
prop_object_iterator_t iter, iter2;
|
||||||
|
size_t len = 0;
|
||||||
|
const char *reqname, *pkgname, *version;
|
||||||
|
char *rdepname, *fpkgn;
|
||||||
|
int rv = 0;
|
||||||
|
|
||||||
|
prop_dictionary_get_cstring_nocopy(pkg, "pkgname", &pkgname);
|
||||||
|
prop_dictionary_get_cstring_nocopy(pkg, "version", &version);
|
||||||
|
len = strlen(pkgname) + strlen(version) + 2;
|
||||||
|
fpkgn = malloc(len);
|
||||||
|
if (fpkgn == NULL)
|
||||||
|
return ENOMEM;
|
||||||
|
|
||||||
|
(void)snprintf(fpkgn, len, "%s-%s", pkgname, version);
|
||||||
|
|
||||||
|
rdeps = prop_dictionary_get(pkg, "run_depends");
|
||||||
|
if (rdeps == NULL || prop_array_count(rdeps) == 0) {
|
||||||
|
free(fpkgn);
|
||||||
|
return EINVAL;
|
||||||
|
}
|
||||||
|
|
||||||
|
iter = prop_array_iterator(rdeps);
|
||||||
|
if (iter == NULL) {
|
||||||
|
free(fpkgn);
|
||||||
|
return ENOMEM;
|
||||||
|
}
|
||||||
|
|
||||||
|
while ((obj = prop_object_iterator_next(iter)) != NULL) {
|
||||||
|
rdepname = xbps_get_pkg_name(prop_string_cstring_nocopy(obj));
|
||||||
|
|
||||||
|
iter2 = prop_array_iterator(regar);
|
||||||
|
if (iter2 == NULL) {
|
||||||
|
free(fpkgn);
|
||||||
|
free(rdepname);
|
||||||
|
prop_object_iterator_release(iter);
|
||||||
|
return ENOMEM;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Iterate over the array to find the dictionary for the
|
||||||
|
* current run dependency.
|
||||||
|
*/
|
||||||
|
while ((obj2 = prop_object_iterator_next(iter2)) != NULL) {
|
||||||
|
prop_dictionary_get_cstring_nocopy(obj2, "pkgname",
|
||||||
|
&reqname);
|
||||||
|
if (strcmp(rdepname, reqname) == 0) {
|
||||||
|
rv = add_pkg_into_requiredby(obj2, fpkgn);
|
||||||
|
if (rv != 0) {
|
||||||
|
free(fpkgn);
|
||||||
|
free(rdepname);
|
||||||
|
prop_object_iterator_release(iter2);
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
free(rdepname);
|
||||||
|
prop_object_iterator_release(iter2);
|
||||||
|
}
|
||||||
|
|
||||||
|
out:
|
||||||
|
free(fpkgn);
|
||||||
|
prop_object_iterator_release(iter);
|
||||||
|
|
||||||
|
return rv;
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue