From e914b78e33143855c850e1cdb513a0103ee9f17e Mon Sep 17 00:00:00 2001 From: root Date: Tue, 9 Jul 1996 02:06:26 +0000 Subject: [PATCH] logic for handling Prefix: CVS patchset: 748 CVS date: 1996/07/09 02:06:26 --- build/files.c | 35 +++++++++++++++++++++++++++++------ build/files.h | 2 +- build/pack.c | 51 ++++++++++++++++++++++++++++++++++++++++++--------- build/spec.c | 7 +++++++ build/specP.h | 2 ++ 5 files changed, 81 insertions(+), 16 deletions(-) diff --git a/build/files.c b/build/files.c index 4171106..ac931b3 100644 --- a/build/files.c +++ b/build/files.c @@ -41,7 +41,7 @@ struct file_entry { static int add_file(struct file_entry **festack, const char *name, int isdoc, int isconf, int isdir, int verify_flags, - char *Pmode, char *Uname, char *Gname); + char *Pmode, char *Uname, char *Gname, char *prefix); static int compare_fe(const void *ap, const void *bp); static int add_file_aux(const char *file, struct stat *sb, int flag); static int glob_error(const char *foo, int bar); @@ -56,7 +56,7 @@ static int isDoc(char *filename); int process_filelist(Header header, struct PackageRec *pr, StringBuf sb, int *size, char *name, - char *version, char *release, int type) + char *version, char *release, int type, char *prefix) { char buf[1024]; char **files, **fp; @@ -203,13 +203,14 @@ int process_filelist(Header header, struct PackageRec *pr, int offset = strlen(getVar(RPMVAR_ROOT) ? : ""); c += add_file(&fes, &(glob_result.gl_pathv[x][offset]), isdoc, isconf, isdir, verify_flags, - currPmode, currUname, currGname); + currPmode, currUname, currGname, prefix); x++; } globfree(&glob_result); } else { c = add_file(&fes, filename, isdoc, isconf, isdir, - verify_flags, currPmode, currUname, currGname); + verify_flags, currPmode, currUname, + currGname, prefix); } } else { /* Source package are the simple case */ @@ -464,13 +465,15 @@ static char *GPmode; static char *GUname; static char *GGname; static struct file_entry **Gfestack; +static char *Gprefix; static int add_file(struct file_entry **festack, const char *name, int isdoc, int isconf, int isdir, int verify_flags, - char *Pmode, char *Uname, char *Gname) + char *Pmode, char *Uname, char *Gname, char *prefix) { struct file_entry *p; char *copyTo, copied; + const char *prefixTest, *prefixPtr; const char *copyFrom; char fullname[1024]; int mode; @@ -483,6 +486,7 @@ static int add_file(struct file_entry **festack, const char *name, GPmode = Pmode; GUname = Uname; GGname = Gname; + Gprefix = prefix; p = malloc(sizeof(struct file_entry)); @@ -505,6 +509,25 @@ static int add_file(struct file_entry **festack, const char *name, } else { strcpy(fullname, name); } + + /* If we are using a prefix, validate the file */ + if (prefix) { + prefixTest = name; + prefixPtr = prefix; + while (*prefixTest == '/') { + prefixTest++; /* Skip leading "/" */ + } + while (*prefixPtr && (*prefixTest == *prefixPtr)) { + prefixPtr++; + prefixTest++; + } + if (*prefixPtr) { + error(RPMERR_BADSPEC, "File doesn't match prefix: %s", name); + return 0; + } + } + + /* OK, finally stat() the file */ if (lstat(fullname, &p->statbuf)) { return 0; } @@ -565,7 +588,7 @@ static int add_file_aux(const char *file, struct stat *sb, int flag) /* The 1 will cause add_file() to *not* descend */ /* directories -- ftw() is already doing it! */ Gcount += add_file(Gfestack, name, Gisdoc, Gisconf, 1, Gverify_flags, - GPmode, GUname, GGname); + GPmode, GUname, GGname, Gprefix); return 0; /* for ftw() */ } diff --git a/build/files.h b/build/files.h index 2ac335e..aa06e66 100644 --- a/build/files.h +++ b/build/files.h @@ -7,6 +7,6 @@ int process_filelist(Header header, struct PackageRec *pr, StringBuf sb, int *size, char *name, char *version, - char *release, int type); + char *release, int type, char *prefix); #endif _FILES_H_ diff --git a/build/pack.c b/build/pack.c index 473511b..ee8f747 100644 --- a/build/pack.c +++ b/build/pack.c @@ -26,14 +26,16 @@ #include "reqprov.h" static int writeMagic(int fd, char *name, unsigned short type); -static int cpio_gzip(int fd, char *tempdir, char *writePtr, int *archiveSize); +static int cpio_gzip(int fd, char *tempdir, char *writePtr, + int *archiveSize, char *prefix); static int generateRPM(char *name, /* name-version-release */ char *filename, /* output filename */ int type, /* source or binary */ Header header, /* the header */ char *stempdir, /* directory containing sources */ char *fileList, /* list of files for cpio */ - char *passPhrase); + char *passPhrase, /* PGP passphrase */ + char *prefix); static int generateRPM(char *name, /* name-version-release */ @@ -42,7 +44,8 @@ static int generateRPM(char *name, /* name-version-release */ Header header, /* the header */ char *stempdir, /* directory containing sources */ char *fileList, /* list of files for cpio */ - char *passPhrase) + char *passPhrase, + char *prefix) { int_32 sigtype; char *sigtarget, *archiveTemp; @@ -56,7 +59,7 @@ static int generateRPM(char *name, /* name-version-release */ fprintf(stderr, "Could not open %s\n", archiveTemp); return 1; } - if (cpio_gzip(fd, stempdir, fileList, &archiveSize)) { + if (cpio_gzip(fd, stempdir, fileList, &archiveSize, prefix)) { close(fd); unlink(archiveTemp); return 1; @@ -178,7 +181,8 @@ static int writeMagic(int fd, char *name, return 0; } -static int cpio_gzip(int fd, char *tempdir, char *writePtr, int *archiveSize) +static int cpio_gzip(int fd, char *tempdir, char *writePtr, + int *archiveSize, char *prefix) { int cpioPID, gzipPID; int cpioDead, gzipDead; @@ -224,6 +228,12 @@ static int cpio_gzip(int fd, char *tempdir, char *writePtr, int *archiveSize) /* This is important! */ chdir("/"); } + if (prefix) { + if (chdir(prefix)) { + error(RPMERR_EXEC, "Couldn't chdir to %s", prefix); + exit(RPMERR_EXEC); + } + } execlp("cpio", "cpio", (isVerbose()) ? "-ov" : "-o", @@ -360,6 +370,8 @@ int packageBinaries(Spec s, char *passPhrase) char *vendor; char *dist; char *packageVersion, *packageRelease; + char *prefix; + int prefixLen; int size; StringBuf cpioFileList; char **farray, *file; @@ -388,6 +400,17 @@ int packageBinaries(Spec s, char *passPhrase) dist = getVar(RPMVAR_DISTRIBUTION); } + if (s->prefix) { + prefix = s->prefix; + while (*prefix && (*prefix == '/')) { + prefix++; + } + if (! *prefix) { + prefix = NULL; + } + prefixLen = strlen(prefix); + } + /* Look through for each package */ pr = s->packages; while (pr) { @@ -475,7 +498,8 @@ int packageBinaries(Spec s, char *passPhrase) /**** Process the file list ****/ if (process_filelist(outHeader, pr, pr->filelist, &size, nametmp, - packageVersion, packageRelease, RPMLEAD_BINARY)) { + packageVersion, packageRelease, RPMLEAD_BINARY, + prefix)) { return 1; } @@ -491,6 +515,14 @@ int packageBinaries(Spec s, char *passPhrase) while (*file == '/') { file++; /* Skip leading "/" */ } + if (prefix) { + if (strncmp(prefix, file, prefixLen)) { + error(RPMERR_BADSPEC, "File doesn't match prefix: %s", + file); + return 1; + } + file += prefixLen + 1; /* 1 for "/" */ + } appendLineStringBuf(cpioFileList, file); } @@ -510,7 +542,7 @@ int packageBinaries(Spec s, char *passPhrase) name, getArchName()); if (generateRPM(name, filename, RPMLEAD_BINARY, outHeader, NULL, - getStringBuf(cpioFileList), passPhrase)) { + getStringBuf(cpioFileList), passPhrase, prefix)) { /* Build failed */ return 1; } @@ -653,7 +685,8 @@ int packageSource(Spec s, char *passPhrase) /* Process the file list */ if (process_filelist(outHeader, NULL, filelist, &size, - s->name, version, release, RPMLEAD_SOURCE)) { + s->name, version, release, RPMLEAD_SOURCE, + NULL)) { return 1; } @@ -668,7 +701,7 @@ int packageSource(Spec s, char *passPhrase) message(MESS_VERBOSE, "Source Packaging: %s\n", fullname); if (generateRPM(fullname, filename, RPMLEAD_SOURCE, outHeader, - tempdir, getStringBuf(cpioFileList), passPhrase)) { + tempdir, getStringBuf(cpioFileList), passPhrase, NULL)) { return 1; } diff --git a/build/spec.c b/build/spec.c index 0129e8a..1613aed 100644 --- a/build/spec.c +++ b/build/spec.c @@ -372,6 +372,7 @@ void freeSpec(Spec s) FREE(s->specfile); FREE(s->noSource); FREE(s->noPatch); + FREE(s->prefix); freeSources(s); freeStringBuf(s->prep); freeStringBuf(s->build); @@ -644,6 +645,7 @@ struct preamble_line { {RPMTAG_PROVIDES, 0, "provides"}, {RPMTAG_REQUIREFLAGS, 0, "requires"}, {RPMTAG_CONFLICTFLAGS, 0, "conflicts"}, + {RPMTAG_DEFAULTPREFIX, 0, "prefix"}, {0, 0, 0} }; @@ -795,6 +797,7 @@ Spec parseSpec(FILE *f, char *specfile) spec->noPatch = NULL; spec->numNoSource = 0; spec->numNoPatch = 0; + spec->prefix = NULL; sb = newStringBuf(); reset_spec(); /* Reset the parser */ @@ -995,6 +998,10 @@ Spec parseSpec(FILE *f, char *specfile) case RPMTAG_URL: addEntry(cur_package->header, tag, STRING_TYPE, s, 1); break; + case RPMTAG_DEFAULTPREFIX: + spec->prefix = strdup(s); + addEntry(cur_package->header, tag, STRING_TYPE, s, 1); + break; case RPMTAG_SERIAL: serial = atoi(s); addEntry(cur_package->header, tag, INT32_TYPE, &serial, 1); diff --git a/build/specP.h b/build/specP.h index 45ec269..91bccc6 100644 --- a/build/specP.h +++ b/build/specP.h @@ -39,6 +39,8 @@ struct SpecRec { StringBuf doc; StringBuf clean; + char *prefix; + struct PackageRec *packages; /* The first package record is the "main" package and contains * the bulk of the preamble information. Subsequent package -- 2.7.4