summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorjbj <devnull@localhost>1999-12-15 15:51:30 +0000
committerjbj <devnull@localhost>1999-12-15 15:51:30 +0000
commit8885331b742acd8a827771fabe51b527c1b455b7 (patch)
tree38c1c124154d573ee49a2ca4529675ac4bb1a10c /lib
parentdab52919d121711f70e286416e2304733aa2e268 (diff)
downloadrpm-8885331b742acd8a827771fabe51b527c1b455b7.tar.gz
rpm-8885331b742acd8a827771fabe51b527c1b455b7.tar.bz2
rpm-8885331b742acd8a827771fabe51b527c1b455b7.zip
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
Diffstat (limited to 'lib')
-rw-r--r--lib/depends.c19
-rw-r--r--lib/depends.h2
-rw-r--r--lib/misc.c29
3 files changed, 34 insertions, 16 deletions
diff --git a/lib/depends.c b/lib/depends.c
index 970a8da87..38722f7a7 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 470064958..8d60228da 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 e5053c156..bdcc5aeab 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;
}