2012-11-02 19:34:25 +05:30
|
|
|
/*-
|
|
|
|
* 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>
|
2012-11-17 02:20:52 +05:30
|
|
|
#include <assert.h>
|
2012-11-02 19:34:25 +05:30
|
|
|
|
|
|
|
#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)
|
|
|
|
{
|
2012-11-17 22:13:54 +05:30
|
|
|
prop_dictionary_t pkgd = arg;
|
|
|
|
prop_array_t curpkg_rdeps, provides, pkgd_reqby;
|
2012-11-02 19:34:25 +05:30
|
|
|
prop_dictionary_t curpkg_propsd;
|
|
|
|
prop_string_t curpkgver;
|
2012-11-17 22:13:54 +05:30
|
|
|
const char *curpkgn, *pkgname, *pkgver;
|
2012-11-02 19:34:25 +05:30
|
|
|
|
|
|
|
(void)done;
|
|
|
|
|
2012-11-17 22:13:54 +05:30
|
|
|
prop_dictionary_get_cstring_nocopy(pkgd, "pkgname", &pkgname);
|
|
|
|
prop_dictionary_get_cstring_nocopy(pkgd, "pkgver", &pkgver);
|
2012-11-02 19:34:25 +05:30
|
|
|
prop_dictionary_get_cstring_nocopy(obj, "pkgname", &curpkgn);
|
|
|
|
/* skip same pkg */
|
2012-11-17 22:13:54 +05:30
|
|
|
if (strcmp(curpkgn, pkgname) == 0)
|
2012-11-02 19:34:25 +05:30
|
|
|
return 0;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Internalize current pkg props dictionary from its
|
|
|
|
* installed metadata directory.
|
|
|
|
*/
|
2012-11-17 02:20:52 +05:30
|
|
|
curpkg_propsd = xbps_metadir_get_pkgd(xhp, curpkgn);
|
2012-11-02 19:34:25 +05:30
|
|
|
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...
|
|
|
|
*/
|
2012-11-17 22:13:54 +05:30
|
|
|
if (!xbps_match_pkgdep_in_array(curpkg_rdeps, pkgver)) {
|
2012-11-02 19:34:25 +05:30
|
|
|
/*
|
|
|
|
* ... otherwise check if package provides any virtual
|
|
|
|
* package and is matched against any object in
|
|
|
|
* run_depends.
|
|
|
|
*/
|
2012-11-17 22:13:54 +05:30
|
|
|
provides = prop_dictionary_get(pkgd, "provides");
|
2012-11-02 19:34:25 +05:30
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
2012-11-17 22:13:54 +05:30
|
|
|
pkgd_reqby = prop_dictionary_get(pkgd, "requiredby");
|
2012-11-02 19:34:25 +05:30
|
|
|
curpkgver = prop_dictionary_get(curpkg_propsd, "pkgver");
|
2012-11-17 22:13:54 +05:30
|
|
|
if (pkgd_reqby != NULL) {
|
2012-11-02 19:34:25 +05:30
|
|
|
/*
|
|
|
|
* Now check that current pkgver has been registered into
|
|
|
|
* its requiredby array.
|
|
|
|
*/
|
2012-11-17 22:13:54 +05:30
|
|
|
if (xbps_match_string_in_array(pkgd_reqby,
|
2012-11-02 19:34:25 +05:30
|
|
|
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.
|
|
|
|
*/
|
2012-11-17 22:13:54 +05:30
|
|
|
pkgd_reqby = prop_array_create();
|
|
|
|
assert(pkgd_reqby);
|
2012-11-02 19:34:25 +05:30
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Added pkgdep into pkg's requiredby array.
|
|
|
|
*/
|
2012-11-17 22:13:54 +05:30
|
|
|
if (!prop_array_add(pkgd_reqby, curpkgver))
|
2012-11-02 19:34:25 +05:30
|
|
|
return -1;
|
2012-11-17 02:20:52 +05:30
|
|
|
|
2012-11-17 22:55:18 +05:30
|
|
|
printf("%s: added requiredby entry for %s.\n",
|
2012-11-17 22:13:54 +05:30
|
|
|
pkgver, prop_string_cstring_nocopy(curpkgver));
|
2012-11-17 02:20:52 +05:30
|
|
|
|
2012-11-17 22:13:54 +05:30
|
|
|
return 0;
|
2012-11-02 19:34:25 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Removes unused entries in pkg's requiredby array.
|
|
|
|
*/
|
2012-11-17 22:13:54 +05:30
|
|
|
static void
|
|
|
|
remove_stale_entries_in_reqby(struct xbps_handle *xhp, prop_dictionary_t pkgd)
|
2012-11-02 19:34:25 +05:30
|
|
|
{
|
|
|
|
prop_array_t reqby;
|
2012-11-17 22:55:18 +05:30
|
|
|
const char *pkgver;
|
|
|
|
char *str;
|
2012-11-02 19:34:25 +05:30
|
|
|
size_t i;
|
|
|
|
|
2012-11-17 22:13:54 +05:30
|
|
|
reqby = prop_dictionary_get(pkgd, "requiredby");
|
2012-11-02 19:34:25 +05:30
|
|
|
if (reqby == NULL || prop_array_count(reqby) == 0)
|
2012-11-17 22:13:54 +05:30
|
|
|
return;
|
2012-11-02 19:34:25 +05:30
|
|
|
|
2012-11-17 22:13:54 +05:30
|
|
|
prop_dictionary_get_cstring_nocopy(pkgd, "pkgver", &pkgver);
|
2012-11-02 19:34:25 +05:30
|
|
|
|
|
|
|
for (i = 0; i < prop_array_count(reqby); i++) {
|
2012-11-17 22:55:18 +05:30
|
|
|
prop_array_get_cstring(reqby, i, &str);
|
2012-11-02 19:34:25 +05:30
|
|
|
if ((pkgd = xbps_pkgdb_get_pkgd_by_pkgver(xhp, str)) != NULL)
|
|
|
|
continue;
|
2012-11-17 22:13:54 +05:30
|
|
|
|
|
|
|
if (!xbps_remove_string_from_array(xhp, reqby, str))
|
|
|
|
fprintf(stderr, "%s: failed to remove %s from "
|
|
|
|
"requiredby!\n", pkgver, str);
|
|
|
|
else
|
|
|
|
printf("%s: removed stale entry in requiredby `%s'\n",
|
|
|
|
pkgver, str);
|
2012-11-02 19:34:25 +05:30
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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
|
2012-11-17 22:13:54 +05:30
|
|
|
check_pkg_requiredby(struct xbps_handle *xhp, const char *pkgname, void *arg)
|
2012-11-02 19:34:25 +05:30
|
|
|
{
|
|
|
|
prop_dictionary_t pkgd = arg;
|
|
|
|
int rv;
|
|
|
|
|
2012-11-17 22:13:54 +05:30
|
|
|
(void)pkgname;
|
2012-11-02 19:34:25 +05:30
|
|
|
|
|
|
|
/* missing reqby entries in pkgs */
|
2012-11-17 22:13:54 +05:30
|
|
|
rv = xbps_pkgdb_foreach_cb(xhp, check_reqby_pkg_cb, pkgd);
|
|
|
|
if (rv != 0)
|
2012-11-02 19:34:25 +05:30
|
|
|
return rv;
|
|
|
|
|
|
|
|
/* remove stale entries in pkg's reqby */
|
2012-11-17 22:13:54 +05:30
|
|
|
remove_stale_entries_in_reqby(xhp, pkgd);
|
2012-11-02 19:34:25 +05:30
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|