From 8885331b742acd8a827771fabe51b527c1b455b7 Mon Sep 17 00:00:00 2001 From: jbj Date: Wed, 15 Dec 1999 15:51:30 +0000 Subject: [PATCH] fix: compressFileList was over-generating dirNames. fix: alAddPackage sorted dirNames too soon, destroying dirMapping. CVS patchset: 3481 CVS date: 1999/12/15 15:51:30 --- CHANGES | 2 ++ lib/depends.c | 19 +++++++++++++------ lib/depends.h | 2 +- lib/misc.c | 29 ++++++++++++++++++++--------- po/rpm.pot | 34 +++++++++++++++++----------------- rpm.spec | 2 +- 6 files changed, 54 insertions(+), 34 deletions(-) diff --git a/CHANGES b/CHANGES index e8fb977..effe991 100644 --- a/CHANGES +++ b/CHANGES @@ -22,6 +22,8 @@ - fix: ftpAbort must close the data channel to read abort status. - perform glob on remote ftp install args. - fix: reload macros from cmd line when re-reading config files. + - fix: compressFileList was over-generating dirNames. + - fix: alAddPackage sorted dirNames too soon, destroying dirMapping. 3.0.2 -> 3.0.3 - add --eval to find result of macro expansion. diff --git a/lib/depends.c b/lib/depends.c index 970a8da..38722f7 100644 --- a/lib/depends.c +++ b/lib/depends.c @@ -128,7 +128,7 @@ static void alFree(struct availableList * al) if (al->numDirs) free(al->dirs); - al->dirs = NULL; + al->dirs = NULL; if (al->alloced && al->list) free(al->list); @@ -139,7 +139,11 @@ static void alFree(struct availableList * al) static int dirInfoCompare(const void * one, const void * two) { const struct dirInfo * a = one; const struct dirInfo * b = two; + int lenchk = a->dirNameLen - b->dirNameLen; + if (lenchk) + return lenchk; + /* XXX FIXME: this might do "backward" strcmp for speed */ return strcmp(a->dirName, b->dirName); } @@ -211,23 +215,21 @@ static /*@exposed@*/ struct availablePackage * alAddPackage(struct availableList for (dirNum = 0; dirNum < numDirs; dirNum++) { dirNeedle.dirName = (char *) dirNames[dirNum]; + dirNeedle.dirNameLen = strlen(dirNames[dirNum]); dirMatch = bsearch(&dirNeedle, al->dirs, origNumDirs, sizeof(dirNeedle), dirInfoCompare); if (dirMatch) { dirMapping[dirNum] = dirMatch - al->dirs; } else { + dirMapping[dirNum] = al->numDirs; al->dirs[al->numDirs].dirName = xstrdup(dirNames[dirNum]); + al->dirs[al->numDirs].dirNameLen = strlen(dirNames[dirNum]); al->dirs[al->numDirs].files = NULL; al->dirs[al->numDirs].numFiles = 0; - al->dirs[al->numDirs].dirNum = al->numDirs; - dirMapping[dirNum] = al->numDirs; al->numDirs++; } } - if (origNumDirs + al->numDirs) - qsort(al->dirs, al->numDirs, sizeof(dirNeedle), dirInfoCompare); - free(dirNames); first = 0; @@ -251,6 +253,10 @@ static /*@exposed@*/ struct availablePackage * alAddPackage(struct availableList first = last + 1; } + + if (origNumDirs + al->numDirs) + qsort(al->dirs, al->numDirs, sizeof(dirNeedle), dirInfoCompare); + } p->key = key; @@ -763,6 +769,7 @@ alFileSatisfiesDepend(struct availableList * al, } dirNeedle.dirName = (char *) dirName; + dirNeedle.dirNameLen = strlen(dirName); dirMatch = bsearch(&dirNeedle, al->dirs, al->numDirs, sizeof(dirNeedle), dirInfoCompare); xfree(dirName); diff --git a/lib/depends.h b/lib/depends.h index 4700649..8d60228 100644 --- a/lib/depends.h +++ b/lib/depends.h @@ -34,7 +34,7 @@ struct fileIndexEntry { struct dirInfo { /*@owned@*/ char * dirName; /* xstrdup'd */ - int dirNum; + int dirNameLen; /*@owned@*/ struct fileIndexEntry * files; /* xmalloc'd */ int numFiles; } ; diff --git a/lib/misc.c b/lib/misc.c index e5053c1..bdcc5ae 100644 --- a/lib/misc.c +++ b/lib/misc.c @@ -473,16 +473,22 @@ char * currentDirectory(void) int _noDirTokens = 1; +static int dncmp(const void * a, const void * b) +{ + const char *const * first = a; + const char *const * second = b; + return strcmp(*first, *second); +} + void compressFilelist(Header h) { - const char ** fileNames; + char ** fileNames; const char ** dirNames; const char ** baseNames; int_32 * dirIndexes; int count; int i; int dirIndex = -1; - int lastLen = -1; /* * This assumes the file list is already sorted, and begins with a @@ -510,19 +516,24 @@ void compressFilelist(Header h) } for (i = 0; i < count; i++) { + const char ** needle; char *baseName = strrchr(fileNames[i], '/') + 1; + char savechar; int len = baseName - fileNames[i]; - if (dirIndex < 0 || lastLen != len || - strncmp(dirNames[dirIndex], fileNames[i], len)) { + savechar = *baseName; + *baseName = '\0'; + if (dirIndex < 0 || + (needle = bsearch(&fileNames[i], dirNames, dirIndex + 1, sizeof(dirNames[0]), dncmp)) == NULL) { char *s = alloca(len + 1); - memcpy(s, fileNames[i], len); + memcpy(s, fileNames[i], len + 1); s[len] = '\0'; - dirNames[++dirIndex] = s; - lastLen = len; - } + dirIndexes[i] = ++dirIndex; + dirNames[dirIndex] = s; + } else + dirIndexes[i] = needle - dirNames; - dirIndexes[i] = dirIndex; + *baseName = savechar; baseNames[i] = baseName; } diff --git a/po/rpm.pot b/po/rpm.pot index 1f7c10d..b1944f4 100644 --- a/po/rpm.pot +++ b/po/rpm.pot @@ -6,7 +6,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" -"POT-Creation-Date: 1999-12-13 14:24-0500\n" +"POT-Creation-Date: 1999-12-15 10:33-0500\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -1997,85 +1997,85 @@ msgid "error removing record %s into %s" msgstr "" #. XXX legacy epoch-less requires/conflicts compatibility -#: lib/depends.c:411 +#: lib/depends.c:417 #, c-format msgid "" "the \"B\" dependency needs an epoch (assuming same as \"A\")\n" "\tA %s\tB %s\n" msgstr "" -#: lib/depends.c:440 +#: lib/depends.c:446 #, c-format msgid " %s A %s\tB %s\n" msgstr "" -#: lib/depends.c:532 +#: lib/depends.c:538 msgid "dbrecMatchesDepFlags() failed to read header" msgstr "" -#: lib/depends.c:777 +#: lib/depends.c:784 #, c-format msgid "%s: %s satisfied by added file list.\n" msgstr "" -#: lib/depends.c:816 +#: lib/depends.c:823 #, c-format msgid "%s: %s satisfied by added package.\n" msgstr "" -#: lib/depends.c:833 +#: lib/depends.c:840 #, c-format msgid "%s: %s satisfied by added provide.\n" msgstr "" -#: lib/depends.c:864 +#: lib/depends.c:871 #, c-format msgid "%s: %s satisfied by rpmrc provides.\n" msgstr "" -#: lib/depends.c:892 +#: lib/depends.c:899 #, c-format msgid "%s: %s satisfied by db file lists.\n" msgstr "" -#: lib/depends.c:914 +#: lib/depends.c:921 #, c-format msgid "%s: %s satisfied by db provides.\n" msgstr "" -#: lib/depends.c:936 +#: lib/depends.c:943 #, c-format msgid "%s: %s satisfied by db packages.\n" msgstr "" -#: lib/depends.c:949 +#: lib/depends.c:956 #, c-format msgid "%s: %s satisfied by rpmlib version.\n" msgstr "" -#: lib/depends.c:959 +#: lib/depends.c:966 #, c-format msgid "%s: %s unsatisfied.\n" msgstr "" #. requirements are not satisfied. -#: lib/depends.c:1007 +#: lib/depends.c:1014 #, c-format msgid "package %s require not satisfied: %s\n" msgstr "" #. conflicts exist. -#: lib/depends.c:1069 +#: lib/depends.c:1076 #, c-format msgid "package %s conflicts: %s\n" msgstr "" -#: lib/depends.c:1124 lib/depends.c:1423 +#: lib/depends.c:1131 lib/depends.c:1430 #, c-format msgid "cannot read header at %d for dependency check" msgstr "" -#: lib/depends.c:1219 +#: lib/depends.c:1226 #, c-format msgid "loop in prerequisite chain: %s" msgstr "" diff --git a/rpm.spec b/rpm.spec index af2dbf0..cc3df39 100644 --- a/rpm.spec +++ b/rpm.spec @@ -2,7 +2,7 @@ Summary: The Red Hat package management system. Name: rpm %define version 3.0.4 Version: %{version} -Release: 0.14 +Release: 0.15 Group: System Environment/Base Source: ftp://ftp.rpm.org/pub/rpm/dist/rpm-3.0.x/rpm-%{version}.tar.gz Copyright: GPL -- 2.7.4