1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
|
#include "config.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <alpm.h>
#include <alpm_list.h>
#define BASENAME "cleanupdelta"
alpm_handle_t *handle = NULL;
static void cleanup(int signum) {
if(handle && alpm_release(handle) == -1) {
fprintf(stderr, "error releasing alpm\n");
}
exit(signum);
}
static void output_cb(alpm_loglevel_t level, const char *fmt, va_list args)
{
if(strlen(fmt)) {
switch(level) {
case ALPM_LOG_ERROR: printf("error: "); break;
case ALPM_LOG_WARNING: printf("warning: "); break;
default: return;
}
vprintf(fmt, args);
}
}
static void checkpkgs(alpm_list_t *pkglist)
{
alpm_list_t *i, *j;
for(i = pkglist; i; i = alpm_list_next(i)) {
alpm_pkg_t *pkg = i->data;
alpm_list_t *unused = alpm_pkg_unused_deltas(pkg);
for(j = unused; j; j = alpm_list_next(j)) {
const char *delta = j->data;
printf("%s\n", delta);
}
alpm_list_free(unused);
}
}
static void checkdbs(alpm_list_t *dbnames) {
alpm_db_t *db = NULL;
alpm_list_t *i;
const alpm_siglevel_t level = ALPM_SIG_DATABASE | ALPM_SIG_DATABASE_OPTIONAL;
for(i = dbnames; i; i = alpm_list_next(i)) {
const char *dbname = i->data;
db = alpm_db_register_sync(handle, dbname, level);
if(db == NULL) {
fprintf(stderr, "error: could not register sync database '%s' (%s)\n",
dbname, alpm_strerror(alpm_errno(handle)));
continue;
}
checkpkgs(alpm_db_get_pkgcache(db));
}
}
static void usage(void) {
fprintf(stderr, "usage:\n");
fprintf(stderr,
"\t%s [-b <pacman db>] core extra ... : check the listed sync databases\n", BASENAME);
exit(1);
}
int main(int argc, char *argv[])
{
const char *dbpath = DBPATH;
enum _alpm_errno_t err;
int a = 1;
alpm_list_t *dbnames = NULL;
while(a < argc) {
if(strcmp(argv[a], "-b") == 0) {
if(++a < argc) {
dbpath = argv[a];
} else {
usage();
}
} else if(strcmp(argv[a], "-h") == 0 ||
strcmp(argv[a], "--help") == 0 ) {
usage();
} else {
dbnames = alpm_list_add(dbnames, argv[a]);
}
a++;
}
if(!dbnames) {
usage();
}
handle = alpm_initialize(ROOTDIR, dbpath, &err);
if(!handle) {
fprintf(stderr, "cannot initialize alpm: %s\n", alpm_strerror(err));
return 1;
}
alpm_option_set_logcb(handle, output_cb);
checkdbs(dbnames);
alpm_list_free(dbnames);
cleanup(0);
}
|