xbps-pkgdb(8): check pkg file mtime (iff the obj is available).

This commit is contained in:
Juan RP 2015-02-22 18:45:47 +01:00
parent 2cae0cba01
commit 3855d2e2fb
3 changed files with 37 additions and 2 deletions

3
NEWS
View File

@ -1,5 +1,8 @@
xbps-0.44 (???): xbps-0.44 (???):
* xbps-pkgdb(8): this now checks the modification time of pkg files
(iff the pkg metadata has that information).
* xbps-create(8): modification time of regular files and links is now stored * xbps-create(8): modification time of regular files and links is now stored
in the package files metadata, will be used in a future version. in the package files metadata, will be used in a future version.

View File

@ -1,5 +1,5 @@
/*- /*-
* Copyright (c) 2011-2013 Juan Romero Pardines. * Copyright (c) 2011-2015 Juan Romero Pardines.
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@ -43,8 +43,34 @@
* o Check the hash for all installed files, except * o Check the hash for all installed files, except
* configuration files (which is expected if they are modified). * configuration files (which is expected if they are modified).
* *
* o Compares stored file modification time.
*
* Return 0 if test ran successfully, 1 otherwise and -1 on error. * Return 0 if test ran successfully, 1 otherwise and -1 on error.
*/ */
static bool
check_file_mtime(xbps_dictionary_t d, const char *pkg, const char *path)
{
struct stat sb;
uint64_t mtime = 0;
const char *file;
/* if obj is not there, skip silently */
if (!xbps_dictionary_get_uint64(d, "mtime", &mtime))
return false;
if (stat(path, &sb) == -1)
return true;
if ((uint64_t)sb.st_mtime != mtime) {
xbps_dictionary_get_cstring_nocopy(d, "file", &file);
xbps_error_printf("%s: %s mtime mismatch "
"(current: %ju, stored %ju)\n",
pkg, file, (uint64_t)sb.st_mtime, mtime);
return true;
}
return false;
}
int int
check_pkg_files(struct xbps_handle *xhp, const char *pkgname, void *arg) check_pkg_files(struct xbps_handle *xhp, const char *pkgname, void *arg)
{ {
@ -72,6 +98,9 @@ check_pkg_files(struct xbps_handle *xhp, const char *pkgname, void *arg)
free(path); free(path);
switch (rv) { switch (rv) {
case 0: case 0:
if (check_file_mtime(obj, pkgname, path)) {
test_broken = true;
}
break; break;
case ENOENT: case ENOENT:
xbps_error_printf("%s: unexistent file %s.\n", xbps_error_printf("%s: unexistent file %s.\n",

View File

@ -1,4 +1,4 @@
.Dd December 15, 2014 .Dd February 22, 2014
.Dt XBPS-PKGDB 8 .Dt XBPS-PKGDB 8
.Sh NAME .Sh NAME
.Nm xbps-pkgdb .Nm xbps-pkgdb
@ -24,6 +24,9 @@ hash that is recorded when package is installed against current one.
.It Sy FILES CHECK .It Sy FILES CHECK
Checks that all files belonging to a package have not been modified and are Checks that all files belonging to a package have not been modified and are
not missing. not missing.
For regular files, its modification time and the SHA256 hash are
compared and checked if they differ.
For symbolic links the target file is checked that it has not been modified.
.It Sy DEPENDENCIES CHECK .It Sy DEPENDENCIES CHECK
Checks that all required dependencies for a package are resolved. Checks that all required dependencies for a package are resolved.
.It Sy OBSOLETE METADATA CHECK .It Sy OBSOLETE METADATA CHECK