logic for handling Prefix:
authorroot <devnull@localhost>
Tue, 9 Jul 1996 02:06:26 +0000 (02:06 +0000)
committerroot <devnull@localhost>
Tue, 9 Jul 1996 02:06:26 +0000 (02:06 +0000)
CVS patchset: 748
CVS date: 1996/07/09 02:06:26

build/files.c
build/files.h
build/pack.c
build/spec.c
build/specP.h

index 4171106..ac931b3 100644 (file)
@@ -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() */
 }
index 2ac335e..aa06e66 100644 (file)
@@ -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_
index 473511b..ee8f747 100644 (file)
 #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;
     }
     
index 0129e8a..1613aed 100644 (file)
@@ -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);
index 45ec269..91bccc6 100644 (file)
@@ -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