xbps-bin: add support to check integrity of all installed packages,
through "xbps-bin check all". --HG-- extra : convert_revision : xtraeme%40gmail.com-20091005224237-plr75i3wveirhu4p
This commit is contained in:
parent
06f70e182c
commit
3d8fb79e94
@ -45,6 +45,38 @@
|
||||
* o Check for missing run time dependencies.
|
||||
*/
|
||||
|
||||
int
|
||||
xbps_check_pkg_integrity_all(void)
|
||||
{
|
||||
prop_dictionary_t d;
|
||||
prop_object_t obj;
|
||||
prop_object_iterator_t iter;
|
||||
const char *pkgname;
|
||||
int rv = 0;
|
||||
size_t npkgs = 0, nbrokenpkgs = 0;
|
||||
|
||||
d = xbps_prepare_regpkgdb_dict();
|
||||
if (d == NULL)
|
||||
return ENODEV;
|
||||
|
||||
iter = xbps_get_array_iter_from_dict(d, "packages");
|
||||
if (iter == NULL)
|
||||
return ENOENT;
|
||||
|
||||
while ((obj = prop_object_iterator_next(iter)) != NULL) {
|
||||
prop_dictionary_get_cstring_nocopy(obj, "pkgname", &pkgname);
|
||||
if ((rv = xbps_check_pkg_integrity(pkgname)) != 0)
|
||||
nbrokenpkgs++;
|
||||
npkgs++;
|
||||
}
|
||||
prop_object_iterator_release(iter);
|
||||
|
||||
printf("%zu package%s processed: %zu broken.\n", npkgs,
|
||||
npkgs == 1 ? "" : "s", nbrokenpkgs);
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
int
|
||||
xbps_check_pkg_integrity(const char *pkgname)
|
||||
{
|
||||
@ -55,7 +87,7 @@ xbps_check_pkg_integrity(const char *pkgname)
|
||||
const char *rootdir, *file, *sha256, *reqpkg;
|
||||
char *path;
|
||||
int rv = 0;
|
||||
bool files_broken = false;
|
||||
bool broken = false, files_broken = false;
|
||||
|
||||
assert(pkgname != NULL);
|
||||
|
||||
@ -174,8 +206,10 @@ xbps_check_pkg_integrity(const char *pkgname)
|
||||
free(path);
|
||||
}
|
||||
prop_object_iterator_release(iter);
|
||||
if (files_broken)
|
||||
if (files_broken) {
|
||||
broken = true;
|
||||
printf("%s: files check FAILED.\n", pkgname);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
@ -201,6 +235,7 @@ xbps_check_pkg_integrity(const char *pkgname)
|
||||
if (errno == ENOENT) {
|
||||
printf("%s: unexistent file %s\n",
|
||||
pkgname, file);
|
||||
broken = true;
|
||||
} else
|
||||
printf("%s: unexpected error for "
|
||||
"%s (%s)\n", pkgname, file,
|
||||
@ -232,9 +267,11 @@ xbps_check_pkg_integrity(const char *pkgname)
|
||||
}
|
||||
}
|
||||
prop_object_iterator_release(iter);
|
||||
if (rv == ENOENT)
|
||||
if (rv == ENOENT) {
|
||||
printf("%s: run-time dependency check FAILED.\n",
|
||||
pkgname);
|
||||
broken = true;
|
||||
}
|
||||
}
|
||||
|
||||
out2:
|
||||
@ -245,5 +282,8 @@ out:
|
||||
prop_object_release(pkgd);
|
||||
xbps_release_regpkgdb_dict();
|
||||
|
||||
if (broken)
|
||||
rv = EINVAL;
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
@ -31,6 +31,7 @@ void xbps_autoremove_pkgs(void);
|
||||
void xbps_remove_installed_pkg(const char *, bool);
|
||||
void xbps_autoupdate_pkgs(bool);
|
||||
int xbps_check_pkg_integrity(const char *);
|
||||
int xbps_check_pkg_integrity_all(void);
|
||||
int xbps_show_pkg_deps(const char *);
|
||||
int xbps_show_pkg_reverse_deps(const char *);
|
||||
|
||||
|
@ -45,7 +45,7 @@ usage(void)
|
||||
" remove, show, show-deps, show-files, show-revdeps, update\n"
|
||||
"\n"
|
||||
" Targets with arguments:\n"
|
||||
" check\t\t<pkgname>\n"
|
||||
" check\t\t[<pkgname>|<all>]\n"
|
||||
" install\t\t<pkgname>\n"
|
||||
" purge\t\t[<pkgname>|<all>]\n"
|
||||
" reconfigure\t\t[<pkgname>|<all>]\n"
|
||||
@ -195,7 +195,10 @@ main(int argc, char **argv)
|
||||
if (argc != 2)
|
||||
usage();
|
||||
|
||||
rv = xbps_check_pkg_integrity(argv[1]);
|
||||
if (strcasecmp(argv[1], "all") == 0)
|
||||
rv = xbps_check_pkg_integrity_all();
|
||||
else
|
||||
rv = xbps_check_pkg_integrity(argv[1]);
|
||||
|
||||
} else if (strcasecmp(argv[0], "autoupdate") == 0) {
|
||||
/*
|
||||
|
Loading…
Reference in New Issue
Block a user