xbps-pkgdb: exit with error if any test fails.

This commit is contained in:
Juan RP 2015-02-26 12:01:20 +01:00
parent 7c52471ff6
commit c712c99ced
5 changed files with 33 additions and 36 deletions

2
NEWS
View File

@ -1,5 +1,7 @@
xbps-0.44 (???):
* xbps-pkgdb(8): this now exits with an error if any test has failed.
* libxbps: while unpacking pkg files that were not modified (sha256 hash matched),
do not forget to also update the file timestamps on disk, to match
what the binary package has stored in the metadata.

View File

@ -1,5 +1,5 @@
/*-
* Copyright (c) 2009-2014 Juan Romero Pardines.
* Copyright (c) 2009-2015 Juan Romero Pardines.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@ -39,12 +39,12 @@ static int
pkgdb_cb(struct xbps_handle *xhp _unused,
xbps_object_t obj,
const char *key _unused,
void *arg _unused,
void *arg,
bool *done _unused)
{
const char *pkgver;
char *pkgname;
int rv;
int rv, *errors = (int *)arg;
xbps_dictionary_get_cstring_nocopy(obj, "pkgver", &pkgver);
if (xhp->flags & XBPS_FLAG_VERBOSE)
@ -52,19 +52,19 @@ pkgdb_cb(struct xbps_handle *xhp _unused,
pkgname = xbps_pkg_name(pkgver);
assert(pkgname);
rv = check_pkg_integrity(xhp, obj, pkgname);
free(pkgname);
if (rv != 0)
fprintf(stderr, "pkgdb failed for %s: %s\n",
pkgver, strerror(rv));
if ((rv = check_pkg_integrity(xhp, obj, pkgname)) != 0)
*errors += 1;
return rv;
free(pkgname);
return 0;
}
int
check_pkg_integrity_all(struct xbps_handle *xhp)
{
return xbps_pkgdb_foreach_cb_multi(xhp, pkgdb_cb, NULL);
int errors = 0;
xbps_pkgdb_foreach_cb_multi(xhp, pkgdb_cb, &errors);
return errors ? -1 : 0;
}
int
@ -75,7 +75,7 @@ check_pkg_integrity(struct xbps_handle *xhp,
xbps_dictionary_t opkgd, filesd = NULL;
const char *sha256;
char *buf;
int rv = 0;
int rv = 0, errors = 0;
filesd = opkgd = NULL;
@ -109,16 +109,11 @@ check_pkg_integrity(struct xbps_handle *xhp,
}
}
#define RUN_PKG_CHECK(x, name, arg) \
do { \
if (arg != NULL) { \
rv = check_pkg_##name(x, pkgname, arg); \
if (rv == -1) { \
xbps_error_printf("%s: the %s test " \
"returned error!\n", pkgname, #name); \
return EINVAL; \
} \
} \
#define RUN_PKG_CHECK(x, name, arg) \
do { \
if ((rv = check_pkg_##name(x, pkgname, arg)) != 0) { \
errors++; \
} \
} while (0)
/* Execute pkg checks */
@ -132,5 +127,5 @@ do { \
#undef RUN_PKG_CHECK
return 0;
return errors ? EXIT_FAILURE : EXIT_SUCCESS;
}

View File

@ -80,8 +80,8 @@ check_pkg_files(struct xbps_handle *xhp, const char *pkgname, void *arg)
xbps_dictionary_t pkg_filesd = arg;
const char *file, *sha256;
char *path;
bool mutable, broken = false, test_broken = false;
int rv;
bool mutable, test_broken = false;
int rv = 0, errors = 0;
array = xbps_dictionary_get(pkg_filesd, "files");
if (array != NULL && xbps_array_count(array) > 0) {
@ -132,7 +132,7 @@ check_pkg_files(struct xbps_handle *xhp, const char *pkgname, void *arg)
if (test_broken) {
xbps_error_printf("%s: files check FAILED.\n", pkgname);
test_broken = false;
broken = true;
errors++;
}
/*
@ -165,8 +165,8 @@ check_pkg_files(struct xbps_handle *xhp, const char *pkgname, void *arg)
}
if (test_broken) {
xbps_error_printf("%s: conf files check FAILED.\n", pkgname);
broken = true;
errors++;
}
return broken;
return errors ? -1 : 0;
}

View File

@ -1,5 +1,5 @@
/*-
* Copyright (c) 2011-2012 Juan Romero Pardines.
* Copyright (c) 2011-2015 Juan Romero Pardines.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@ -50,7 +50,7 @@ check_pkg_rundeps(struct xbps_handle *xhp, const char *pkgname, void *arg)
xbps_dictionary_t pkg_propsd = arg;
xbps_array_t array;
const char *reqpkg;
bool test_broken = false;
int rv = 0;
if (!xbps_pkg_has_rundeps(pkg_propsd))
return 0;
@ -61,8 +61,8 @@ check_pkg_rundeps(struct xbps_handle *xhp, const char *pkgname, void *arg)
if (xbps_pkg_is_installed(xhp, reqpkg) <= 0) {
xbps_error_printf("%s: dependency not satisfied: %s\n",
pkgname, reqpkg);
test_broken = true;
rv = -1;
}
}
return test_broken;
return rv;
}

View File

@ -52,11 +52,11 @@ check_pkg_symlinks(struct xbps_handle *xhp, const char *pkgname, void *arg)
xbps_array_t array;
xbps_object_t obj;
xbps_dictionary_t filesd = arg;
bool broken = false;
int rv = 0;
array = xbps_dictionary_get(filesd, "links");
if (array == NULL)
return false;
return 0;
for (unsigned int i = 0; i < xbps_array_count(array); i++) {
const char *file = NULL, *tgt = NULL;
@ -79,16 +79,16 @@ check_pkg_symlinks(struct xbps_handle *xhp, const char *pkgname, void *arg)
snprintf(path, sizeof(path), "%s/%s", xhp->rootdir, file);
if ((lnk = xbps_symlink_target(xhp, path, tgt)) == NULL) {
xbps_error_printf("%s: broken symlink %s (target: %s)\n", pkgname, file, tgt);
broken = true;
rv = -1;
continue;
}
if (strcmp(lnk, tgt)) {
xbps_warn_printf("%s: modified symlink %s "
"points to %s (shall be %s)\n",
pkgname, file, lnk, tgt);
broken = true;
rv = -1;
}
free(lnk);
}
return broken;
return rv;
}