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 <limits.h> /* PATH_MAX */
28 #include <alpm_list.h>
30 #define BASENAME "cleanupdelta"
32 alpm_handle_t
*handle
= NULL
;
34 static void cleanup(int signum
) {
35 if(handle
&& alpm_release(handle
) == -1) {
36 fprintf(stderr
, "error releasing alpm\n");
42 static void output_cb(pmloglevel_t level
, const char *fmt
, va_list args
)
46 case PM_LOG_ERROR
: printf("error: "); break;
47 case PM_LOG_WARNING
: printf("warning: "); break;
48 //case PM_LOG_DEBUG: printf("debug: "); break;
56 static void checkpkgs(alpm_list_t
*pkglist
)
59 for(i
= pkglist
; i
; i
= alpm_list_next(i
)) {
60 pmpkg_t
*pkg
= alpm_list_getdata(i
);
61 alpm_list_t
*unused
= alpm_pkg_unused_deltas(pkg
);
62 for(j
= unused
; j
; j
= alpm_list_next(j
)) {
63 char *delta
= alpm_list_getdata(j
);
64 printf("%s\n", delta
);
66 alpm_list_free(unused
);
70 static void checkdbs(const char *dbpath
, alpm_list_t
*dbnames
) {
71 char syncdbpath
[PATH_MAX
];
75 for(i
= dbnames
; i
; i
= alpm_list_next(i
)) {
76 char *dbname
= alpm_list_getdata(i
);
77 snprintf(syncdbpath
, PATH_MAX
, "%s/sync/%s", dbpath
, dbname
);
78 db
= alpm_db_register_sync(handle
, dbname
, PM_PGP_VERIFY_OPTIONAL
);
80 fprintf(stderr
, "error: could not register sync database (%s)\n",
81 alpm_strerror(alpm_errno(handle
)));
84 checkpkgs(alpm_db_get_pkgcache(db
));
89 static void usage(void) {
90 fprintf(stderr
, "usage:\n");
92 "\t%s [-b <pacman db>] core extra ... : check the listed sync databases\n", BASENAME
);
96 int main(int argc
, char *argv
[])
98 const char *dbpath
= DBPATH
;
101 alpm_list_t
*dbnames
= NULL
;
104 if(strcmp(argv
[a
], "-b") == 0) {
110 } else if(strcmp(argv
[a
], "-h") == 0 ||
111 strcmp(argv
[a
], "--help") == 0 ) {
114 dbnames
= alpm_list_add(dbnames
, argv
[a
]);
123 handle
= alpm_initialize(ROOTDIR
, dbpath
, &err
);
125 fprintf(stderr
, "cannot initialize alpm: %s\n", alpm_strerror(err
));
129 /* let us get log messages from libalpm */
130 alpm_option_set_logcb(handle
, output_cb
);
132 checkdbs(dbpath
,dbnames
);
133 alpm_list_free(dbnames
);
138 /* vim: set ts=2 sw=2 noet: */