From 13accd8fd9c587ef495e1fe7247f2f9e40abd3a9 Mon Sep 17 00:00:00 2001 From: Paul Nasrat Date: Mon, 30 Jan 2006 19:40:06 +0000 Subject: Remove genhdlist --- utils/Makefile | 14 +- utils/genhdlist.c | 617 ------------------------------------------------------ 2 files changed, 2 insertions(+), 629 deletions(-) delete mode 100644 utils/genhdlist.c diff --git a/utils/Makefile b/utils/Makefile index b05a0bd2c..313f89723 100644 --- a/utils/Makefile +++ b/utils/Makefile @@ -19,7 +19,7 @@ endif everything: $(TARGET) -all: modlist moddeps snarffont mapshdr readmap genhdlist +all: modlist moddeps snarffont mapshdr readmap modlist: modlist.o moduleinfo.o $(CC) $(LDFLAGS) -o modlist modlist.o moduleinfo.o $(LOADLIBES) @@ -42,21 +42,11 @@ md5.o: md5.c md5.h hash.o : hash.c $(CC) $(RPMCFLAGS) -c -o $@ $< -# XXX rpm needs to be fixed not to have const functions. Until then, -# -Wno-return-type -genhdlist.o : genhdlist.c - $(CC) $(RPMCFLAGS) -Wno-return-type -c -o $@ $< - -genhdlist: genhdlist.o hash.o - $(CC) $(LDFLAGS) -o genhdlist $^ \ - -lrpm -lrpmdb -lrpmio -lbz2 -lz -lpopt -lelf -lpthread -lbeecrypt - depends: install: all mkdir -p $(DESTDIR)/usr/bin mkdir -p $(DESTDIR)/$(RUNTIMEDIR) - install -m755 genhdlist $(DESTDIR)/$(RUNTIMEDIR) install -m755 trimmodalias $(DESTDIR)/$(RUNTIMEDIR) install -m755 trimpciids $(DESTDIR)/$(RUNTIMEDIR) install -m755 moddeps $(DESTDIR)/$(RUNTIMEDIR) @@ -66,7 +56,7 @@ install: all install -m755 mapshdr $(DESTDIR)/$(RUNTIMEDIR) clean: - rm -f modlist moddeps snarffont genhdlist mapshdr readmap \ + rm -f modlist moddeps snarffont mapshdr readmap \ moduledeps.c moduleinfo.c .depend *.o depend: diff --git a/utils/genhdlist.c b/utils/genhdlist.c deleted file mode 100644 index 4c8a7a3e8..000000000 --- a/utils/genhdlist.c +++ /dev/null @@ -1,617 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "hash.h" - -#define FILENAME_TAG 1000000 -#define FILESIZE_TAG 1000001 -#define CDNUM_TAG 1000002 -#define ORDER_TAG 1000003 -#define MATCHER_TAG 1000004 - -void expandFilelist(Header h); -void compressFilelist(Header h); - -struct onePackageInfo { - char * name; - char * arch; -}; - -int pkgInfoCmp(const void * a, const void * b) { - const struct onePackageInfo * one = a; - const struct onePackageInfo * two = b; - int i; - - i = strcmp(one->name, two->name); - if (i) return i; - - return strcmp(one->arch, two->arch); -} - -int tagsInList2[] = { - RPMTAG_FILESIZES, RPMTAG_FILEMODES, RPMTAG_FILEMD5S, RPMTAG_FILELINKTOS, - RPMTAG_FILEFLAGS, RPMTAG_FILELANGS, - RPMTAG_DIRNAMES, RPMTAG_DIRINDEXES, RPMTAG_BASENAMES, - -1 -}; - -struct onePackageInfo * pkgList; -int pkgListItems = 0; -int pkgListAlloced = 0; -char ** depOrder = NULL; -hashTable requireTable; - -/* Acts like fgets() except allocates buffer internally. - * Responsibility of consumer to free() buffer. - */ -char * _fgets(FILE *fptr) { - long oPos, ePos; - int c; - long size; - char * buf; - - /* Get original file position and save aside */ - if((oPos = ftell(fptr)) == -1) { - perror("Could not get file position:"); - return NULL; - } - - /* "Seek" to next EOL or EOF */ - while((c = fgetc(fptr)) != '\n' && c != EOF); - - /* Get current file position */ - if((ePos = ftell(fptr)) == -1) { - perror("Could not get file position:"); - return NULL; - } - - /* Calculate size of buffer and allocate */ - size = ePos - oPos; - if(size == 0) return NULL; /* Nothing to do (probably EOF after EOL) */ - buf = (char *) malloc(sizeof(buf)*size + 1); - if(buf == NULL) { - perror("Could not allocate buffer for _fgets():"); - return NULL; - } - - /* Seek to beggining and read in buffer */ - if(fseek(fptr, oPos, SEEK_SET) == -1) { - perror("Could not seek to string begining in _fgets():"); - free(buf); - return NULL; - } - if(fread(buf, size, 1, fptr) != 1) { - perror("Could not read string into buffer in _fgets():"); - free(buf); - return NULL; - } - buf[size - 1] = '\0'; - - return buf; -} - -/* make sure its -- */ -int sanityCheckDepOrderLine(char *line) { - char *r, *v; - - - r = strrchr(line, '-'); - if (!r) - return -1; - - v = strrchr(r, '-'); - if (!v) - return -1; - - return 0; - -} - -/* mmmm... linear search */ -int getOrder (char * fn) -{ - char *p; - int i; - - if (!depOrder || !depOrder[0] || !depOrder[0][0]) { - return -1; - } - - i = 0; - p = depOrder[i]; - while (p && *p && strncmp (fn, p, strlen(p))) { - p = depOrder[++i]; - } - - if (p) { - return i; - } - - fprintf (stderr, "WARNING: ordering not found for %s\n", fn); - - return -1; -} - -int onePrePass(const char * dirName) { - struct dirent * ent; - DIR * dir; - char * subdir = strdup(dirName); - FD_t fd; - int rc; - Header h; - char ** requires; - int c; - rpmts ts = rpmtsCreate(); - rpmtsSetRootDir(ts, "/"); - rpmtsSetVSFlags(ts, ~RPMVSF_NOHDRCHK); - rpmtsCloseDB(ts); - - dir = opendir(subdir); - if (!dir) { - fprintf(stderr,"error opening directory %s: %s\n", subdir, - strerror(errno)); - return 1; - } - - if (chdir(subdir) == -1) abort(); - - errno = 0; - ent = readdir(dir); - if (errno) { - perror("readdir"); - return 1; - } - - while (ent) { - int i = strlen (ent->d_name); - - if (i > 4 && strcasecmp (&ent->d_name [i - 4], ".rpm") == 0) { - fd = Fopen(ent->d_name, "r"); - - if (!fd) { - fprintf(stderr, "Error opening '%s': %s\n", ent->d_name, - strerror(errno)); - exit(1); - } - - rc = rpmReadPackageFile(ts, fd, ent->d_name, &h); - - if (!rc) { - if (headerGetEntry(h, RPMTAG_REQUIRENAME, NULL, - (void **) &requires, &c)) { - while (c--) - if (*requires[c] == '/') - htAddToTable(requireTable, requires[c], "."); - } - - headerFree(h); - /* XXX free requires */ - } - - Fclose(fd); - } - - errno = 0; - ent = readdir(dir); - if (errno) { - perror("readdir"); - return 1; - } - } - - closedir(dir); - - return 0; -} - -int onePass(FD_t outfd, FD_t out2fd, const char * dirName, int cdNum, - int doSplit) { - FD_t fd; - struct dirent * ent; - char * subdir = strdup(dirName); - int errno; - Header h, nh, h2 = NULL; - int rc; - int_32 size; - DIR * dir; - struct stat sb; - int_32 * fileSizes; - int fileCount; - int order = -1; - char ** newFileList, ** fileNames; - uint_32 * newFileFlags, * fileFlags; - int newFileListCount = 0; - int marker = time(NULL); /* good enough counter; we'll increment it */ - rpmts ts = rpmtsCreate(); - rpmtsSetRootDir(ts, "/"); - rpmtsSetVSFlags(ts, ~RPMVSF_NOHDRCHK); - rpmtsCloseDB(ts); - - dir = opendir(subdir); - if (!dir) { - fprintf(stderr,"error opening directory %s: %s\n", subdir, - strerror(errno)); - return 1; - } - - if (chdir(subdir) == -1) abort(); - - errno = 0; - ent = readdir(dir); - if (errno) { - perror("readdir"); - return 1; - } - - while (ent) { - int i = strlen (ent->d_name); - if (i > 4 && strcasecmp (&ent->d_name [i - 4], ".rpm") == 0) { - fd = Fopen(ent->d_name, "r"); - - if (!fd) { - perror("open"); - exit(1); - } - - if (stat(ent->d_name, &sb)) { - perror("stat"); - exit(1); - } - size = sb.st_size; - - rc = rpmReadPackageFile(ts, fd, ent->d_name, &h); - - if (!rc) { - if (pkgListItems == pkgListAlloced) { - pkgListAlloced += 100; - pkgList = realloc(pkgList, - sizeof(*pkgList) * pkgListAlloced); - } - - headerGetEntry(h, RPMTAG_NAME, NULL, - (void **) &pkgList[pkgListItems].name, NULL); - headerGetEntry(h, RPMTAG_ARCH, NULL, - (void **) &pkgList[pkgListItems].arch, NULL); - - pkgList[pkgListItems].name = strdup(pkgList[pkgListItems].name); - pkgList[pkgListItems].arch = strdup(pkgList[pkgListItems].arch); - pkgListItems++; - - headerRemoveEntry(h, RPMTAG_POSTIN); - headerRemoveEntry(h, RPMTAG_POSTUN); - headerRemoveEntry(h, RPMTAG_PREIN); - headerRemoveEntry(h, RPMTAG_PREUN); - headerRemoveEntry(h, RPMTAG_FILEUSERNAME); - headerRemoveEntry(h, RPMTAG_FILEGROUPNAME); - headerRemoveEntry(h, RPMTAG_FILEVERIFYFLAGS); - headerRemoveEntry(h, RPMTAG_FILERDEVS); - headerRemoveEntry(h, RPMTAG_FILEMTIMES); - headerRemoveEntry(h, RPMTAG_FILEDEVICES); - headerRemoveEntry(h, RPMTAG_FILEINODES); - headerRemoveEntry(h, RPMTAG_TRIGGERSCRIPTS); - headerRemoveEntry(h, RPMTAG_TRIGGERVERSION); - headerRemoveEntry(h, RPMTAG_TRIGGERFLAGS); - headerRemoveEntry(h, RPMTAG_TRIGGERNAME); - headerRemoveEntry(h, RPMTAG_CHANGELOGTIME); - headerRemoveEntry(h, RPMTAG_CHANGELOGNAME); - headerRemoveEntry(h, RPMTAG_CHANGELOGTEXT); - headerRemoveEntry(h, RPMTAG_ICON); - headerRemoveEntry(h, RPMTAG_GIF); - headerRemoveEntry(h, RPMTAG_VENDOR); - headerRemoveEntry(h, RPMTAG_EXCLUDE); - headerRemoveEntry(h, RPMTAG_EXCLUSIVE); - headerRemoveEntry(h, RPMTAG_DISTRIBUTION); - headerRemoveEntry(h, RPMTAG_VERIFYSCRIPT); - - /* new header sigs */ - headerRemoveEntry(h, RPMTAG_SIGSIZE); - headerRemoveEntry(h, RPMTAG_SIGGPG); - headerRemoveEntry(h, RPMTAG_SIGPGP); - - /* other stuff we don't need - msw */ - headerRemoveEntry(h, RPMTAG_PACKAGER); - headerRemoveEntry(h, RPMTAG_LICENSE); - headerRemoveEntry(h, RPMTAG_BUILDTIME); - headerRemoveEntry(h, RPMTAG_BUILDHOST); - headerRemoveEntry(h, RPMTAG_RPMVERSION); - headerRemoveEntry(h, RPMTAG_POSTINPROG); - headerRemoveEntry(h, RPMTAG_POSTUNPROG); - headerRemoveEntry(h, RPMTAG_PREINPROG); - headerRemoveEntry(h, RPMTAG_PREUNPROG); - headerRemoveEntry(h, RPMTAG_COOKIE); - headerRemoveEntry(h, RPMTAG_OPTFLAGS); - headerRemoveEntry(h, RPMTAG_PAYLOADFORMAT); - headerRemoveEntry(h, RPMTAG_PAYLOADCOMPRESSOR); - headerRemoveEntry(h, RPMTAG_PAYLOADFLAGS); - - headerAddEntry(h, FILENAME_TAG, RPM_STRING_TYPE, ent->d_name, 1); - headerAddEntry(h, FILESIZE_TAG, RPM_INT32_TYPE, - &size, 1); - - /* Recaclulate the package size based on a 4k block size */ - if (headerGetEntry(h, RPMTAG_FILESIZES, NULL, - (void **) &fileSizes, &fileCount)) { - int fileNum; - int newSize = 0; - int * p; - - for (fileNum = 0; fileNum < fileCount; fileNum++) - newSize += ((fileSizes[fileNum] + 4093) / 4096) * 4096; - - headerGetEntry(h, RPMTAG_SIZE, NULL, (void **) &p, NULL); - - headerRemoveEntry(h, RPMTAG_SIZE); - headerAddEntry(h, RPMTAG_SIZE, RPM_INT32_TYPE, - &newSize, 1); - } - - if (cdNum > -1) - headerAddEntry(h, CDNUM_TAG, RPM_INT32_TYPE, - &cdNum, 1); - - if ((order = getOrder (ent->d_name)) > -1) { - headerAddEntry(h, ORDER_TAG, RPM_INT32_TYPE, - &order, 1); - } - - expandFilelist(h); - newFileList = NULL; - if (headerGetEntry(h, RPMTAG_OLDFILENAMES, NULL, - (void **) &fileNames, &fileCount)) { - headerGetEntry(h, RPMTAG_FILEFLAGS, NULL, - (void **) &fileFlags, NULL); - - newFileList = malloc(sizeof(*newFileList) * fileCount); - newFileFlags = malloc(sizeof(*newFileList) * fileCount); - newFileListCount = 0; - - for (i = 0; i < fileCount; i++) { - if (htInTable(requireTable, fileNames[i], ".")) { - newFileList[newFileListCount] = strdup(fileNames[i]); - newFileFlags[newFileListCount] = fileFlags[i]; - newFileListCount++; - } - } - - if (!newFileListCount) { - free(newFileList); - free(newFileFlags); - newFileList = NULL; - } - - /* XXX free fileNames */ - } - compressFilelist(h); - - if (doSplit) { - h2 = headerNew(); - for (i = 0; tagsInList2[i] > -1; i++) { - int_32 type, c; - void * p; - - if (headerGetEntry(h, tagsInList2[i], &type, &p, &c)) { - headerAddEntry(h2, tagsInList2[i], type, p, c); - headerRemoveEntry(h, tagsInList2[i]); - } - - /* XXX need to headerFreeData */ - } - } - - if (newFileList) { - headerAddEntry(h, RPMTAG_OLDFILENAMES, - RPM_STRING_ARRAY_TYPE, - newFileList, newFileListCount); - headerAddEntry(h, RPMTAG_FILEFLAGS, - RPM_INT32_TYPE, - &newFileFlags, newFileListCount); - - compressFilelist(h); - while (newFileListCount--) { - free(newFileList[newFileListCount]); - } - free(newFileList); - free(newFileFlags); - newFileList = NULL; - } - - if (doSplit) { - headerAddEntry(h, MATCHER_TAG, RPM_INT32_TYPE, &marker, 1); - headerAddEntry(h2, MATCHER_TAG, RPM_INT32_TYPE, &marker, 1); - marker++; - } - - nh = headerCopy (h); - headerWrite(outfd, nh, HEADER_MAGIC_YES); - if (doSplit) - headerWrite(out2fd, h2, HEADER_MAGIC_YES); - - headerFree(h); - headerFree(nh); - headerFree(h2); - } - - Fclose(fd); - } - - errno = 0; - ent = readdir(dir); - if (errno) { - perror("readdir"); - return 1; - } - } - - closedir(dir); - - return 0; -} - -static void usage(void) { - fprintf(stderr, "genhdlist: genhdlist [--withnumbers] [--fileorder ] [--hdlist ] [--productpath ] +\n"); - exit(1); -} - -int main(int argc, const char ** argv) { - char buf[300]; - FD_t outfd = NULL, out2fd = NULL; - int cdNum = -1; - const char ** args; - int doNumber = 0; - int split = 1, noSplit = 0, doSplit = 0; - int rc; - int i; - char * hdListFile = NULL; - char * hdListFile2 = NULL; - char * depOrderFile = NULL; - char * prodDir = strdup("anaconda"); - poptContext optCon; - struct poptOption options[] = { - { "hdlist", '\0', POPT_ARG_STRING, &hdListFile, 0 }, - { "withnumbers", '\0', 0, &doNumber, 0 }, - { "fileorder", '\0', POPT_ARG_STRING, &depOrderFile, 0 }, - { "nosplit", '\0', 0, &noSplit, 0 }, - { "split", '\0', 0, &split, 0 }, - { "productpath", '\0', POPT_ARG_STRING, &prodDir, 0 }, - { 0, 0, 0, 0, 0 } - }; - - optCon = poptGetContext("genhdlist", argc, argv, options, 0); - poptReadDefaultConfig(optCon, 1); - - if ((rc = poptGetNextOpt(optCon)) < -1) { - fprintf(stderr, "%s: bad argument %s: %s\n", "genhdlist", - poptBadOption(optCon, POPT_BADOPTION_NOALIAS), - poptStrerror(rc)); - return 1; - } - - args = poptGetArgs(optCon); - if (!args || !args[0] || !args[0][0]) - usage(); - - if (split && !noSplit) doSplit = 1; - - if (depOrderFile) { - FILE *f; - int nalloced = 0; - int numpkgs = 0; - char *b; - - if (!(f = fopen(depOrderFile, "r"))) { - fprintf (stderr, "Unable to read %s\n", depOrderFile); - usage(); - } - - while ((b = _fgets(f))) { - if (numpkgs == nalloced) { - depOrder = realloc (depOrder, sizeof (char *) * (nalloced + 6)); - memset (depOrder + numpkgs, '\0', sizeof (char *) * 6); - nalloced += 5; - } - - /* sanity check */ - /* should have the format of a -- */ - if (sanityCheckDepOrderLine(b)) { - fprintf(stderr, "genhdlist: FATAL ERROR -> \"%s\" is not a package name!!\n",b); - fprintf(stderr, "Your package list file %s is most likely CORRUPT!\n", depOrderFile); - exit(1); - } - - depOrder[numpkgs] = b; - numpkgs++; - } - depOrder[numpkgs] = NULL; /* end with a null */ - } - - requireTable = htNewTable(1000); - - if (!hdListFile) { - sprintf(buf, "%s/%s/base/hdlist", args[0], prodDir); - hdListFile = buf; - } - - unlink(hdListFile); - - hdListFile2 = malloc(strlen(hdListFile) + 2); - sprintf(hdListFile2, "%s2", hdListFile); - - unlink (hdListFile); - unlink (hdListFile2); - - outfd = Fopen(hdListFile, "w"); - if (!outfd) { - fprintf(stderr,"error creating file %s: %s\n", hdListFile, - strerror(errno)); - return 1; - } - - if (doSplit) { - out2fd = Fopen(hdListFile2, "w"); - if (!out2fd) { - fprintf(stderr,"error creating file %s: %s\n", hdListFile2, - strerror(errno)); - return 1; - } - } - - if (doNumber) - cdNum = 1; - -/* if (args > 1 && !doNumber) { */ -/* fprintf(stderr, "error: building hdlist for multiple trees without numbers\n"); */ -/* exit(1); */ -/* } */ - - i = 0; - while (args[i]) { - sprintf(buf, "%s/%s/RPMS", args[i], prodDir); - if (onePrePass(buf)) - return 1; - i++; - } - - i = 0; - while (args[i]) { - sprintf(buf, "%s/%s/RPMS", args[i], prodDir); - if (onePass(outfd, out2fd, buf, cdNum, doSplit)) - return 1; - if (doNumber) cdNum++; - i++; - } - - Fclose(outfd); - if (doSplit) - Fclose(out2fd); - - poptFreeContext(optCon); - - qsort(pkgList, pkgListItems, sizeof(*pkgList), pkgInfoCmp); - rc = 0; - for (i = 1; i < pkgListItems; i++) { - if (!pkgInfoCmp(pkgList + i - 1, pkgList + i)) { - fprintf(stderr, "duplicate package for %s on %s\n", - pkgList[i].name, pkgList[i].arch); - rc = 1; - } - } - - return rc; -} -- cgit