fix: resurrect relative path's in fprint lookup queries.

CVS patchset: 3518
CVS date: 2000/01/12 21:48:58
This commit is contained in:
jbj 2000-01-12 21:48:58 +00:00
parent ea3ab95e17
commit 0d185e8fb5
9 changed files with 80 additions and 58 deletions

View File

@ -42,6 +42,7 @@
- use only %_install_langs, not LINGUAS/LANG when deciding to install.
- configurable compression type/level for package payloads.
- default value for %_install_langs is all.
- fix: resurrect relative path's in fprint lookup queries.
3.0.2 -> 3.0.3
- add --eval to find result of macro expansion.

View File

@ -1,6 +1,8 @@
#include "system.h"
#include <rpmlib.h>
#include <rpmmacro.h> /* XXX for rpmCleanPath */
#include "fprint.h"
fingerPrintCache fpCacheCreate(int sizeHint)
@ -34,6 +36,8 @@ static fingerPrint doLookup(fingerPrintCache cache,
const char * dirName, const char * baseName, int scareMemory)
{
char dir[PATH_MAX];
const char * cleanDirName;
size_t cdnl;
char * end; /* points to the '\0' at the end of "buf" */
fingerPrint fp;
struct stat sb;
@ -42,12 +46,20 @@ static fingerPrint doLookup(fingerPrintCache cache,
/* assert(*dirName == '/' || !scareMemory); */
if (*dirName != '/') {
scareMemory = 0;
/* XXX WATCHOUT: fp.subDir is set below from relocated dirName arg */
cleanDirName = dirName;
cdnl = strlen(cleanDirName);
if (*cleanDirName == '/') {
if (!scareMemory)
cleanDirName =
rpmCleanPath(strcpy(alloca(cdnl+1), dirName));
} else {
scareMemory = 0; /* XXX causes memory leak */
/* Using realpath on the arg isn't correct if the arg is a symlink,
* especially if the symlink is a dangling link. What we
* do instaed is use realpath() on `.' and then append arg to
* do instead is use realpath() on `.' and then append arg to
* the result.
*/
@ -55,21 +67,24 @@ static fingerPrint doLookup(fingerPrintCache cache,
oh well. likewise if it's too long. */
dir[0] = '\0';
if ( /*@-unrecog@*/ realpath(".", dir) /*@=unrecog@*/ != NULL) {
char *s = alloca(strlen(dir) + strlen(dirName) + 2);
sprintf(s, "%s/%s", dir, dirName);
dirName = s;
end = dir + strlen(dir);
if (end[-1] != '/') *end++ = '/';
end = stpncpy(end, cleanDirName, sizeof(dir) - (end - dir));
*end = '\0';
rpmCleanPath(dir); /* XXX possible /../ from concatenation */
end = dir + strlen(dir);
if (end[-1] != '/') *end++ = '/';
*end = '\0';
cleanDirName = dir;
cdnl = end - dir;
}
}
/* FIXME: perhaps we should collapse //, /./, and /../ stuff if
!scareMemory?? */
buf = alloca(strlen(dirName) + 1);
strcpy(buf, dirName);
end = buf + strlen(buf);
buf = strcpy(alloca(cdnl + 1), cleanDirName);
end = buf + cdnl;
/* no need to pay attention to that extra little / at the end of dirName */
if (*(end - 1) == '/' && buf[1]) {
if (buf[1] && end[-1] == '/') {
end--;
*end = '\0';
}
@ -82,9 +97,10 @@ static fingerPrint doLookup(fingerPrintCache cache,
if ((cacheHit = cacheContainsDirectory(cache, *buf ? buf : "/"))) {
fp.entry = cacheHit;
} else if (!stat(*buf ? buf : "/", &sb)) {
size_t nb = sizeof(*fp.entry) + (*buf ? strlen(buf) : 1) + 1;
size_t nb = sizeof(*fp.entry) + (*buf ? (end-buf) : 1) + 1;
char * dn = xmalloc(nb);
struct fprintCacheEntry_s * newEntry = (void *)dn;
dn += sizeof(*newEntry);
strcpy(dn, (*buf ? buf : "/"));
newEntry->ino = sb.st_ino;
@ -97,7 +113,7 @@ static fingerPrint doLookup(fingerPrintCache cache,
}
if (fp.entry) {
fp.subDir = dirName + (end - buf);
fp.subDir = cleanDirName + (end - buf);
if (fp.subDir[0] == '/' && fp.subDir[1] != '\0')
fp.subDir++;
if (fp.subDir[0] == '\0')

View File

@ -1487,7 +1487,8 @@ rpmExpandNumeric(const char *arg)
return rc;
}
const char *rpmCleanPath(char * path)
/* XXX FIXME: ../sbin/./../bin/ */
char *rpmCleanPath(char * path)
{
const char *s;
char *se, *t, *te;

View File

@ -303,7 +303,7 @@ static Header doGetRecord(rpmdb db, unsigned int offset, int pristine)
h = headerRead(db->pkgs, HEADER_MAGIC_NO);
if (pristine) return h;
if (pristine || h == NULL) return h;
/* the RPM used to build much of RH 5.1 could produce packages whose
file lists did not have leading /'s. Now is a good time to fix
@ -360,21 +360,21 @@ int rpmdbFindByFile(rpmdb db, const char * filespec, dbiIndexSet * matches)
fingerPrint fp1, fp2;
dbiIndexSet allMatches;
int i, rc;
Header h;
fingerPrintCache fpc;
{ char * t = strcpy(alloca(strlen(filespec)+1), filespec);
char * te = strrchr(t, '/');
if (te) {
te++;
*te = '\0';
}
if ((baseName = strrchr(filespec, '/')) != NULL) {
char * t;
size_t len;
len = baseName - filespec + 1;
t = strncpy(alloca(len + 1), filespec, len);
t[len] = '\0';
dirName = t;
}
if ((baseName = strrchr(filespec, '/')) != NULL)
baseName++;
else
} else {
dirName = "";
baseName = filespec;
}
fpc = fpCacheCreate(20);
fp1 = fpLookup(fpc, dirName, baseName, 1);
@ -390,6 +390,7 @@ int rpmdbFindByFile(rpmdb db, const char * filespec, dbiIndexSet * matches)
while (i < allMatches.count) {
const char ** baseNames, ** dirNames;
int_32 * dirIndexes;
Header h;
if ((h = rpmdbGetRecord(db, allMatches.recs[i].recOffset)) == NULL) {
i++;

View File

@ -55,7 +55,7 @@ void rpmFreeMacros (MacroContext * mc);
int isCompressed (const char * file, int * compressed);
char * rpmExpand (const char * arg, ...);
const char *rpmCleanPath(char * path);
char * rpmCleanPath (char * path);
const char *rpmGetPath (const char * path, ...);
const char *rpmGenPath (const char * root, const char * mdir,
const char * file);

View File

@ -1,4 +1,4 @@
# $Id: macros.in,v 1.43 2000/01/11 19:12:35 jbj Exp $
# $Id: macros.in,v 1.44 2000/01/12 21:48:58 jbj Exp $
#==============================================================================
# Macro naming conventions (preliminary):
#
@ -116,6 +116,8 @@
#%buildroot
# The sub-directory (relative to %{_builddir}) where sources are compiled.
# This macro is set after processing %setup, either explicitly from the
# value given to -n or the default name-version.
#
#%buildsubdir

View File

@ -6,7 +6,7 @@
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"POT-Creation-Date: 2000-01-11 11:56-0500\n"
"POT-Creation-Date: 2000-01-12 16:44-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"
@ -1421,7 +1421,7 @@ msgstr ""
msgid "Could not open %%files file %s: %s"
msgstr ""
#: build/files.c:1164 build/pack.c:481
#: build/files.c:1164 build/pack.c:485
#, c-format
msgid "line: %s"
msgstr ""
@ -1549,47 +1549,47 @@ msgstr ""
msgid "Wrote: %s\n"
msgstr ""
#: build/pack.c:430
#: build/pack.c:433
#, c-format
msgid "create archive failed on file %s: %s"
msgstr ""
#: build/pack.c:449
#: build/pack.c:453
#, c-format
msgid "cpio_copy write failed: %s"
msgstr ""
#: build/pack.c:456
#: build/pack.c:460
#, c-format
msgid "cpio_copy read failed: %s"
msgstr ""
#: build/pack.c:536
#: build/pack.c:540
#, c-format
msgid "Could not open PreIn file: %s"
msgstr ""
#: build/pack.c:543
#: build/pack.c:547
#, c-format
msgid "Could not open PreUn file: %s"
msgstr ""
#: build/pack.c:550
#: build/pack.c:554
#, c-format
msgid "Could not open PostIn file: %s"
msgstr ""
#: build/pack.c:557
#: build/pack.c:561
#, c-format
msgid "Could not open PostUn file: %s"
msgstr ""
#: build/pack.c:565
#: build/pack.c:569
#, c-format
msgid "Could not open VerifyScript file: %s"
msgstr ""
#: build/pack.c:580
#: build/pack.c:584
#, c-format
msgid "Could not open Trigger script file: %s"
msgstr ""
@ -2862,76 +2862,76 @@ msgid ""
"database"
msgstr ""
#: lib/rpmdb.c:469
#: lib/rpmdb.c:470
#, c-format
msgid "package %s not listed in %s"
msgstr ""
#: lib/rpmdb.c:480
#: lib/rpmdb.c:481
#, c-format
msgid "package %s not found in %s"
msgstr ""
#: lib/rpmdb.c:504 lib/uninstall.c:87
#: lib/rpmdb.c:505 lib/uninstall.c:87
#, c-format
msgid "cannot read header at %d for uninstall"
msgstr ""
#: lib/rpmdb.c:512
#: lib/rpmdb.c:513
msgid "package has no name"
msgstr ""
#: lib/rpmdb.c:514
#: lib/rpmdb.c:515
msgid "removing name index\n"
msgstr ""
#: lib/rpmdb.c:519
#: lib/rpmdb.c:520
msgid "package has no group\n"
msgstr ""
#: lib/rpmdb.c:521
#: lib/rpmdb.c:522
msgid "removing group index\n"
msgstr ""
#: lib/rpmdb.c:528
#: lib/rpmdb.c:529
#, c-format
msgid "removing provides index for %s\n"
msgstr ""
#: lib/rpmdb.c:543
#: lib/rpmdb.c:544
#, c-format
msgid "removing requiredby index for %s\n"
msgstr ""
#: lib/rpmdb.c:555
#: lib/rpmdb.c:556
#, c-format
msgid "removing trigger index for %s\n"
msgstr ""
#: lib/rpmdb.c:566
#: lib/rpmdb.c:567
#, c-format
msgid "removing conflict index for %s\n"
msgstr ""
#: lib/rpmdb.c:577
#: lib/rpmdb.c:578
#, c-format
msgid "removing file index for %s\n"
msgstr ""
#: lib/rpmdb.c:586
#: lib/rpmdb.c:587
msgid "package has no files\n"
msgstr ""
#: lib/rpmdb.c:692
#: lib/rpmdb.c:693
msgid "cannot allocate space for database"
msgstr ""
#: lib/rpmdb.c:751
#: lib/rpmdb.c:752
#, c-format
msgid "cannot read header at %d for update"
msgstr ""
#: lib/rpmdb.c:764
#: lib/rpmdb.c:765
msgid "header changed size!"
msgstr ""

View File

@ -1487,7 +1487,8 @@ rpmExpandNumeric(const char *arg)
return rc;
}
const char *rpmCleanPath(char * path)
/* XXX FIXME: ../sbin/./../bin/ */
char *rpmCleanPath(char * path)
{
const char *s;
char *se, *t, *te;

View File

@ -55,7 +55,7 @@ void rpmFreeMacros (MacroContext * mc);
int isCompressed (const char * file, int * compressed);
char * rpmExpand (const char * arg, ...);
const char *rpmCleanPath(char * path);
char * rpmCleanPath (char * path);
const char *rpmGetPath (const char * path, ...);
const char *rpmGenPath (const char * root, const char * mdir,
const char * file);