2 * cleanupdelta.c : return list of unused delta in a given sync database
4 * Copyright (c) 2011 Pacman Development Team <pacman-dev@archlinux.org>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
25 #include <alpm_list.h>
27 #define BASENAME "cleanupdelta"
29 alpm_handle_t
*handle
= NULL
;
31 static void cleanup(int signum
) {
32 if(handle
&& alpm_release(handle
) == -1) {
33 fprintf(stderr
, "error releasing alpm\n");
39 static void output_cb(alpm_loglevel_t level
, const char *fmt
, va_list args
)
43 case ALPM_LOG_ERROR
: printf("error: "); break;
44 case ALPM_LOG_WARNING
: printf("warning: "); break;
45 //case ALPM_LOG_DEBUG: printf("debug: "); break;
53 static void checkpkgs(alpm_list_t
*pkglist
)
56 for(i
= pkglist
; i
; i
= alpm_list_next(i
)) {
57 alpm_pkg_t
*pkg
= i
->data
;
58 alpm_list_t
*unused
= alpm_pkg_unused_deltas(pkg
);
59 for(j
= unused
; j
; j
= alpm_list_next(j
)) {
60 const char *delta
= j
->data
;
61 printf("%s\n", delta
);
63 alpm_list_free(unused
);
67 static void checkdbs(alpm_list_t
*dbnames
) {
70 const alpm_siglevel_t level
= ALPM_SIG_DATABASE
| ALPM_SIG_DATABASE_OPTIONAL
;
72 for(i
= dbnames
; i
; i
= alpm_list_next(i
)) {
73 const char *dbname
= i
->data
;
74 db
= alpm_register_syncdb(handle
, dbname
, level
);
76 fprintf(stderr
, "error: could not register sync database '%s' (%s)\n",
77 dbname
, alpm_strerror(alpm_errno(handle
)));
80 checkpkgs(alpm_db_get_pkgcache(db
));
85 static void usage(void) {
86 fprintf(stderr
, "usage:\n");
88 "\t%s [-b <pacman db>] core extra ... : check the listed sync databases\n", BASENAME
);
92 int main(int argc
, char *argv
[])
94 const char *dbpath
= DBPATH
;
97 alpm_list_t
*dbnames
= NULL
;
100 if(strcmp(argv
[a
], "-b") == 0) {
106 } else if(strcmp(argv
[a
], "-h") == 0 ||
107 strcmp(argv
[a
], "--help") == 0 ) {
110 dbnames
= alpm_list_add(dbnames
, argv
[a
]);
119 handle
= alpm_initialize(ROOTDIR
, dbpath
, &err
);
121 fprintf(stderr
, "cannot initialize alpm: %s\n", alpm_strerror(err
));
125 /* let us get log messages from libalpm */
126 alpm_option_set_logcb(handle
, output_cb
);
129 alpm_list_free(dbnames
);
134 /* vim: set ts=2 sw=2 noet: */