diff -r e45f50e940b6 -r a3e288343fe7 librazor/razor.c --- a/librazor/razor.c Thu May 14 05:55:19 2009 +0100 +++ b/librazor/razor.c Thu Jul 02 11:31:03 2009 +0100 @@ -1,6 +1,7 @@ /* * Copyright (C) 2008 Kristian Høgsberg * Copyright (C) 2008 Red Hat, Inc + * Copyright (C) 2009 J. Ali Harlow * * 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 @@ -34,6 +35,7 @@ #include #include #include +#include #include #include "razor-internal.h" @@ -410,6 +412,22 @@ pool = set->details_string_pool.data; return &pool[package->license]; + case RAZOR_DETAIL_PREUNPROG: + pool = set->string_pool.data; + return &pool[package->preun.program]; + + case RAZOR_DETAIL_PREUN: + pool = set->string_pool.data; + return &pool[package->preun.body]; + + case RAZOR_DETAIL_POSTUNPROG: + pool = set->string_pool.data; + return &pool[package->postun.program]; + + case RAZOR_DETAIL_POSTUN: + pool = set->string_pool.data; + return &pool[package->postun.body]; + default: fprintf(stderr, "type %u not found\n", type); return NULL; @@ -466,6 +484,60 @@ va_end (args); } +/** + * razor_package_remove: + * @set: a %razor_set + * @package: a %razor_package + * @root: the root into which the package is currently installed + * + * Removes an installed package. + **/ +RAZOR_EXPORT int +razor_package_remove(struct razor_set *set, struct razor_package *package, + const char *root) +{ + struct razor_file_iterator *fi; + struct razor_package_iterator *pi; + struct razor_package *p; + char buffer[PATH_MAX]; + const char *name, *program, *script; + int retval = 0, count; + + razor_package_get_details(set, package, + RAZOR_DETAIL_PREUNPROG, &program, + RAZOR_DETAIL_PREUN, &script, + RAZOR_DETAIL_LAST); + + if (razor_run_script(root, RAZOR_PROPERTY_PREUN, program, script)) + return -1; + + fi = razor_file_iterator_create(set, package); + + while (!retval && razor_file_iterator_next(fi, &name)) { + pi = razor_package_iterator_create_for_file(set, name); + count = 0; + while (razor_package_iterator_next(pi, &p, RAZOR_DETAIL_LAST)) + count++; + razor_package_iterator_destroy(pi); + if (count <= 1) { + snprintf(buffer, sizeof buffer, "%s%s", root, name); + retval = remove(buffer); + } + } + + razor_file_iterator_destroy(fi); + + if (retval) + return retval; + + razor_package_get_details(set, package, + RAZOR_DETAIL_POSTUNPROG, &program, + RAZOR_DETAIL_POSTUN, &script, + RAZOR_DETAIL_LAST); + + return razor_run_script(root, RAZOR_PROPERTY_POSTUN, program, script); +} + RAZOR_EXPORT const char * razor_property_relation_to_string(struct razor_property *p) {