Added support for dynamic generation of revdeps for installed packages.
This commit is contained in:
@@ -3,7 +3,7 @@ TOPDIR = ../..
|
||||
|
||||
BIN = xbps-pkgdb
|
||||
OBJS = main.o check.o check_pkg_files.o
|
||||
OBJS += check_pkg_requiredby.o check_pkg_rundeps.o
|
||||
OBJS += check_pkg_rundeps.o
|
||||
OBJS += check_pkg_symlinks.o check_pkg_unneeded.o
|
||||
OBJS += convert.o
|
||||
|
||||
|
||||
@@ -91,6 +91,7 @@ check_pkg_integrity(struct xbps_handle *xhp,
|
||||
prop_dictionary_t pkgd,
|
||||
const char *pkgname)
|
||||
{
|
||||
prop_array_t rundeps;
|
||||
prop_dictionary_t opkgd, propsd;
|
||||
const char *sha256;
|
||||
char *buf;
|
||||
@@ -100,13 +101,9 @@ check_pkg_integrity(struct xbps_handle *xhp,
|
||||
|
||||
/* find real pkg by name */
|
||||
opkgd = pkgd;
|
||||
if (pkgd == NULL) {
|
||||
opkgd = xbps_pkgdb_get_pkg(xhp, pkgname);
|
||||
if (opkgd == NULL) {
|
||||
/* find virtual pkg by name */
|
||||
opkgd = xbps_pkgdb_get_virtualpkg(xhp, pkgname);
|
||||
}
|
||||
if (opkgd == NULL) {
|
||||
if (opkgd == NULL) {
|
||||
if (((opkgd = xbps_pkgdb_get_pkg(xhp, pkgname)) == NULL) &&
|
||||
((opkgd = xbps_pkgdb_get_virtualpkg(xhp, pkgname)) == NULL)) {
|
||||
printf("Package %s is not installed.\n", pkgname);
|
||||
return 0;
|
||||
}
|
||||
@@ -127,7 +124,24 @@ check_pkg_integrity(struct xbps_handle *xhp,
|
||||
xbps_error_printf("%s: incomplete metadata file.\n", pkgname);
|
||||
return 1;
|
||||
}
|
||||
/*
|
||||
* Check if pkgdb pkg has been converted to 0.19 format,
|
||||
* which adds "run_depends" array object.
|
||||
*/
|
||||
rundeps = prop_dictionary_get(opkgd, "run_depends");
|
||||
if (rundeps == NULL) {
|
||||
rundeps = prop_dictionary_get(propsd, "run_depends");
|
||||
if (rundeps == NULL)
|
||||
rundeps = prop_array_create();
|
||||
|
||||
prop_dictionary_set(opkgd, "run_depends", rundeps);
|
||||
/* remove requiredby object, unneeded since 0.19 */
|
||||
prop_dictionary_remove(opkgd, "requiredby");
|
||||
}
|
||||
|
||||
/*
|
||||
* Check pkg metadata signature.
|
||||
*/
|
||||
prop_dictionary_get_cstring_nocopy(opkgd, "metafile-sha256", &sha256);
|
||||
if (sha256 != NULL) {
|
||||
buf = xbps_xasprintf("%s/.%s.plist",
|
||||
@@ -155,7 +169,6 @@ do { \
|
||||
RUN_PKG_CHECK(xhp, files, propsd);
|
||||
RUN_PKG_CHECK(xhp, symlinks, propsd);
|
||||
RUN_PKG_CHECK(xhp, rundeps, propsd);
|
||||
RUN_PKG_CHECK(xhp, requiredby, opkgd);
|
||||
RUN_PKG_CHECK(xhp, unneeded, opkgd);
|
||||
|
||||
#undef RUN_PKG_CHECK
|
||||
|
||||
@@ -1,188 +0,0 @@
|
||||
/*-
|
||||
* Copyright (c) 2011-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 <unistd.h>
|
||||
#include <assert.h>
|
||||
|
||||
#include <xbps_api.h>
|
||||
#include "defs.h"
|
||||
|
||||
static int
|
||||
check_reqby_pkg_cb(struct xbps_handle *xhp,
|
||||
prop_object_t obj,
|
||||
void *arg,
|
||||
bool *done)
|
||||
{
|
||||
prop_dictionary_t pkgd = arg;
|
||||
prop_array_t curpkg_rdeps, provides, pkgd_reqby;
|
||||
prop_dictionary_t curpkg_propsd;
|
||||
prop_string_t curpkgver;
|
||||
const char *curpkgn, *pkgname, *pkgver;
|
||||
|
||||
(void)done;
|
||||
|
||||
prop_dictionary_get_cstring_nocopy(pkgd, "pkgname", &pkgname);
|
||||
prop_dictionary_get_cstring_nocopy(pkgd, "pkgver", &pkgver);
|
||||
prop_dictionary_get_cstring_nocopy(obj, "pkgname", &curpkgn);
|
||||
/* skip same pkg */
|
||||
if (strcmp(curpkgn, pkgname) == 0)
|
||||
return 0;
|
||||
|
||||
/*
|
||||
* Internalize current pkg props dictionary from its
|
||||
* installed metadata directory.
|
||||
*/
|
||||
curpkg_propsd = xbps_pkgdb_get_pkg_metadata(xhp, curpkgn);
|
||||
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 */
|
||||
return 0;
|
||||
}
|
||||
/*
|
||||
* 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 (provides == NULL) {
|
||||
/* doesn't provide any virtual pkg */
|
||||
return 0;
|
||||
}
|
||||
if (!xbps_match_any_virtualpkg_in_rundeps(curpkg_rdeps,
|
||||
provides)) {
|
||||
/* doesn't match any virtual pkg */
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
pkgd_reqby = prop_dictionary_get(pkgd, "requiredby");
|
||||
curpkgver = prop_dictionary_get(curpkg_propsd, "pkgver");
|
||||
if (pkgd_reqby != NULL) {
|
||||
/*
|
||||
* Now check that current pkgver has been registered into
|
||||
* its requiredby array.
|
||||
*/
|
||||
if (xbps_match_string_in_array(pkgd_reqby,
|
||||
prop_string_cstring_nocopy(curpkgver))) {
|
||||
/*
|
||||
* Current package already requires our package,
|
||||
* this is good so skip it.
|
||||
*/
|
||||
return 0;
|
||||
}
|
||||
} else {
|
||||
/*
|
||||
* Missing requiredby array object, create it.
|
||||
*/
|
||||
pkgd_reqby = prop_array_create();
|
||||
assert(pkgd_reqby);
|
||||
}
|
||||
/*
|
||||
* Added pkgdep into pkg's requiredby array.
|
||||
*/
|
||||
if (!prop_array_add(pkgd_reqby, curpkgver))
|
||||
return -1;
|
||||
|
||||
prop_dictionary_set(pkgd, "requiredby", pkgd_reqby);
|
||||
|
||||
printf("%s: added requiredby entry for %s.\n",
|
||||
pkgver, prop_string_cstring_nocopy(curpkgver));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Removes unused entries in pkg's requiredby array.
|
||||
*/
|
||||
static void
|
||||
remove_stale_entries_in_reqby(struct xbps_handle *xhp, prop_dictionary_t pkgd)
|
||||
{
|
||||
prop_array_t reqby;
|
||||
const char *pkgver;
|
||||
char *str;
|
||||
size_t i;
|
||||
|
||||
prop_dictionary_get_cstring_nocopy(pkgd, "pkgver", &pkgver);
|
||||
|
||||
again:
|
||||
reqby = prop_dictionary_get(pkgd, "requiredby");
|
||||
if (reqby == NULL || prop_array_count(reqby) == 0)
|
||||
return;
|
||||
|
||||
for (i = 0; i < prop_array_count(reqby); i++) {
|
||||
prop_array_get_cstring(reqby, i, &str);
|
||||
if ((pkgd = xbps_pkgdb_get_pkg(xhp, str)) != NULL)
|
||||
continue;
|
||||
|
||||
prop_array_remove(reqby, i);
|
||||
printf("%s: removed stale entry in requiredby `%s'\n",
|
||||
pkgver, str);
|
||||
prop_dictionary_set(pkgd, "requiredby", reqby);
|
||||
free(str);
|
||||
goto again;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* 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 pkgdb dictionary.
|
||||
*
|
||||
* Returns 0 if test ran successfully, 1 otherwise and -1 on error.
|
||||
*/
|
||||
int
|
||||
check_pkg_requiredby(struct xbps_handle *xhp, const char *pkgname, void *arg)
|
||||
{
|
||||
prop_dictionary_t pkgd = arg;
|
||||
int rv;
|
||||
|
||||
(void)pkgname;
|
||||
|
||||
/* missing reqby entries in pkgs */
|
||||
rv = xbps_pkgdb_foreach_cb(xhp, check_reqby_pkg_cb, pkgd);
|
||||
if (rv != 0)
|
||||
return rv;
|
||||
|
||||
/* remove stale entries in pkg's reqby */
|
||||
remove_stale_entries_in_reqby(xhp, pkgd);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -40,7 +40,6 @@ CHECK_PKG_DECL(unneeded);
|
||||
CHECK_PKG_DECL(files);
|
||||
CHECK_PKG_DECL(rundeps);
|
||||
CHECK_PKG_DECL(symlinks);
|
||||
CHECK_PKG_DECL(requiredby);
|
||||
|
||||
/* from convert.c */
|
||||
int convert_pkgd_metadir(struct xbps_handle *, prop_dictionary_t);
|
||||
|
||||
@@ -54,19 +54,18 @@ show_pkg_deps(struct xbps_handle *xhp, const char *pkgname)
|
||||
int
|
||||
show_pkg_revdeps(struct xbps_handle *xhp, const char *pkg)
|
||||
{
|
||||
prop_dictionary_t pkgd;
|
||||
int rv = 0;
|
||||
prop_array_t reqby;
|
||||
const char *pkgdep;
|
||||
size_t i;
|
||||
|
||||
pkgd = xbps_pkgdb_get_virtualpkg(xhp, pkg);
|
||||
if (pkgd == NULL) {
|
||||
pkgd = xbps_pkgdb_get_pkg(xhp, pkg);
|
||||
if (pkgd == NULL)
|
||||
return ENOENT;
|
||||
reqby = xbps_pkgdb_get_pkg_revdeps(xhp, pkg);
|
||||
if (reqby) {
|
||||
for (i = 0; i < prop_array_count(reqby); i++) {
|
||||
prop_array_get_cstring_nocopy(reqby, i, &pkgdep);
|
||||
printf("%s\n", pkgdep);
|
||||
}
|
||||
}
|
||||
rv = xbps_callback_array_iter_in_dict(xhp, pkgd, "requiredby",
|
||||
list_strings_sep_in_array, NULL);
|
||||
|
||||
return rv;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
|
||||
@@ -162,7 +162,6 @@ show_pkg_info(prop_dictionary_t dict)
|
||||
obj = prop_dictionary_get_keysym(dict, keysym);
|
||||
/* ignore objs shown by other targets */
|
||||
if ((strcmp(keyname, "run_depends") == 0) ||
|
||||
(strcmp(keyname, "requiredby") == 0) ||
|
||||
(strcmp(keyname, "files") == 0) ||
|
||||
(strcmp(keyname, "dirs") == 0) ||
|
||||
(strcmp(keyname, "links") == 0))
|
||||
|
||||
@@ -204,7 +204,6 @@ static int
|
||||
remove_pkg(struct xbps_handle *xhp, const char *pkgname, size_t cols,
|
||||
bool recursive)
|
||||
{
|
||||
prop_dictionary_t pkgd;
|
||||
prop_array_t reqby;
|
||||
const char *pkgver;
|
||||
size_t x;
|
||||
@@ -213,11 +212,9 @@ remove_pkg(struct xbps_handle *xhp, const char *pkgname, size_t cols,
|
||||
rv = xbps_transaction_remove_pkg(xhp, pkgname, recursive);
|
||||
if (rv == EEXIST) {
|
||||
/* pkg has revdeps */
|
||||
pkgd = xbps_pkgdb_get_pkg(xhp, pkgname);
|
||||
prop_dictionary_get_cstring_nocopy(pkgd, "pkgver", &pkgver);
|
||||
reqby = prop_dictionary_get(pkgd, "requiredby");
|
||||
reqby = xbps_pkgdb_get_pkg_revdeps(xhp, pkgname);
|
||||
printf("WARNING: %s IS REQUIRED BY %u PACKAGE%s:\n\n",
|
||||
pkgver, prop_array_count(reqby),
|
||||
pkgname, prop_array_count(reqby),
|
||||
prop_array_count(reqby) > 1 ? "S" : "");
|
||||
for (x = 0; x < prop_array_count(reqby); x++) {
|
||||
prop_array_get_cstring_nocopy(reqby, x, &pkgver);
|
||||
|
||||
Reference in New Issue
Block a user