fix: compressFileList was over-generating dirNames.
authorjbj <devnull@localhost>
Wed, 15 Dec 1999 15:51:30 +0000 (15:51 +0000)
committerjbj <devnull@localhost>
Wed, 15 Dec 1999 15:51:30 +0000 (15:51 +0000)
fix: alAddPackage sorted dirNames too soon, destroying dirMapping.

CVS patchset: 3481
CVS date: 1999/12/15 15:51:30

CHANGES
lib/depends.c
lib/depends.h
lib/misc.c
po/rpm.pot
rpm.spec

diff --git a/CHANGES b/CHANGES
index e8fb977..effe991 100644 (file)
--- 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.
index 970a8da..38722f7 100644 (file)
@@ -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);
index 4700649..8d60228 100644 (file)
@@ -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;
 } ;
index e5053c1..bdcc5ae 100644 (file)
@@ -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;
     }
 
index 1f7c10d..b1944f4 100644 (file)
@@ -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 <EMAIL@ADDRESS>\n"
 "Language-Team: LANGUAGE <LL@li.org>\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 ""
index af2dbf0..cc3df39 100644 (file)
--- 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