summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorjbj <devnull@localhost>1999-11-26 16:19:30 +0000
committerjbj <devnull@localhost>1999-11-26 16:19:30 +0000
commitc8406c80d2a9670df64f1ab7e38d90626cad906f (patch)
tree73cd94dccefe9e495fa59f775b6e931e4867e984 /lib
parent2a423cf9398d597b1320e95e864909e292f9c82f (diff)
downloadrpm-c8406c80d2a9670df64f1ab7e38d90626cad906f.tar.gz
rpm-c8406c80d2a9670df64f1ab7e38d90626cad906f.tar.bz2
rpm-c8406c80d2a9670df64f1ab7e38d90626cad906f.zip
lib/macro.c: Create rpmCleanPath().
build/misc.c: Delete cleanFileName(). CVS patchset: 3435 CVS date: 1999/11/26 16:19:30
Diffstat (limited to 'lib')
-rw-r--r--lib/macro.c94
-rw-r--r--lib/rpminstall.c78
-rw-r--r--lib/rpmmacro.h28
3 files changed, 112 insertions, 88 deletions
diff --git a/lib/macro.c b/lib/macro.c
index bf8a5a412..0323f2873 100644
--- a/lib/macro.c
+++ b/lib/macro.c
@@ -132,7 +132,7 @@ sortMacroTable(MacroContext *mc)
}
void
-dumpMacroTable(MacroContext *mc, FILE *f)
+dumpMacroTable(MacroContext * mc, FILE * fp)
{
int i;
int nempty = 0;
@@ -140,10 +140,10 @@ dumpMacroTable(MacroContext *mc, FILE *f)
if (mc == NULL)
mc = &globalMacroContext;
- if (f == NULL)
- f = stderr;
+ if (fp == NULL)
+ fp = stderr;
- fprintf(f, "========================\n");
+ fprintf(fp, "========================\n");
for (i = 0; i < mc->firstFree; i++) {
MacroEntry *me;
if ((me = mc->macroTable[i]) == NULL) {
@@ -151,16 +151,16 @@ dumpMacroTable(MacroContext *mc, FILE *f)
nempty++;
continue;
}
- fprintf(f, "%3d%c %s", me->level,
+ fprintf(fp, "%3d%c %s", me->level,
(me->used > 0 ? '=' : ':'), me->name);
if (me->opts && *me->opts)
- fprintf(f, "(%s)", me->opts);
+ fprintf(fp, "(%s)", me->opts);
if (me->body && *me->body)
- fprintf(f, "\t%s", me->body);
- fprintf(f, "\n");
+ fprintf(fp, "\t%s", me->body);
+ fprintf(fp, "\n");
nactive++;
}
- fprintf(f, _("======================== active %d empty %d\n"),
+ fprintf(fp, _("======================== active %d empty %d\n"),
nactive, nempty);
}
@@ -1462,32 +1462,14 @@ rpmExpandNumeric(const char *arg)
return rc;
}
-/* Return concatenated and expanded path with multiple /'s removed */
-const char *
-rpmGetPath(const char *path, ...)
+const char *rpmCleanPath(char * path)
{
- char buf[BUFSIZ], *t, *te, *se;
const char *s;
- va_list ap;
-
- if (path == NULL)
- return xstrdup("");
+ char *se, *t, *te;
- t = buf;
- te = stpcpy(t, path);
- *te = '\0';
-
- va_start(ap, path);
- while ((s = va_arg(ap, const char *)) != NULL) {
- te = stpcpy(te, s);
- *te = '\0';
- }
- va_end(ap);
- expandMacros(NULL, NULL, buf, sizeof(buf));
-
- s = t = te = buf;
+ s = t = te = path;
while (*s) {
-/*fprintf(stderr, "*** got \"%.*s\"\trest \"%s\"\n", (t-buf), buf, s); */
+/*fprintf(stderr, "*** got \"%.*s\"\trest \"%s\"\n", (t-path), path, s); */
switch(*s) {
case ':': /* handle url's */
if (s[1] == '/' && s[2] == '/') {
@@ -1501,37 +1483,37 @@ rpmGetPath(const char *path, ...)
;
if (se < t && *se == '/') {
te = se;
-/*fprintf(stderr, "*** next pdir \"%.*s\"\n", (te-buf), buf); */
+/*fprintf(stderr, "*** next pdir \"%.*s\"\n", (te-path), path); */
}
while (s[1] == '/')
s++;
- while (t > buf && t[-1] == '/')
+ while (t > path && t[-1] == '/')
t--;
break;
case '.':
/* Leading .. is special */
- if (t == buf && s[1] == '.') {
+ if (t == path && s[1] == '.') {
*t++ = *s++;
break;
}
/* Single . is special */
- if (t == buf && s[1] == '\0') {
+ if (t == path && s[1] == '\0') {
break;
}
/* Trim leading ./ , embedded ./ , trailing /. */
- if ((t == buf || t[-1] == '/') && (s[1] == '/' || s[1] == '\0')) {
+ if ((t == path || t[-1] == '/') && (s[1] == '/' || s[1] == '\0')) {
/*fprintf(stderr, "*** Trim leading ./ , embedded ./ , trailing /.\n"); */
s++;
continue;
}
/* Trim embedded /../ and trailing /.. */
- if (t > buf && t[-1] == '/' && s[1] == '.' && (s[2] == '/' || s[2] == '\0')) {
+ if (t > path && t[-1] == '/' && s[1] == '.' && (s[2] == '/' || s[2] == '\0')) {
t = te;
/* Move parent dir forward */
- if (te > buf)
- for (--te; te > buf && *te != '/'; te--)
+ if (te > path)
+ for (--te; te > path && *te != '/'; te--)
;
-/*fprintf(stderr, "*** prev pdir \"%.*s\"\n", (te-buf), buf); */
+/*fprintf(stderr, "*** prev pdir \"%.*s\"\n", (te-path), path); */
s++;
s++;
continue;
@@ -1542,12 +1524,40 @@ rpmGetPath(const char *path, ...)
}
*t++ = *s++;
}
+
/* Trim trailing / (but leave single / alone) */
- if (t > &buf[1] && t[-1] == '/')
+ if (t > &path[1] && t[-1] == '/')
t--;
*t = '\0';
- return xstrdup(buf);
+ return path;
+}
+
+/* Return concatenated and expanded canonical path. */
+const char *
+rpmGetPath(const char *path, ...)
+{
+ char buf[BUFSIZ];
+ const char * s;
+ char * t, * te;
+ va_list ap;
+
+ if (path == NULL)
+ return xstrdup("");
+
+ t = buf;
+ te = stpcpy(t, path);
+ *te = '\0';
+
+ va_start(ap, path);
+ while ((s = va_arg(ap, const char *)) != NULL) {
+ te = stpcpy(te, s);
+ *te = '\0';
+ }
+ va_end(ap);
+ expandMacros(NULL, NULL, buf, sizeof(buf));
+
+ return xstrdup( rpmCleanPath(buf) );
}
/* Merge 3 args into path, any or all of which may be a url. */
diff --git a/lib/rpminstall.c b/lib/rpminstall.c
index e71778425..18cd2bc53 100644
--- a/lib/rpminstall.c
+++ b/lib/rpminstall.c
@@ -90,13 +90,14 @@ static void * showProgress(const Header h, const rpmCallbackType what,
int rpmInstall(const char * rootdir, const char ** argv, int transFlags,
int interfaceFlags, int probFilter,
- rpmRelocation * relocations) {
+ rpmRelocation * relocations)
+{
rpmdb db = NULL;
FD_t fd;
int i;
int mode, rc, major;
- const char ** packages, ** tmpPackages;
- const char ** filename;
+ const char ** pkgURL, ** tmppkgURL;
+ const char ** fileURL;
int numPackages;
int numTmpPackages = 0, numBinaryPackages = 0, numSourcePackages = 0;
int numFailed = 0;
@@ -108,7 +109,7 @@ int rpmInstall(const char * rootdir, const char ** argv, int transFlags,
size_t nb;
int notifyFlags = interfaceFlags | (rpmIsVerbose() ? INSTALL_LABEL : 0 );
int dbIsOpen = 0;
- const char ** sourcePackages;
+ const char ** sourceURL;
rpmRelocation * defaultReloc;
if (transFlags & RPMTRANS_FLAG_TEST)
@@ -121,31 +122,31 @@ int rpmInstall(const char * rootdir, const char ** argv, int transFlags,
if (defaultReloc && !defaultReloc->newPath) defaultReloc = NULL;
rpmMessage(RPMMESS_DEBUG, _("counting packages to install\n"));
- for (filename = argv, numPackages = 0; *filename; filename++, numPackages++)
+ for (fileURL = argv, numPackages = 0; *fileURL; fileURL++, numPackages++)
;
rpmMessage(RPMMESS_DEBUG, _("found %d packages\n"), numPackages);
nb = (numPackages + 1) * sizeof(char *);
- packages = alloca(nb);
- memset(packages, 0, nb);
- tmpPackages = alloca(nb);
- memset(tmpPackages, 0, nb);
+ pkgURL = alloca(nb);
+ memset(pkgURL, 0, nb);
+ tmppkgURL = alloca(nb);
+ memset(tmppkgURL, 0, nb);
nb = (numPackages + 1) * sizeof(Header);
rpmMessage(RPMMESS_DEBUG, _("looking for packages to download\n"));
- for (filename = argv, i = 0; *filename; filename++) {
+ for (fileURL = argv, i = 0; *fileURL; fileURL++) {
- switch (urlIsURL(*filename)) {
+ switch (urlIsURL(*fileURL)) {
case URL_IS_FTP:
case URL_IS_HTTP:
- case URL_IS_PATH:
{ int myrc;
const char *tfn;
if (rpmIsVerbose())
- fprintf(stdout, _("Retrieving %s\n"), *filename);
+ fprintf(stdout, _("Retrieving %s\n"), *fileURL);
+#ifdef DYING
{ char tfnbuf[64];
const char * tempfn;
strcpy(tfnbuf, "rpm-xfer.XXXXXX");
@@ -168,29 +169,36 @@ int rpmInstall(const char * rootdir, const char ** argv, int transFlags,
break;
}
}
+#else
+ { char tfnbuf[64];
+ strcpy(tfnbuf, "rpm-xfer.XXXXXX");
+ tfn = rpmGenPath(rootdir, "%{_tmppath}/", mktemp(tfnbuf));
+ }
+#endif
/* XXX undefined %{name}/%{version}/%{release} here */
/* XXX %{_tmpdir} does not exist */
rpmMessage(RPMMESS_DEBUG, _(" ... as %s\n"), tfn);
- myrc = urlGetFile(*filename, tfn);
+ myrc = urlGetFile(*fileURL, tfn);
if (myrc < 0) {
rpmMessage(RPMMESS_ERROR,
_("skipping %s - transfer failed - %s\n"),
- *filename, ftpStrerror(myrc));
+ *fileURL, ftpStrerror(myrc));
numFailed++;
- packages[i] = NULL;
+ pkgURL[i] = NULL;
xfree(tfn);
} else {
- tmpPackages[numTmpPackages++] = packages[i++] = tfn;
+ tmppkgURL[numTmpPackages++] = pkgURL[i++] = tfn;
}
} break;
+ case URL_IS_PATH:
default:
- packages[i++] = *filename;
+ pkgURL[i++] = *fileURL;
break;
}
}
- sourcePackages = alloca(sizeof(*sourcePackages) * i);
+ sourceURL = alloca(sizeof(*sourceURL) * i);
rpmMessage(RPMMESS_DEBUG, _("retrieved %d packages\n"), numTmpPackages);
@@ -198,13 +206,15 @@ int rpmInstall(const char * rootdir, const char ** argv, int transFlags,
are installed right here, only because they don't have headers and
would create all sorts of confusion later. */
- for (filename = packages; *filename; filename++) {
- fd = Fopen(*filename, "r.ufdio");
+ for (fileURL = pkgURL; *fileURL; fileURL++) {
+ const char * fileName;
+ (void) urlPath(*fileURL, &fileName);
+ fd = Fopen(*fileURL, "r.ufdio");
if (Ferror(fd)) {
- rpmMessage(RPMMESS_ERROR, _("cannot open file %s: %s\n"), *filename,
+ rpmMessage(RPMMESS_ERROR, _("cannot open file %s: %s\n"), *fileURL,
Fstrerror(fd));
numFailed++;
- packages[i] = NULL;
+ pkgURL[i] = NULL;
continue;
}
@@ -215,16 +225,16 @@ int rpmInstall(const char * rootdir, const char ** argv, int transFlags,
Fclose(fd);
rpmMessage(RPMMESS_ERROR,
_("%s does not appear to be a RPM package\n"),
- *filename);
+ *fileURL);
break;
default:
- rpmMessage(RPMMESS_ERROR, _("%s cannot be installed\n"), *filename);
+ rpmMessage(RPMMESS_ERROR, _("%s cannot be installed\n"), *fileURL);
numFailed++;
- packages[i] = NULL;
+ pkgURL[i] = NULL;
break;
case 0:
if (isSource) {
- sourcePackages[numSourcePackages++] = *filename;
+ sourceURL[numSourcePackages++] = fileName;
Fclose(fd);
} else {
if (!dbIsOpen) {
@@ -260,7 +270,7 @@ int rpmInstall(const char * rootdir, const char ** argv, int transFlags,
}
}
- rc = rpmtransAddPackage(rpmdep, h, NULL, *filename,
+ rc = rpmtransAddPackage(rpmdep, h, NULL, fileName,
(interfaceFlags & INSTALL_UPGRADE) != 0,
relocations);
@@ -272,13 +282,13 @@ int rpmInstall(const char * rootdir, const char ** argv, int transFlags,
break;
case 1:
rpmMessage(RPMMESS_ERROR,
- _("error reading from file %s\n"), *filename);
+ _("error reading from file %s\n"), *fileURL);
return numPackages;
/*@notreached@*/ break;
case 2:
rpmMessage(RPMMESS_ERROR,
_("file %s requires a newer version of RPM\n"),
- *filename);
+ *fileURL);
return numPackages;
/*@notreached@*/ break;
}
@@ -341,10 +351,10 @@ int rpmInstall(const char * rootdir, const char ** argv, int transFlags,
if (numSourcePackages && !stopInstall) {
for (i = 0; i < numSourcePackages; i++) {
- fd = Fopen(sourcePackages[i], "r.ufdio");
+ fd = Fopen(sourceURL[i], "r.ufdio");
if (Ferror(fd)) {
rpmMessage(RPMMESS_ERROR, _("cannot open file %s: %s\n"),
- sourcePackages[i], Fstrerror(fd));
+ sourceURL[i], Fstrerror(fd));
continue;
}
@@ -357,8 +367,8 @@ int rpmInstall(const char * rootdir, const char ** argv, int transFlags,
}
for (i = 0; i < numTmpPackages; i++) {
- unlink(tmpPackages[i]);
- xfree(tmpPackages[i]);
+ Unlink(tmppkgURL[i]);
+ xfree(tmppkgURL[i]);
}
/* FIXME how do we close our various fd's? */
diff --git a/lib/rpmmacro.h b/lib/rpmmacro.h
index a1d038666..9ad1e5ded 100644
--- a/lib/rpmmacro.h
+++ b/lib/rpmmacro.h
@@ -33,28 +33,32 @@ typedef /*@abstract@*/ struct MacroContext {
extern "C" {
#endif
-void dumpMacroTable (MacroContext *mc, FILE *f);
+void dumpMacroTable (MacroContext * mc, FILE * fp);
/* XXX this is used only in build/expression.c and will go away. */
const char *getMacroBody (MacroContext *mc, const char *name);
-int expandMacros (void *spec, MacroContext *mc, char *sbuf, size_t sbuflen);
-void addMacro (MacroContext *mc, const char *n, const char *o, const char *b, int depth);
-void delMacro (MacroContext *mc, const char *n);
+int expandMacros (void * spec, MacroContext * mc, char * sbuf,
+ size_t sbuflen);
+void addMacro (MacroContext * mc, const char * n, const char * o,
+ const char * b, int depth);
+void delMacro (MacroContext * mc, const char * n);
-int rpmDefineMacro (MacroContext *mc, const char *macro, int level);
-void initMacros (MacroContext *mc, const char *macrofile);
-void freeMacros (MacroContext *mc);
+int rpmDefineMacro (MacroContext * mc, const char * macro, int level);
+void initMacros (MacroContext * mc, const char * macrofile);
+void freeMacros (MacroContext * mc);
#define COMPRESSED_NOT 0
#define COMPRESSED_OTHER 1
#define COMPRESSED_BZIP2 2
-int isCompressed (const char *file, int *compressed);
+int isCompressed (const char * file, int * compressed);
-char * rpmExpand (const char *arg, ...);
-const char *rpmGetPath (const char *path, ...);
-const char *rpmGenPath (const char *root, const char *mdir, const char *file);
-int rpmExpandNumeric (const char *arg);
+char * rpmExpand (const char * arg, ...);
+const char *rpmCleanPath(char * path);
+const char *rpmGetPath (const char * path, ...);
+const char *rpmGenPath (const char * root, const char * mdir,
+ const char * file);
+int rpmExpandNumeric (const char * arg);
#ifdef __cplusplus
}