xbps-bin: simplify and make 'check' target work after regpkgdb flush changes.

This commit is contained in:
Juan RP 2011-12-29 16:43:52 +01:00
parent bae664c639
commit e22ba9a972
7 changed files with 52 additions and 96 deletions

View File

@ -128,24 +128,24 @@ check_pkg_integrity(prop_dictionary_t pkgd, const char *pkgname)
goto out;
}
#define RUN_PKG_CHECK(name) \
do { \
rv = check_pkg_##name(pkgd ? pkgd : opkgd, propsd, filesd); \
if (rv) \
broken = true; \
else if (rv == -1) { \
xbps_error_printf("%s: the %s test " \
"returned error!\n", pkgname, #name); \
goto out; \
} \
#define RUN_PKG_CHECK(name, arg) \
do { \
rv = check_pkg_##name(pkgname, arg); \
if (rv) \
broken = true; \
else if (rv == -1) { \
xbps_error_printf("%s: the %s test " \
"returned error!\n", pkgname, #name); \
goto out; \
} \
} while (0)
/* Execute pkg checks */
RUN_PKG_CHECK(autoinstall);
RUN_PKG_CHECK(files);
RUN_PKG_CHECK(symlinks);
RUN_PKG_CHECK(rundeps);
RUN_PKG_CHECK(requiredby);
RUN_PKG_CHECK(requiredby, pkgd);
RUN_PKG_CHECK(autoinstall, pkgd);
RUN_PKG_CHECK(files, filesd);
RUN_PKG_CHECK(symlinks, filesd);
RUN_PKG_CHECK(rundeps, propsd);
#undef RUN_PKG_CHECK

View File

@ -47,70 +47,50 @@
* Returns 0 if test ran successfully, 1 otherwise and -1 on error.
*/
int
check_pkg_autoinstall(prop_dictionary_t pkgd_regpkgdb,
prop_dictionary_t pkg_propsd,
prop_dictionary_t pkg_filesd)
check_pkg_autoinstall(const char *pkgname, void *arg)
{
const struct xbps_handle *xhp = xbps_handle_get();
prop_dictionary_t dict;
struct xbps_handle *xhp = xbps_handle_get();
prop_dictionary_t pkgd = arg;
prop_array_t array, reqby;
const char *pkgname;
char *path;
int rv = 0;
bool autoinst = false;
(void)pkg_propsd;
(void)pkg_filesd;
prop_dictionary_get_cstring_nocopy(pkgd_regpkgdb, "pkgname", &pkgname);
/*
* Check if package has been installed manually but any other
* package is currently depending on it; in that case the package
* must be in automatic mode.
*/
if (prop_dictionary_get_bool(pkgd_regpkgdb,
"automatic-install", &autoinst)) {
reqby = prop_dictionary_get(pkgd_regpkgdb, "requiredby");
if (prop_dictionary_get_bool(pkgd, "automatic-install", &autoinst)) {
reqby = prop_dictionary_get(pkgd, "requiredby");
if (((prop_object_type(reqby) == PROP_TYPE_ARRAY)) &&
((prop_array_count(reqby) > 0) && !autoinst)) {
path = xbps_xasprintf("%s/%s/%s", xhp->rootdir,
XBPS_META_PATH, XBPS_REGPKGDB);
assert(path != NULL);
/* pkg has reversedeps and was installed manually */
prop_dictionary_set_bool(pkgd_regpkgdb,
prop_dictionary_set_bool(pkgd,
"automatic-install", true);
dict = prop_dictionary_internalize_from_zfile(path);
if (dict == NULL) {
xbps_error_printf("%s: [0] failed to set "
"automatic mode (%s)\n", pkgname,
strerror(errno));
return -1;
}
array = prop_dictionary_get(dict, "packages");
array = prop_dictionary_get(xhp->regpkgdb, "packages");
rv = xbps_array_replace_dict_by_name(array,
pkgd_regpkgdb, pkgname);
pkgd, pkgname);
if (rv != 0) {
xbps_error_printf("%s: [1] failed to set "
"automatic mode (%s)\n", pkgname,
strerror(rv));
return -1;
}
if (!prop_dictionary_set(dict, "packages", array)) {
if (!prop_dictionary_set(xhp->regpkgdb,
"packages", array)) {
xbps_error_printf("%s: [2] failed to set "
"automatic mode (%s)\n", pkgname,
strerror(rv));
return -1;
}
if (!prop_dictionary_externalize_to_zfile(dict, path)) {
xbps_error_printf("%s: [3] failed to set "
"automatic mode (%s)\n", pkgname,
strerror(errno));
if ((rv = xbps_regpkgdb_update(xhp, true)) != 0) {
xbps_error_printf("%s: failed to write "
"regpkgdb plist: %s\n", pkgname,
strerror(rv));
return -1;
}
free(path);
path = NULL;
xbps_warn_printf("%s: was installed manually and has "
"reverse dependencies (FIXED)\n", pkgname);
}

View File

@ -47,22 +47,18 @@
* Return 0 if test ran successfully, 1 otherwise and -1 on error.
*/
int
check_pkg_files(prop_dictionary_t pkgd_regpkgdb,
prop_dictionary_t pkg_propsd,
prop_dictionary_t pkg_filesd)
check_pkg_files(const char *pkgname, void *arg)
{
struct xbps_handle *xhp = xbps_handle_get();
prop_array_t array;
prop_object_t obj;
prop_object_iterator_t iter;
const char *pkgname, *file, *sha256;
prop_dictionary_t pkg_filesd = arg;
const char *file, *sha256;
char *path;
int rv = 0;
bool broken = false, test_broken = false;
(void)pkg_propsd;
prop_dictionary_get_cstring_nocopy(pkgd_regpkgdb, "pkgname", &pkgname);
array = prop_dictionary_get(pkg_filesd, "files");
if ((prop_object_type(array) == PROP_TYPE_ARRAY) &&
prop_array_count(array) > 0) {

View File

@ -45,25 +45,18 @@
* Returns 0 if test ran successfully, 1 otherwise and -1 on error.
*/
int
check_pkg_requiredby(prop_dictionary_t pkgd_regpkgdb,
prop_dictionary_t pkg_propsd,
prop_dictionary_t pkg_filesd)
check_pkg_requiredby(const char *pkgname, void *arg)
{
prop_array_t regpkgs, reqby, curpkg_rdeps, provides;
prop_dictionary_t curpkg_propsd;
prop_dictionary_t curpkg_propsd, pkgd = arg;
prop_object_t obj;
prop_string_t curpkgver;
struct xbps_handle *xhp = xbps_handle_get();
const char *curpkgn, *pkgname, *pkgver;
const char *curpkgn, *pkgver;
size_t i;
int rv;
bool pkg_fixed = false;
(void)pkg_propsd;
(void)pkg_filesd;
prop_dictionary_get_cstring_nocopy(pkgd_regpkgdb, "pkgname", &pkgname);
prop_dictionary_get_cstring_nocopy(pkgd_regpkgdb, "pkgver", &pkgver);
prop_dictionary_get_cstring_nocopy(pkgd, "pkgver", &pkgver);
regpkgs = prop_dictionary_get(xhp->regpkgdb, "packages");
@ -100,7 +93,7 @@ check_pkg_requiredby(prop_dictionary_t pkgd_regpkgdb,
* package and is matched against any object in
* run_depends.
*/
provides = prop_dictionary_get(pkgd_regpkgdb, "provides");
provides = prop_dictionary_get(pkgd, "provides");
if (prop_object_type(provides) != PROP_TYPE_ARRAY) {
/* doesn't provide any virtual pkg */
prop_object_release(curpkg_propsd);
@ -113,7 +106,7 @@ check_pkg_requiredby(prop_dictionary_t pkgd_regpkgdb,
continue;
}
}
reqby = prop_dictionary_get(pkgd_regpkgdb, "requiredby");
reqby = prop_dictionary_get(pkgd, "requiredby");
curpkgver = prop_dictionary_get(curpkg_propsd, "pkgver");
if (prop_object_type(reqby) == PROP_TYPE_ARRAY) {
/*
@ -144,7 +137,7 @@ check_pkg_requiredby(prop_dictionary_t pkgd_regpkgdb,
* file to disk.
*/
prop_array_add(reqby, curpkgver);
prop_dictionary_set(pkgd_regpkgdb, "requiredby", reqby);
prop_dictionary_set(pkgd, "requiredby", reqby);
rv = xbps_array_replace_dict_by_name(regpkgs, obj, curpkgn);
if (rv != 0) {
xbps_error_printf("%s: failed to replace pkgd: %s\n",
@ -156,19 +149,14 @@ check_pkg_requiredby(prop_dictionary_t pkgd_regpkgdb,
"packages array: %s", curpkgn, strerror(errno));
return -1;
}
pkg_fixed = true;
if ((rv = xbps_regpkgdb_update(xhp, true)) != 0) {
xbps_error_printf("failed to write regpkgdb plist: "
" %s\n", strerror(rv));
return rv;
}
printf("%s: added requiredby entry for %s.\n",
pkgver, prop_string_cstring_nocopy(curpkgver));
prop_object_release(curpkg_propsd);
}
if (pkg_fixed == false)
return rv;
if ((rv = xbps_regpkgdb_update(xhp, true)) != 0) {
xbps_error_printf("failed to write regpkgdb plist: "
" %s\n", strerror(rv));
return rv;
}
return rv;
}

View File

@ -45,18 +45,14 @@
*/
int
check_pkg_rundeps(prop_dictionary_t pkgd_regpkgdb,
prop_dictionary_t pkg_propsd,
prop_dictionary_t pkg_filesd)
check_pkg_rundeps(const char *pkgname, void *arg)
{
prop_dictionary_t pkg_propsd = arg;
prop_object_t obj;
prop_object_iterator_t iter;
const char *reqpkg, *pkgname;
const char *reqpkg;
bool test_broken = false;
(void)pkg_filesd;
prop_dictionary_get_cstring_nocopy(pkgd_regpkgdb, "pkgname", &pkgname);
if (!xbps_pkg_has_rundeps(pkg_propsd))
return 0;

View File

@ -45,21 +45,17 @@
* returns 0 if test ran successfully, 1 otherwise and -1 on error.
*/
int
check_pkg_symlinks(prop_dictionary_t pkgd_regpkgdb,
prop_dictionary_t pkg_propsd,
prop_dictionary_t pkg_filesd)
check_pkg_symlinks(const char *pkgname, void *arg)
{
const struct xbps_handle *xhp = xbps_handle_get();
prop_array_t array;
prop_object_t obj;
prop_object_iterator_t iter;
const char *pkgname, *file, *tgt = NULL;
prop_dictionary_t pkg_filesd = arg;
const char *file, *tgt = NULL;
char *path, buf[PATH_MAX];
bool broken = false, test_broken = false;
(void)pkg_propsd;
prop_dictionary_get_cstring_nocopy(pkgd_regpkgdb, "pkgname", &pkgname);
array = prop_dictionary_get(pkg_filesd, "links");
if ((prop_object_type(array) == PROP_TYPE_ARRAY) &&
prop_array_count(array) > 0) {

View File

@ -59,8 +59,8 @@ int remove_installed_pkgs(int, char **, bool, bool, bool, bool);
int check_pkg_integrity(prop_dictionary_t, const char *);
int check_pkg_integrity_all(void);
#define CHECK_PKG_DECL(type) \
int check_pkg_##type (prop_dictionary_t, prop_dictionary_t, prop_dictionary_t)
#define CHECK_PKG_DECL(type) \
int check_pkg_##type (const char *, void *)
CHECK_PKG_DECL(autoinstall);
CHECK_PKG_DECL(files);