diff options
author | ewt <devnull@localhost> | 1996-01-05 18:12:55 +0000 |
---|---|---|
committer | ewt <devnull@localhost> | 1996-01-05 18:12:55 +0000 |
commit | fc3166e80dd0787b5a9e7d1ee0a58e198faf54af (patch) | |
tree | 142b70a6896295f2781228e282ad9a2bcb6766d4 /lib/uninstall.c | |
parent | 7558c83bdb60fbbdb07a44462a1625ec51d53d17 (diff) | |
download | rpm-fc3166e80dd0787b5a9e7d1ee0a58e198faf54af.tar.gz rpm-fc3166e80dd0787b5a9e7d1ee0a58e198faf54af.tar.bz2 rpm-fc3166e80dd0787b5a9e7d1ee0a58e198faf54af.zip |
Initial revision
CVS patchset: 132
CVS date: 1996/01/05 18:12:55
Diffstat (limited to 'lib/uninstall.c')
-rw-r--r-- | lib/uninstall.c | 82 |
1 files changed, 82 insertions, 0 deletions
diff --git a/lib/uninstall.c b/lib/uninstall.c new file mode 100644 index 000000000..33fb8bb85 --- /dev/null +++ b/lib/uninstall.c @@ -0,0 +1,82 @@ +#include <alloca.h> +#include <stdlib.h> +#include <string.h> + +#include "rpmerr.h" +#include "rpmlib.h" + +int rpmRemovePackage(char * prefix, rpmdb db, unsigned int offset, int test) { + Header h; + int i; + int count; + char * rmmess; + char * fnbuffer = NULL; + int fnbuffersize = 0; + int prefixLength = strlen(prefix); + char ** fileList; + int type; + char * fileStatesList; + + h = rpmdbGetRecord(db, offset); + if (!h) { + error(RPMERR_DBCORRUPT, "cannot read header at %d for uninstall", + offset); + return 0; + } + + /* dependency checking should go in here */ + + if (test) { + rmmess = "would remove"; + } else { + rmmess = "removing"; + } + + message(MESS_DEBUG, "%s files test = %d\n", rmmess, test); + if (!getEntry(h, RPMTAG_FILENAMES, &type, (void **) &fileList, + &count)) { + puts("(contains no files)"); + } else { + if (prefix[0]) { + fnbuffersize = 1024; + fnbuffer = alloca(fnbuffersize); + } + + getEntry(h, RPMTAG_FILESTATES, &type, + (void **) &fileStatesList, &count); + + for (i = 0; i < count; i++) { + if (prefix[0]) { + if ((strlen(fileList[i]) + prefixLength + 1) > fnbuffersize) { + fnbuffersize = (strlen(fileList[i]) + prefixLength) * 2; + fnbuffer = alloca(fnbuffersize); + } + strcpy(fnbuffer, ""); + strcat(fnbuffer, "/"); + strcpy(fnbuffer, fileList[i]); + } else { + fnbuffer = fileList[i]; + } + + switch (fileStatesList[i]) { + case RPMFILE_STATE_REPLACED: + message(MESS_DEBUG, "%s has already been replaced\n", + fileList[i]); + break; + + case RPMFILE_STATE_NORMAL: + message(MESS_DEBUG, "%s - %s\n", fileList[i], rmmess); + break; + } + } + + free(fileList); + } + + message(MESS_DEBUG, "%s database entry\n", rmmess); + if (!test) + rpmdbRemove(db, offset, 0); + + return 1; +} + |