3535#include <xbps.h>
3636#include "defs.h"
3737
38+ struct check_context {
39+ int errors ;
40+ unsigned ctr ;
41+ };
42+
3843static int
39- pkgdb_cb (struct xbps_handle * xhp UNUSED ,
44+ check_cb (struct xbps_handle * xhp UNUSED ,
4045 xbps_object_t obj ,
4146 const char * key UNUSED ,
4247 void * arg ,
4348 bool * done UNUSED )
4449{
4550 const char * pkgver = NULL ;
4651 char pkgname [XBPS_NAME_SIZE ];
47- int rv , * errors = (int * )arg ;
52+ struct check_context * ctx = arg ;
53+ int rv ;
4854
4955 xbps_dictionary_get_cstring_nocopy (obj , "pkgver" , & pkgver );
5056 if (xhp -> flags & XBPS_FLAG_VERBOSE )
@@ -53,24 +59,28 @@ pkgdb_cb(struct xbps_handle *xhp UNUSED,
5359 if (!xbps_pkg_name (pkgname , sizeof (pkgname ), pkgver )) {
5460 abort ();
5561 }
56- if ((rv = check_pkg_integrity (xhp , obj , pkgname )) != 0 )
57- * errors += 1 ;
62+ if ((rv = check_pkg (xhp , obj , pkgname , ctx -> ctr )) != 0 )
63+ ctx -> errors += 1 ;
5864
5965 return 0 ;
6066}
6167
6268int
63- check_pkg_integrity_all (struct xbps_handle * xhp )
69+ check_all (struct xbps_handle * xhp , unsigned int checks )
6470{
65- int errors = 0 ;
66- xbps_pkgdb_foreach_cb_multi (xhp , pkgdb_cb , & errors );
67- return errors ? -1 : 0 ;
71+ struct check_context args = {
72+ .errors = 0 ,
73+ .ctr = checks ,
74+ };
75+ xbps_pkgdb_foreach_cb_multi (xhp , check_cb , & args );
76+ return args .errors ? -1 : 0 ;
6877}
6978
7079int
71- check_pkg_integrity (struct xbps_handle * xhp ,
80+ check_pkg (struct xbps_handle * xhp ,
7281 xbps_dictionary_t pkgd ,
73- const char * pkgname )
82+ const char * pkgname ,
83+ unsigned checks )
7484{
7585 xbps_dictionary_t opkgd , filesd ;
7686 const char * sha256 ;
@@ -116,24 +126,27 @@ check_pkg_integrity(struct xbps_handle *xhp,
116126 }
117127 }
118128
119- #define RUN_PKG_CHECK (x , name , arg ) \
120- do { \
121- if (check_pkg_##name(x, pkgname, arg)) { \
122- errors++; \
123- } \
124- } while (0)
125-
126- /* Execute pkg checks */
127- RUN_PKG_CHECK (xhp , files , filesd );
128- RUN_PKG_CHECK (xhp , symlinks , filesd );
129- RUN_PKG_CHECK (xhp , rundeps , opkgd );
130- RUN_PKG_CHECK (xhp , unneeded , opkgd );
131- RUN_PKG_CHECK (xhp , alternatives , opkgd );
129+ if (checks & CHECK_FILES ) {
130+ if (check_pkg_files (xhp , pkgname , filesd ))
131+ errors ++ ;
132+ if (check_pkg_symlinks (xhp , pkgname , filesd ))
133+ errors ++ ;
134+ }
135+ if (checks & CHECK_DEPENDENCIES ) {
136+ if (check_pkg_rundeps (xhp , pkgname , opkgd ))
137+ errors ++ ;
138+ }
139+ if (checks & CHECK_ALTERNATIVES ) {
140+ if (check_pkg_alternatives (xhp , pkgname , opkgd ))
141+ errors ++ ;
142+ }
143+ if (checks & CHECK_PKGDB ) {
144+ if (check_pkg_unneeded (xhp , pkgname , opkgd ))
145+ errors ++ ;
146+ }
132147
133148 if (filesd )
134149 xbps_object_release (filesd );
135150
136- #undef RUN_PKG_CHECK
137-
138151 return !!errors ;
139152}
0 commit comments