From b696bb30932f309838bc67f6bd22b755ef41af79 Mon Sep 17 00:00:00 2001 From: ewt Date: Mon, 8 Jan 1996 19:16:46 +0000 Subject: [PATCH] added support for retrieving pre/post uninstalls from database CVS patchset: 165 CVS date: 1996/01/08 19:16:46 --- lib/oldrpmdb.h | 33 ++++++++++++++++++++++----------- oldrpmdb.c | 41 +++++++++++++++++++++++++++++++++++++++-- 2 files changed, 61 insertions(+), 13 deletions(-) diff --git a/lib/oldrpmdb.h b/lib/oldrpmdb.h index 985634c..675ac28 100644 --- a/lib/oldrpmdb.h +++ b/lib/oldrpmdb.h @@ -5,11 +5,14 @@ #include "oldheader.h" -typedef enum { +typedef enum + { RPMDB_NONE, RPMDB_GDBM_ERROR, RPMDB_NO_MEMORY -} rpm_error; + } +rpm_error; -struct oldrpmdb { +struct oldrpmdb + { GDBM_FILE packages; GDBM_FILE nameIndex; GDBM_FILE pathIndex; @@ -18,20 +21,23 @@ struct oldrpmdb { GDBM_FILE postIndex; rpm_error rpmdbError; gdbm_error gdbmError; -}; + }; -enum oldrpmdbFreeType { +enum oldrpmdbFreeType + { RPMDB_NOFREE, RPMDB_FREENAME, RPMDB_FREEALL -}; + }; -struct oldrpmdbLabel { +struct oldrpmdbLabel + { char *name, *version, *release; enum oldrpmdbFreeType freeType; struct oldrpmdbLabel *next; int fileNumber; /* -1 means invalid */ -}; + }; -struct oldrpmdbPackageInfo { +struct oldrpmdbPackageInfo + { char *name, *version, *release; char *labelstr; unsigned int installTime, buildTime; @@ -44,7 +50,7 @@ struct oldrpmdbPackageInfo { char *copyright; unsigned int fileCount; struct oldrpmFileInfo *files; -}; + }; #define RPMDB_READER 1 @@ -55,7 +61,12 @@ struct oldrpmdbLabel *oldrpmdbFindPackagesByFile (struct oldrpmdb *oldrpmdb, cha struct oldrpmdbLabel *oldrpmdbFindPackagesByLabel (struct oldrpmdb *oldrpmdb, struct oldrpmdbLabel label); -char *oldrpmdbGetPackageGroup (struct oldrpmdb *oldrpmdb, struct oldrpmdbLabel label); +char *oldrpmdbGetPackageGroup (struct oldrpmdb *oldrpmdb, + struct oldrpmdbLabel label); +char *oldrpmdbGetPackagePostun (struct oldrpmdb *oldrpmdb, + struct oldrpmdbLabel label); +char *oldrpmdbGetPackagePreun (struct oldrpmdb *oldrpmdb, + struct oldrpmdbLabel label); char *oldrpmdbGetPackageGif (struct oldrpmdb *oldrpmdb, struct oldrpmdbLabel label, int *size); int oldrpmdbGetPackageInfo (struct oldrpmdb *oldrpmdb, struct oldrpmdbLabel label, diff --git a/oldrpmdb.c b/oldrpmdb.c index bf4d61a..0d188c8 100644 --- a/oldrpmdb.c +++ b/oldrpmdb.c @@ -10,6 +10,9 @@ static int labelstrlistToLabelList(char * str, int length, struct oldrpmdbLabel ** list); +static char * getScript(char * which, struct oldrpmdb *oldrpmdb, + struct oldrpmdbLabel label); + static char * prefix = "/var/lib/rpm"; char * oldrpmdbLabelToLabelstr(struct oldrpmdbLabel label, int withFileNum) { @@ -381,9 +384,43 @@ char * oldrpmdbGetPackageGroup(struct oldrpmdb * oldrpmdb, struct oldrpmdbLabel return g; } +static char * getScript(char * which, struct oldrpmdb *oldrpmdb, + struct oldrpmdbLabel label) { + datum key, rec; + char * labelstr; + + labelstr = oldrpmdbLabelToLabelstr(label, 0); + labelstr = realloc(labelstr, strlen(labelstr) + 10); + strcat(labelstr, ":"); + strcat(labelstr, which); + + key.dptr = labelstr; + key.dsize = strlen(labelstr); + + rec = gdbm_fetch(oldrpmdb->postIndex, key); + free(labelstr); + if (!rec.dptr) { + return NULL; + } + + printf("found for: %s\n", labelstr); + + return rec.dptr; +} + +char *oldrpmdbGetPackagePostun (struct oldrpmdb *oldrpmdb, + struct oldrpmdbLabel label) { + return getScript("post", oldrpmdb, label); +} + +char *oldrpmdbGetPackagePreun (struct oldrpmdb *oldrpmdb, + struct oldrpmdbLabel label) { + return getScript("pre", oldrpmdb, label); +} + /* Returns NULL on error or if no icon exists */ -char * oldrpmdbGetPackageGif(struct oldrpmdb * oldrpmdb, struct oldrpmdbLabel label, - int * size) { +char * oldrpmdbGetPackageGif(struct oldrpmdb * oldrpmdb, + struct oldrpmdbLabel label, int * size) { datum key, rec; char * labelstr; -- 2.7.4