Skip to content

Commit 93032d0

Browse files
ericonrDuncaen
andcommitted
xbps-pkgdb: add check selection.
Add the --checks option to xbps-pkgdb, which allows the user to select which package checks should be run. It works for a single package as well as with the --all option. Co-authored-by: Duncaen Overbruck <[email protected]>
1 parent 64be0bf commit 93032d0

File tree

8 files changed

+136
-70
lines changed

8 files changed

+136
-70
lines changed

bin/xbps-pkgdb/check.c

Lines changed: 38 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -35,16 +35,22 @@
3535
#include <xbps.h>
3636
#include "defs.h"
3737

38+
struct check_context {
39+
int errors;
40+
unsigned ctr;
41+
};
42+
3843
static 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

6268
int
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

7079
int
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
}

bin/xbps-pkgdb/check_pkg_alternatives.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,16 @@
2424
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2525
*/
2626

27-
#include <stdio.h>
27+
#include <sys/param.h>
28+
29+
#include <assert.h>
30+
#include <errno.h>
31+
#include <libgen.h>
2832
#include <stdbool.h>
33+
#include <stdio.h>
2934
#include <stdlib.h>
3035
#include <string.h>
31-
#include <errno.h>
32-
#include <assert.h>
3336
#include <unistd.h>
34-
#include <libgen.h>
35-
#include <sys/param.h>
3637

3738
#include <xbps.h>
3839
#include "defs.h"
@@ -153,10 +154,9 @@ check_symlinks(struct xbps_handle *xhp, const char *pkgname, xbps_array_t a,
153154
}
154155

155156
int
156-
check_pkg_alternatives(struct xbps_handle *xhp, const char *pkgname, void *arg)
157+
check_pkg_alternatives(struct xbps_handle *xhp, const char *pkgname, xbps_dictionary_t pkg_propsd)
157158
{
158159
xbps_array_t allkeys, array;
159-
xbps_dictionary_t pkg_propsd = arg;
160160
xbps_dictionary_t alternatives, pkg_alternatives;
161161
int rv = 0;
162162

bin/xbps-pkgdb/check_pkg_files.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,14 @@
2222
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
2323
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2424
*/
25+
#include <sys/param.h>
2526

26-
#include <stdio.h>
27+
#include <errno.h>
2728
#include <stdbool.h>
29+
#include <stdio.h>
2830
#include <stdlib.h>
2931
#include <string.h>
30-
#include <errno.h>
3132
#include <unistd.h>
32-
#include <sys/param.h>
3333

3434
#include <xbps.h>
3535
#include "defs.h"
@@ -49,12 +49,11 @@
4949
*/
5050

5151
int
52-
check_pkg_files(struct xbps_handle *xhp, const char *pkgname, void *arg)
52+
check_pkg_files(struct xbps_handle *xhp, const char *pkgname, xbps_dictionary_t pkg_filesd)
5353
{
5454
xbps_array_t array;
5555
xbps_object_t obj;
5656
xbps_object_iterator_t iter;
57-
xbps_dictionary_t pkg_filesd = arg;
5857
const char *file = NULL, *sha256 = NULL;
5958
char *path;
6059
bool mutable, test_broken = false;

bin/xbps-pkgdb/check_pkg_rundeps.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,13 @@
2323
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2424
*/
2525

26-
#include <stdio.h>
26+
#include <sys/param.h>
27+
2728
#include <stdbool.h>
29+
#include <stdio.h>
2830
#include <stdlib.h>
2931
#include <string.h>
30-
#include <errno.h>
31-
#include <assert.h>
3232
#include <unistd.h>
33-
#include <sys/param.h>
3433

3534
#include <xbps.h>
3635
#include "defs.h"
@@ -45,9 +44,8 @@
4544
*/
4645

4746
int
48-
check_pkg_rundeps(struct xbps_handle *xhp, const char *pkgname, void *arg)
47+
check_pkg_rundeps(struct xbps_handle *xhp, const char *pkgname, xbps_dictionary_t pkg_propsd)
4948
{
50-
xbps_dictionary_t pkg_propsd = arg;
5149
xbps_array_t array;
5250
const char *reqpkg = NULL;
5351
int rv = 0;

bin/xbps-pkgdb/check_pkg_symlinks.c

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,15 @@
2323
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2424
*/
2525

26-
#include <stdio.h>
26+
#include <sys/param.h>
27+
28+
#include <assert.h>
29+
#include <libgen.h>
2730
#include <stdbool.h>
31+
#include <stdio.h>
2832
#include <stdlib.h>
2933
#include <string.h>
30-
#include <errno.h>
31-
#include <assert.h>
3234
#include <unistd.h>
33-
#include <libgen.h>
34-
#include <sys/param.h>
3535

3636
#include <xbps.h>
3737
#include "defs.h"
@@ -47,11 +47,10 @@
4747
*/
4848

4949
int
50-
check_pkg_symlinks(struct xbps_handle *xhp, const char *pkgname, void *arg)
50+
check_pkg_symlinks(struct xbps_handle *xhp, const char *pkgname, xbps_dictionary_t filesd)
5151
{
5252
xbps_array_t array;
5353
xbps_object_t obj;
54-
xbps_dictionary_t filesd = arg;
5554
int rv = 0;
5655

5756
array = xbps_dictionary_get(filesd, "links");

bin/xbps-pkgdb/check_pkg_unneeded.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,14 @@
2323
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2424
*/
2525

26+
#include <sys/param.h>
27+
2628
#include <stdio.h>
2729
#include <stdbool.h>
2830
#include <stdlib.h>
2931
#include <string.h>
30-
#include <errno.h>
3132
#include <assert.h>
3233
#include <unistd.h>
33-
#include <sys/param.h>
3434

3535
#include <xbps.h>
3636
#include "defs.h"
@@ -43,10 +43,9 @@
4343
* and remove them if that was true.
4444
*/
4545
int
46-
check_pkg_unneeded(struct xbps_handle *xhp UNUSED, const char *pkgname, void *arg)
46+
check_pkg_unneeded(struct xbps_handle *xhp UNUSED, const char *pkgname, xbps_dictionary_t pkgd)
4747
{
4848
xbps_array_t replaces;
49-
xbps_dictionary_t pkgd = arg;
5049
const char *repo = NULL;
5150
char *buf;
5251

bin/xbps-pkgdb/defs.h

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,18 +29,29 @@
2929
#include <sys/time.h>
3030
#include <xbps.h>
3131

32+
enum {
33+
CHECK_FILES = 1 << 0,
34+
CHECK_DEPENDENCIES = 1 << 1,
35+
CHECK_ALTERNATIVES = 1 << 2,
36+
CHECK_PKGDB = 1 << 3,
37+
};
38+
3239
/* from check.c */
33-
int check_pkg_integrity(struct xbps_handle *, xbps_dictionary_t, const char *);
34-
int check_pkg_integrity_all(struct xbps_handle *);
40+
int check_pkg(struct xbps_handle *, xbps_dictionary_t, const char *, unsigned);
41+
int check_all(struct xbps_handle *, unsigned);
3542

36-
#define CHECK_PKG_DECL(type) \
37-
int check_pkg_##type (struct xbps_handle *, const char *, void *)
43+
int check_pkg_unneeded(
44+
struct xbps_handle *xhp, const char *pkgname, xbps_dictionary_t pkgd);
45+
int check_pkg_files(
46+
struct xbps_handle *xhp, const char *pkgname, xbps_dictionary_t filesd);
47+
int check_pkg_symlinks(
48+
struct xbps_handle *xhp, const char *pkgname, xbps_dictionary_t filesd);
49+
int check_pkg_rundeps(
50+
struct xbps_handle *xhp, const char *pkgname, xbps_dictionary_t pkgd);
51+
int check_pkg_alternatives(
52+
struct xbps_handle *xhp, const char *pkgname, xbps_dictionary_t pkgd);
3853

39-
CHECK_PKG_DECL(unneeded);
40-
CHECK_PKG_DECL(files);
41-
CHECK_PKG_DECL(rundeps);
42-
CHECK_PKG_DECL(symlinks);
43-
CHECK_PKG_DECL(alternatives);
54+
int get_checks_to_run(unsigned *, char *);
4455

4556
/* from convert.c */
4657
void convert_pkgdb_format(struct xbps_handle *);

0 commit comments

Comments
 (0)