2009-09-18 15:59:52 -04:00
|
|
|
/*
|
|
|
|
* cleanupdelta.c : return list of unused delta in a given sync database
|
|
|
|
*
|
2011-01-05 23:45:15 -05:00
|
|
|
* Copyright (c) 2011 Pacman Development Team <pacman-dev@archlinux.org>
|
2009-09-18 15:59:52 -04:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include <alpm.h>
|
|
|
|
#include <alpm_list.h>
|
|
|
|
|
|
|
|
#define BASENAME "cleanupdelta"
|
|
|
|
|
2011-06-28 00:04:00 -04:00
|
|
|
alpm_handle_t *handle = NULL;
|
2011-06-03 16:46:06 -04:00
|
|
|
|
2009-09-18 15:59:52 -04:00
|
|
|
static void cleanup(int signum) {
|
2011-06-03 16:46:06 -04:00
|
|
|
if(handle && alpm_release(handle) == -1) {
|
|
|
|
fprintf(stderr, "error releasing alpm\n");
|
2009-09-18 15:59:52 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
exit(signum);
|
|
|
|
}
|
|
|
|
|
2011-06-28 00:41:07 -04:00
|
|
|
static void output_cb(alpm_loglevel_t level, const char *fmt, va_list args)
|
2009-09-18 15:59:52 -04:00
|
|
|
{
|
|
|
|
if(strlen(fmt)) {
|
|
|
|
switch(level) {
|
2011-07-01 12:01:38 -04:00
|
|
|
case ALPM_LOG_ERROR: printf("error: "); break;
|
|
|
|
case ALPM_LOG_WARNING: printf("warning: "); break;
|
|
|
|
//case ALPM_LOG_DEBUG: printf("debug: "); break;
|
2009-09-18 15:59:52 -04:00
|
|
|
default: return;
|
|
|
|
}
|
|
|
|
vprintf(fmt, args);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-10-11 21:20:06 -04:00
|
|
|
static void checkpkgs(alpm_list_t *pkglist)
|
2009-09-18 15:59:52 -04:00
|
|
|
{
|
|
|
|
alpm_list_t *i, *j;
|
|
|
|
for(i = pkglist; i; i = alpm_list_next(i)) {
|
2011-10-06 01:55:47 -04:00
|
|
|
alpm_pkg_t *pkg = i->data;
|
2009-09-18 15:59:52 -04:00
|
|
|
alpm_list_t *unused = alpm_pkg_unused_deltas(pkg);
|
|
|
|
for(j = unused; j; j = alpm_list_next(j)) {
|
2011-10-06 01:55:47 -04:00
|
|
|
const char *delta = j->data;
|
2009-09-18 15:59:52 -04:00
|
|
|
printf("%s\n", delta);
|
|
|
|
}
|
|
|
|
alpm_list_free(unused);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-19 20:15:16 -04:00
|
|
|
static void checkdbs(alpm_list_t *dbnames) {
|
2011-06-28 00:11:43 -04:00
|
|
|
alpm_db_t *db = NULL;
|
2009-09-18 15:59:52 -04:00
|
|
|
alpm_list_t *i;
|
2011-06-27 17:29:49 -04:00
|
|
|
const alpm_siglevel_t level = ALPM_SIG_DATABASE | ALPM_SIG_DATABASE_OPTIONAL;
|
2009-09-18 15:59:52 -04:00
|
|
|
|
|
|
|
for(i = dbnames; i; i = alpm_list_next(i)) {
|
2011-10-06 01:55:47 -04:00
|
|
|
const char *dbname = i->data;
|
2012-02-02 00:45:52 -05:00
|
|
|
db = alpm_register_syncdb(handle, dbname, level);
|
2009-09-18 15:59:52 -04:00
|
|
|
if(db == NULL) {
|
2011-09-19 20:15:16 -04:00
|
|
|
fprintf(stderr, "error: could not register sync database '%s' (%s)\n",
|
|
|
|
dbname, alpm_strerror(alpm_errno(handle)));
|
|
|
|
continue;
|
2009-09-18 15:59:52 -04:00
|
|
|
}
|
2011-02-25 09:22:09 -05:00
|
|
|
checkpkgs(alpm_db_get_pkgcache(db));
|
2009-09-18 15:59:52 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2010-10-11 21:20:06 -04:00
|
|
|
static void usage(void) {
|
2009-09-18 15:59:52 -04:00
|
|
|
fprintf(stderr, "usage:\n");
|
|
|
|
fprintf(stderr,
|
|
|
|
"\t%s [-b <pacman db>] core extra ... : check the listed sync databases\n", BASENAME);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2010-10-11 21:20:06 -04:00
|
|
|
int main(int argc, char *argv[])
|
2009-09-18 15:59:52 -04:00
|
|
|
{
|
2011-05-04 16:48:47 -04:00
|
|
|
const char *dbpath = DBPATH;
|
2011-10-28 22:03:24 -04:00
|
|
|
alpm_errno_t err;
|
2009-09-18 15:59:52 -04:00
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
2011-06-03 16:46:06 -04:00
|
|
|
handle = alpm_initialize(ROOTDIR, dbpath, &err);
|
|
|
|
if(!handle) {
|
|
|
|
fprintf(stderr, "cannot initialize alpm: %s\n", alpm_strerror(err));
|
2011-03-20 20:45:57 -04:00
|
|
|
return 1;
|
2009-09-18 15:59:52 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* let us get log messages from libalpm */
|
2011-06-07 14:15:43 -04:00
|
|
|
alpm_option_set_logcb(handle, output_cb);
|
2009-09-18 15:59:52 -04:00
|
|
|
|
2011-09-19 20:15:16 -04:00
|
|
|
checkdbs(dbnames);
|
2009-09-18 15:59:52 -04:00
|
|
|
alpm_list_free(dbnames);
|
|
|
|
|
|
|
|
cleanup(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* vim: set ts=2 sw=2 noet: */
|