1
0
mirror of https://github.com/moparisthebest/pacman synced 2024-08-13 17:03:46 -04:00
pacman/src/util/cleanupdelta.c
Dan McGee b488f229d2 ALPM API adjustments for sanity and consistency
This makes several small adjustments to our exposed method names, and in
one case, parameters. The justification here is to make methods less odd
in their naming convention. If a method takes an alpm_db_t argument, the
method should be named 'alpm_db_*', but perhaps more importantly, if it
doesn't take a database as the first parameter, it should not.

Summary of changes:

    alpm_db_register_sync   -> alpm_register_syncdb
    alpm_db_unregister_all  -> alpm_unregister_all_syncdbs
    alpm_option_get_localdb -> aplpm_get_localdb
    alpm_option_get_syncdbs -> aplpm_get_syncdbs
    alpm_db_readgroup       -> alpm_db_get_group
    alpm_db_set_pkgreason   -> alpm_pkg_set_reason

All methods keep the same argument list except for alpm_pkg_set_reason;
there we drop the 'handle' argument as it can be retrieved from the
passed in package object.

Signed-off-by: Dan McGee <dan@archlinux.org>
2012-02-06 05:49:52 -06:00

135 lines
3.2 KiB
C

/*
* cleanupdelta.c : return list of unused delta in a given sync database
*
* Copyright (c) 2011 Pacman Development Team <pacman-dev@archlinux.org>
*
* 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"
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;
//case ALPM_LOG_DEBUG: printf("debug: "); 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_register_syncdb(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;
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;
}
/* let us get log messages from libalpm */
alpm_option_set_logcb(handle, output_cb);
checkdbs(dbnames);
alpm_list_free(dbnames);
cleanup(0);
}
/* vim: set ts=2 sw=2 noet: */