1.1 --- a/librazor/razor.c Thu May 14 05:55:19 2009 +0100
1.2 +++ b/librazor/razor.c Thu Jul 02 11:31:45 2009 +0100
1.3 @@ -1,6 +1,7 @@
1.4 /*
1.5 * Copyright (C) 2008 Kristian Høgsberg <krh@redhat.com>
1.6 * Copyright (C) 2008 Red Hat, Inc
1.7 + * Copyright (C) 2009 J. Ali Harlow <ali@juiblex.co.uk>
1.8 *
1.9 * This program is free software; you can redistribute it and/or modify
1.10 * it under the terms of the GNU General Public License as published by
1.11 @@ -34,6 +35,7 @@
1.12 #include <errno.h>
1.13 #include <ctype.h>
1.14 #include <fnmatch.h>
1.15 +#include <limits.h>
1.16 #include <assert.h>
1.17
1.18 #include "razor-internal.h"
1.19 @@ -410,6 +412,22 @@
1.20 pool = set->details_string_pool.data;
1.21 return &pool[package->license];
1.22
1.23 + case RAZOR_DETAIL_PREUNPROG:
1.24 + pool = set->string_pool.data;
1.25 + return &pool[package->preun.program];
1.26 +
1.27 + case RAZOR_DETAIL_PREUN:
1.28 + pool = set->string_pool.data;
1.29 + return &pool[package->preun.body];
1.30 +
1.31 + case RAZOR_DETAIL_POSTUNPROG:
1.32 + pool = set->string_pool.data;
1.33 + return &pool[package->postun.program];
1.34 +
1.35 + case RAZOR_DETAIL_POSTUN:
1.36 + pool = set->string_pool.data;
1.37 + return &pool[package->postun.body];
1.38 +
1.39 default:
1.40 fprintf(stderr, "type %u not found\n", type);
1.41 return NULL;
1.42 @@ -466,6 +484,60 @@
1.43 va_end (args);
1.44 }
1.45
1.46 +/**
1.47 + * razor_package_remove:
1.48 + * @set: a %razor_set
1.49 + * @package: a %razor_package
1.50 + * @root: the root into which the package is currently installed
1.51 + *
1.52 + * Removes an installed package.
1.53 + **/
1.54 +RAZOR_EXPORT int
1.55 +razor_package_remove(struct razor_set *set, struct razor_package *package,
1.56 + const char *root)
1.57 +{
1.58 + struct razor_file_iterator *fi;
1.59 + struct razor_package_iterator *pi;
1.60 + struct razor_package *p;
1.61 + char buffer[PATH_MAX];
1.62 + const char *name, *program, *script;
1.63 + int retval = 0, count;
1.64 +
1.65 + razor_package_get_details(set, package,
1.66 + RAZOR_DETAIL_PREUNPROG, &program,
1.67 + RAZOR_DETAIL_PREUN, &script,
1.68 + RAZOR_DETAIL_LAST);
1.69 +
1.70 + if (razor_run_script(root, RAZOR_PROPERTY_PREUN, program, script))
1.71 + return -1;
1.72 +
1.73 + fi = razor_file_iterator_create(set, package);
1.74 +
1.75 + while (!retval && razor_file_iterator_next(fi, &name)) {
1.76 + pi = razor_package_iterator_create_for_file(set, name);
1.77 + count = 0;
1.78 + while (razor_package_iterator_next(pi, &p, RAZOR_DETAIL_LAST))
1.79 + count++;
1.80 + razor_package_iterator_destroy(pi);
1.81 + if (count <= 1) {
1.82 + snprintf(buffer, sizeof buffer, "%s%s", root, name);
1.83 + retval = remove(buffer);
1.84 + }
1.85 + }
1.86 +
1.87 + razor_file_iterator_destroy(fi);
1.88 +
1.89 + if (retval)
1.90 + return retval;
1.91 +
1.92 + razor_package_get_details(set, package,
1.93 + RAZOR_DETAIL_POSTUNPROG, &program,
1.94 + RAZOR_DETAIL_POSTUN, &script,
1.95 + RAZOR_DETAIL_LAST);
1.96 +
1.97 + return razor_run_script(root, RAZOR_PROPERTY_POSTUN, program, script);
1.98 +}
1.99 +
1.100 RAZOR_EXPORT const char *
1.101 razor_property_relation_to_string(struct razor_property *p)
1.102 {