build/parsePrep.c

Go to the documentation of this file.
00001 
00006 #include "system.h"
00007 
00008 #include <rpmio_internal.h>
00009 #include <rpmbuild.h>
00010 #include "debug.h"
00011 
00012 /*@access StringBuf @*/ /* compared with NULL */
00013 
00014 /* These have to be global to make up for stupid compilers */
00015 /*@unchecked@*/
00016     static int leaveDirs, skipDefaultAction;
00017 /*@unchecked@*/
00018     static int createDir, quietly;
00019 /*@unchecked@*/ /*@observer@*/ /*@null@*/
00020     static const char * dirName = NULL;
00021 /*@unchecked@*/ /*@observer@*/
00022     static struct poptOption optionsTable[] = {
00023             { NULL, 'a', POPT_ARG_STRING, NULL, 'a',    NULL, NULL},
00024             { NULL, 'b', POPT_ARG_STRING, NULL, 'b',    NULL, NULL},
00025             { NULL, 'c', 0, &createDir, 0,              NULL, NULL},
00026             { NULL, 'D', 0, &leaveDirs, 0,              NULL, NULL},
00027             { NULL, 'n', POPT_ARG_STRING, &dirName, 0,  NULL, NULL},
00028             { NULL, 'T', 0, &skipDefaultAction, 0,      NULL, NULL},
00029             { NULL, 'q', 0, &quietly, 0,                NULL, NULL},
00030             { 0, 0, 0, 0, 0,    NULL, NULL}
00031     };
00032 
00038 static int checkOwners(const char * urlfn)
00039         /*@globals h_errno, fileSystem, internalState @*/
00040         /*@modifies fileSystem, internalState @*/
00041 {
00042     struct stat sb;
00043 
00044     if (Lstat(urlfn, &sb)) {
00045         rpmError(RPMERR_BADSPEC, _("Bad source: %s: %s\n"),
00046                 urlfn, strerror(errno));
00047         return RPMERR_BADSPEC;
00048     }
00049     if (!getUname(sb.st_uid) || !getGname(sb.st_gid)) {
00050         rpmError(RPMERR_BADSPEC, _("Bad owner/group: %s\n"), urlfn);
00051         return RPMERR_BADSPEC;
00052     }
00053 
00054     return 0;
00055 }
00056 
00067 /*@-boundswrite@*/
00068 /*@observer@*/
00069 static char *doPatch(Spec spec, int c, int strip, const char *db,
00070                      int reverse, int removeEmpties)
00071         /*@globals rpmGlobalMacroContext, h_errno, fileSystem, internalState @*/
00072         /*@modifies rpmGlobalMacroContext, fileSystem, internalState @*/
00073 {
00074     const char *fn, *Lurlfn;
00075     static char buf[BUFSIZ];
00076     char args[BUFSIZ];
00077     struct Source *sp;
00078     rpmCompressedMagic compressed = COMPRESSED_NOT;
00079     int urltype;
00080 
00081     args[0] = '\0';
00082     if (db) {
00083 #if HAVE_OLDPATCH_21 == 0
00084         strcat(args, "-b ");
00085 #endif
00086         strcat(args, "--suffix ");
00087         strcat(args, db);
00088     }
00089     if (reverse) {
00090         strcat(args, " -R");
00091     }
00092     if (removeEmpties) {
00093         strcat(args, " -E");
00094     }
00095 
00096     for (sp = spec->sources; sp != NULL; sp = sp->next) {
00097         if ((sp->flags & RPMFILE_PATCH) && (sp->num == c))
00098             break;
00099     }
00100     if (sp == NULL) {
00101         rpmError(RPMERR_BADSPEC, _("No patch number %d\n"), c);
00102         return NULL;
00103     }
00104 
00105     Lurlfn = rpmGenPath(NULL, "%{_patchdir}/", sp->source);
00106 
00107     /* XXX On non-build parse's, file cannot be stat'd or read */
00108     if (!spec->force && (isCompressed(Lurlfn, &compressed) || checkOwners(Lurlfn))) {
00109         Lurlfn = _free(Lurlfn);
00110         return NULL;
00111     }
00112 
00113     fn = NULL;
00114     urltype = urlPath(Lurlfn, &fn);
00115     switch (urltype) {
00116     case URL_IS_HTTPS:  /* XXX WRONG WRONG WRONG */
00117     case URL_IS_HTTP:   /* XXX WRONG WRONG WRONG */
00118     case URL_IS_FTP:    /* XXX WRONG WRONG WRONG */
00119     case URL_IS_HKP:    /* XXX WRONG WRONG WRONG */
00120     case URL_IS_PATH:
00121     case URL_IS_UNKNOWN:
00122         break;
00123     case URL_IS_DASH:
00124         Lurlfn = _free(Lurlfn);
00125         return NULL;
00126         /*@notreached@*/ break;
00127     }
00128 
00129     if (compressed) {
00130         const char *zipper;
00131 
00132         switch (compressed) {
00133         case COMPRESSED_NOT:    /* XXX can't happen */
00134         case COMPRESSED_OTHER:
00135         case COMPRESSED_ZIP:    /* XXX wrong */
00136             zipper = "%{__gzip}";
00137             break;
00138         case COMPRESSED_BZIP2:
00139             zipper = "%{__bzip2}";
00140             break;
00141         case COMPRESSED_LZOP:
00142             zipper = "%{__lzop}";
00143             break;
00144         case COMPRESSED_LZMA:
00145             zipper = "%{__lzma}";
00146             break;
00147         }
00148         zipper = rpmGetPath(zipper, NULL);
00149 
00150         sprintf(buf,
00151                 "echo \"Patch #%d (%s):\"\n"
00152                 "%s -d < '%s' | patch -p%d %s -s\n"
00153                 "STATUS=$?\n"
00154                 "if [ $STATUS -ne 0 ]; then\n"
00155                 "  exit $STATUS\n"
00156                 "fi",
00157                 c, /*@-unrecog@*/ (const char *) basename(fn), /*@=unrecog@*/
00158                 zipper,
00159                 fn, strip, args);
00160         zipper = _free(zipper);
00161     } else {
00162         sprintf(buf,
00163                 "echo \"Patch #%d (%s):\"\n"
00164                 "patch -p%d %s -s < '%s'", c, (const char *) basename(fn),
00165                 strip, args, fn);
00166     }
00167 
00168     Lurlfn = _free(Lurlfn);
00169     return buf;
00170 }
00171 /*@=boundswrite@*/
00172 
00180 /*@-boundswrite@*/
00181 /*@observer@*/
00182 static const char *doUntar(Spec spec, int c, int quietly)
00183         /*@globals rpmGlobalMacroContext, h_errno, fileSystem, internalState @*/
00184         /*@modifies rpmGlobalMacroContext, fileSystem, internalState @*/
00185 {
00186     const char *fn, *Lurlfn;
00187     static char buf[BUFSIZ];
00188     char *taropts;
00189     char *t = NULL;
00190     struct Source *sp;
00191     rpmCompressedMagic compressed = COMPRESSED_NOT;
00192     int urltype;
00193 
00194     for (sp = spec->sources; sp != NULL; sp = sp->next) {
00195         if ((sp->flags & RPMFILE_SOURCE) && (sp->num == c)) {
00196             break;
00197         }
00198     }
00199     if (sp == NULL) {
00200         rpmError(RPMERR_BADSPEC, _("No source number %d\n"), c);
00201         return NULL;
00202     }
00203 
00204     /*@-internalglobs@*/ /* FIX: shrug */
00205     taropts = ((rpmIsVerbose() && !quietly) ? "-xvvf" : "-xf");
00206     /*@=internalglobs@*/
00207 
00208     Lurlfn = rpmGenPath(NULL, "%{_sourcedir}/", sp->source);
00209 
00210     /* XXX On non-build parse's, file cannot be stat'd or read */
00211     if (!spec->force && (isCompressed(Lurlfn, &compressed) || checkOwners(Lurlfn))) {
00212         Lurlfn = _free(Lurlfn);
00213         return NULL;
00214     }
00215 
00216     fn = NULL;
00217     urltype = urlPath(Lurlfn, &fn);
00218     switch (urltype) {
00219     case URL_IS_HTTPS:  /* XXX WRONG WRONG WRONG */
00220     case URL_IS_HTTP:   /* XXX WRONG WRONG WRONG */
00221     case URL_IS_FTP:    /* XXX WRONG WRONG WRONG */
00222     case URL_IS_HKP:    /* XXX WRONG WRONG WRONG */
00223     case URL_IS_PATH:
00224     case URL_IS_UNKNOWN:
00225         break;
00226     case URL_IS_DASH:
00227         Lurlfn = _free(Lurlfn);
00228         return NULL;
00229         /*@notreached@*/ break;
00230     }
00231 
00232     if (compressed != COMPRESSED_NOT) {
00233         const char *zipper;
00234         int needtar = 1;
00235 
00236         switch (compressed) {
00237         case COMPRESSED_NOT:    /* XXX can't happen */
00238         case COMPRESSED_OTHER:
00239             t = "%{__gzip} -dc";
00240             break;
00241         case COMPRESSED_BZIP2:
00242             t = "%{__bzip2} -dc";
00243             break;
00244         case COMPRESSED_LZOP:
00245             t = "%{__lzop} -dc";
00246             break;
00247         case COMPRESSED_LZMA:
00248             t = "%{__lzma} -dc";
00249             break;
00250         case COMPRESSED_ZIP:
00251             if (rpmIsVerbose() && !quietly)
00252                 t = "%{__unzip}";
00253             else
00254                 t = "%{__unzip} -qq";
00255             needtar = 0;
00256             break;
00257         }
00258         zipper = rpmGetPath(t, NULL);
00259         buf[0] = '\0';
00260         t = stpcpy(buf, zipper);
00261         zipper = _free(zipper);
00262         *t++ = ' ';
00263         *t++ = '\'';
00264         t = stpcpy(t, fn);
00265         *t++ = '\'';
00266         if (needtar)
00267             t = stpcpy( stpcpy( stpcpy(t, " | tar "), taropts), " -");
00268         t = stpcpy(t,
00269                 "\n"
00270                 "STATUS=$?\n"
00271                 "if [ $STATUS -ne 0 ]; then\n"
00272                 "  exit $STATUS\n"
00273                 "fi");
00274     } else {
00275         buf[0] = '\0';
00276         t = stpcpy( stpcpy(buf, "tar "), taropts);
00277         *t++ = ' ';
00278         t = stpcpy(t, fn);
00279     }
00280 
00281     Lurlfn = _free(Lurlfn);
00282     return buf;
00283 }
00284 /*@=boundswrite@*/
00285 
00293 static int doSetupMacro(Spec spec, char *line)
00294         /*@globals rpmGlobalMacroContext, h_errno, fileSystem, internalState @*/
00295         /*@modifies spec->buildSubdir, spec->macros, spec->prep,
00296                 rpmGlobalMacroContext, fileSystem, internalState @*/
00297 {
00298     char buf[BUFSIZ];
00299     StringBuf before;
00300     StringBuf after;
00301     poptContext optCon;
00302     int argc;
00303     const char ** argv;
00304     int arg;
00305     const char * optArg;
00306     int rc;
00307     int num;
00308 
00309     /*@-mods@*/
00310     leaveDirs = skipDefaultAction = 0;
00311     createDir = quietly = 0;
00312     dirName = NULL;
00313     /*@=mods@*/
00314 
00315     if ((rc = poptParseArgvString(line, &argc, &argv))) {
00316         rpmError(RPMERR_BADSPEC, _("Error parsing %%setup: %s\n"),
00317                         poptStrerror(rc));
00318         return RPMERR_BADSPEC;
00319     }
00320 
00321     before = newStringBuf();
00322     after = newStringBuf();
00323 
00324     optCon = poptGetContext(NULL, argc, argv, optionsTable, 0);
00325     while ((arg = poptGetNextOpt(optCon)) > 0) {
00326         optArg = poptGetOptArg(optCon);
00327 
00328         /* We only parse -a and -b here */
00329 
00330         if (parseNum(optArg, &num)) {
00331             rpmError(RPMERR_BADSPEC, _("line %d: Bad arg to %%setup: %s\n"),
00332                      spec->lineNum, (optArg ? optArg : "???"));
00333             before = freeStringBuf(before);
00334             after = freeStringBuf(after);
00335             optCon = poptFreeContext(optCon);
00336             argv = _free(argv);
00337             return RPMERR_BADSPEC;
00338         }
00339 
00340         {   const char *chptr = doUntar(spec, num, quietly);
00341             if (chptr == NULL)
00342                 return RPMERR_BADSPEC;
00343 
00344             appendLineStringBuf((arg == 'a' ? after : before), chptr);
00345         }
00346     }
00347 
00348     if (arg < -1) {
00349         rpmError(RPMERR_BADSPEC, _("line %d: Bad %%setup option %s: %s\n"),
00350                  spec->lineNum,
00351                  poptBadOption(optCon, POPT_BADOPTION_NOALIAS), 
00352                  poptStrerror(arg));
00353         before = freeStringBuf(before);
00354         after = freeStringBuf(after);
00355         optCon = poptFreeContext(optCon);
00356         argv = _free(argv);
00357         return RPMERR_BADSPEC;
00358     }
00359 
00360     if (dirName) {
00361         spec->buildSubdir = xstrdup(dirName);
00362     } else {
00363         const char *name, *version;
00364         (void) headerNVR(spec->packages->header, &name, &version, NULL);
00365         sprintf(buf, "%s-%s", name, version);
00366         spec->buildSubdir = xstrdup(buf);
00367     }
00368     addMacro(spec->macros, "buildsubdir", NULL, spec->buildSubdir, RMIL_SPEC);
00369     
00370     optCon = poptFreeContext(optCon);
00371     argv = _free(argv);
00372 
00373     /* cd to the build dir */
00374     {   const char * buildDirURL = rpmGenPath(spec->rootURL, "%{_builddir}", "");
00375         const char *buildDir;
00376 
00377         (void) urlPath(buildDirURL, &buildDir);
00378         sprintf(buf, "cd '%s'", buildDir);
00379         appendLineStringBuf(spec->prep, buf);
00380         buildDirURL = _free(buildDirURL);
00381     }
00382     
00383     /* delete any old sources */
00384     if (!leaveDirs) {
00385         sprintf(buf, "rm -rf '%s'", spec->buildSubdir);
00386         appendLineStringBuf(spec->prep, buf);
00387     }
00388 
00389     /* if necessary, create and cd into the proper dir */
00390     if (createDir) {
00391         sprintf(buf, MKDIR_P " '%s'\ncd '%s'",
00392                 spec->buildSubdir, spec->buildSubdir);
00393         appendLineStringBuf(spec->prep, buf);
00394     }
00395 
00396     /* do the default action */
00397    if (!createDir && !skipDefaultAction) {
00398         const char *chptr = doUntar(spec, 0, quietly);
00399         if (!chptr)
00400             return RPMERR_BADSPEC;
00401         appendLineStringBuf(spec->prep, chptr);
00402     }
00403 
00404     appendStringBuf(spec->prep, getStringBuf(before));
00405     before = freeStringBuf(before);
00406 
00407     if (!createDir) {
00408         sprintf(buf, "cd '%s'", spec->buildSubdir);
00409         appendLineStringBuf(spec->prep, buf);
00410     }
00411 
00412     if (createDir && !skipDefaultAction) {
00413         const char * chptr = doUntar(spec, 0, quietly);
00414         if (chptr == NULL)
00415             return RPMERR_BADSPEC;
00416         appendLineStringBuf(spec->prep, chptr);
00417     }
00418     
00419     appendStringBuf(spec->prep, getStringBuf(after));
00420     after = freeStringBuf(after);
00421 
00422     /* XXX FIXME: owner & group fixes were conditioned on !geteuid() */
00423     /* Fix the owner, group, and permissions of the setup build tree */
00424     {   /*@observer@*/ static const char *fixmacs[] =
00425                 { "%{_fixowner}", "%{_fixgroup}", "%{_fixperms}", NULL };
00426         const char ** fm;
00427 
00428         for (fm = fixmacs; *fm; fm++) {
00429             const char *fix;
00430 /*@-boundsread@*/
00431             fix = rpmExpand(*fm, " .", NULL);
00432             if (fix && *fix != '%')
00433                 appendLineStringBuf(spec->prep, fix);
00434             fix = _free(fix);
00435 /*@=boundsread@*/
00436         }
00437     }
00438     
00439     return 0;
00440 }
00441 
00448 /*@-boundswrite@*/
00449 static int doPatchMacro(Spec spec, char *line)
00450         /*@globals rpmGlobalMacroContext, h_errno,
00451                 fileSystem, internalState @*/
00452         /*@modifies spec->prep, rpmGlobalMacroContext,
00453                 fileSystem, internalState  @*/
00454 {
00455     char *opt_b;
00456     int opt_P, opt_p, opt_R, opt_E;
00457     char *s;
00458     char buf[BUFSIZ], *bp;
00459     int patch_nums[1024];  /* XXX - we can only handle 1024 patches! */
00460     int patch_index, x;
00461 
00462     memset(patch_nums, 0, sizeof(patch_nums));
00463     opt_P = opt_p = opt_R = opt_E = 0;
00464     opt_b = NULL;
00465     patch_index = 0;
00466 
00467     if (! strchr(" \t\n", line[6])) {
00468         /* %patchN */
00469         sprintf(buf, "%%patch -P %s", line + 6);
00470     } else {
00471         strcpy(buf, line);
00472     }
00473     
00474     /*@-internalglobs@*/        /* FIX: strtok has state */
00475     for (bp = buf; (s = strtok(bp, " \t\n")) != NULL;) {
00476         if (bp) {       /* remove 1st token (%patch) */
00477             bp = NULL;
00478             continue;
00479         }
00480         if (!strcmp(s, "-P")) {
00481             opt_P = 1;
00482         } else if (!strcmp(s, "-R")) {
00483             opt_R = 1;
00484         } else if (!strcmp(s, "-E")) {
00485             opt_E = 1;
00486         } else if (!strcmp(s, "-b")) {
00487             /* orig suffix */
00488             opt_b = strtok(NULL, " \t\n");
00489             if (! opt_b) {
00490                 rpmError(RPMERR_BADSPEC,
00491                         _("line %d: Need arg to %%patch -b: %s\n"),
00492                         spec->lineNum, spec->line);
00493                 return RPMERR_BADSPEC;
00494             }
00495         } else if (!strcmp(s, "-z")) {
00496             /* orig suffix */
00497             opt_b = strtok(NULL, " \t\n");
00498             if (! opt_b) {
00499                 rpmError(RPMERR_BADSPEC,
00500                         _("line %d: Need arg to %%patch -z: %s\n"),
00501                         spec->lineNum, spec->line);
00502                 return RPMERR_BADSPEC;
00503             }
00504         } else if (!strncmp(s, "-p", sizeof("-p")-1)) {
00505             /* unfortunately, we must support -pX */
00506             if (! strchr(" \t\n", s[2])) {
00507                 s = s + 2;
00508             } else {
00509                 s = strtok(NULL, " \t\n");
00510                 if (s == NULL) {
00511                     rpmError(RPMERR_BADSPEC,
00512                              _("line %d: Need arg to %%patch -p: %s\n"),
00513                              spec->lineNum, spec->line);
00514                     return RPMERR_BADSPEC;
00515                 }
00516             }
00517             if (parseNum(s, &opt_p)) {
00518                 rpmError(RPMERR_BADSPEC,
00519                         _("line %d: Bad arg to %%patch -p: %s\n"),
00520                         spec->lineNum, spec->line);
00521                 return RPMERR_BADSPEC;
00522             }
00523         } else {
00524             /* Must be a patch num */
00525             if (patch_index == 1024) {
00526                 rpmError(RPMERR_BADSPEC, _("Too many patches!\n"));
00527                 return RPMERR_BADSPEC;
00528             }
00529             if (parseNum(s, &(patch_nums[patch_index]))) {
00530                 rpmError(RPMERR_BADSPEC, _("line %d: Bad arg to %%patch: %s\n"),
00531                          spec->lineNum, spec->line);
00532                 return RPMERR_BADSPEC;
00533             }
00534             patch_index++;
00535         }
00536     }
00537     /*@=internalglobs@*/
00538 
00539     /* All args processed */
00540 
00541     if (! opt_P) {
00542         s = doPatch(spec, 0, opt_p, opt_b, opt_R, opt_E);
00543         if (s == NULL)
00544             return RPMERR_BADSPEC;
00545         appendLineStringBuf(spec->prep, s);
00546     }
00547 
00548     for (x = 0; x < patch_index; x++) {
00549         s = doPatch(spec, patch_nums[x], opt_p, opt_b, opt_R, opt_E);
00550         if (s == NULL)
00551             return RPMERR_BADSPEC;
00552         appendLineStringBuf(spec->prep, s);
00553     }
00554     
00555     return 0;
00556 }
00557 /*@=boundswrite@*/
00558 
00562 static int prepFetch(Spec spec)
00563         /*@globals rpmGlobalMacroContext, h_errno, fileSystem, internalState @*/
00564         /*@modifies rpmGlobalMacroContext, fileSystem, internalState @*/
00565 {
00566     const char *Lmacro, *Lurlfn = NULL;
00567     const char *Rmacro, *Rurlfn = NULL;
00568     struct Source *sp;
00569     struct stat st;
00570     rpmRC rpmrc;
00571     int ec, rc;
00572 
00573     /* XXX insure that %{_sourcedir} exists */
00574     rpmrc = RPMRC_OK;
00575     Lurlfn = rpmGenPath(NULL, "%{?_sourcedir}", NULL);
00576     if (Lurlfn != NULL && *Lurlfn != '\0')
00577         rpmrc = rpmMkdirPath(Lurlfn, "_sourcedir");
00578     Lurlfn = _free(Lurlfn);
00579     if (rpmrc != RPMRC_OK)
00580         return -1;
00581 
00582     /* XXX insure that %{_patchdir} exists */
00583     rpmrc = RPMRC_OK;
00584     Lurlfn = rpmGenPath(NULL, "%{?_patchdir}", NULL);
00585     if (Lurlfn != NULL && *Lurlfn != '\0')
00586         rpmrc = rpmMkdirPath(Lurlfn, "_patchdir");
00587     Lurlfn = _free(Lurlfn);
00588     if (rpmrc != RPMRC_OK)
00589         return -1;
00590 
00591     /* XXX insure that %{_icondir} exists */
00592     rpmrc = RPMRC_OK;
00593     Lurlfn = rpmGenPath(NULL, "%{?_icondir}", NULL);
00594     if (Lurlfn != NULL && *Lurlfn != '\0')
00595         rpmrc = rpmMkdirPath(Lurlfn, "_icondir");
00596     Lurlfn = _free(Lurlfn);
00597     if (rpmrc != RPMRC_OK)
00598         return -1;
00599 
00600 /*@-branchstate@*/
00601     ec = 0;
00602     for (sp = spec->sources; sp != NULL; sp = sp->next) {
00603 
00604         if (sp->flags & RPMFILE_SOURCE) {
00605             Rmacro = "%{_Rsourcedir}/";
00606             Lmacro = "%{_sourcedir}/";
00607         } else
00608         if (sp->flags & RPMFILE_PATCH) {
00609             Rmacro = "%{_Rpatchdir}/";
00610             Lmacro = "%{_patchdir}/";
00611         } else
00612         if (sp->flags & RPMFILE_ICON) {
00613             Rmacro = "%{_Ricondir}/";
00614             Lmacro = "%{_icondir}/";
00615         } else
00616             continue;
00617 
00618         Lurlfn = rpmGenPath(NULL, Lmacro, sp->source);
00619         rc = Lstat(Lurlfn, &st);
00620         if (rc == 0)
00621             goto bottom;
00622         if (errno != ENOENT) {
00623             ec++;
00624             rpmError(RPMERR_BADFILENAME, _("Missing %s%d %s: %s\n"),
00625                 ((sp->flags & RPMFILE_SOURCE) ? "Source" : "Patch"),
00626                 sp->num, sp->source, strerror(ENOENT));
00627             goto bottom;
00628         }
00629 
00630         Rurlfn = rpmGenPath(NULL, Rmacro, sp->source);
00631         if (Rurlfn == NULL || *Rurlfn == '%' || !strcmp(Lurlfn, Rurlfn)) {
00632             rpmError(RPMERR_BADFILENAME, _("file %s missing: %s\n"),
00633                 Lurlfn, strerror(errno));
00634             ec++;
00635             goto bottom;
00636         }
00637 
00638         rc = urlGetFile(Rurlfn, Lurlfn);
00639         if (rc != 0) {
00640             rpmError(RPMERR_BADFILENAME, _("Fetching %s failed: %s\n"),
00641                 Rurlfn, ftpStrerror(rc));
00642             ec++;
00643             goto bottom;
00644         }
00645 
00646 bottom:
00647         Lurlfn = _free(Lurlfn);
00648         Rurlfn = _free(Rurlfn);
00649     }
00650 /*@=branchstate@*/
00651 
00652     return ec;
00653 }
00654 
00655 int parsePrep(Spec spec, int verify)
00656 {
00657     int nextPart, res, rc;
00658     StringBuf sb;
00659     char **lines, **saveLines;
00660 
00661     if (spec->prep != NULL) {
00662         rpmError(RPMERR_BADSPEC, _("line %d: second %%prep\n"), spec->lineNum);
00663         return RPMERR_BADSPEC;
00664     }
00665 
00666     spec->prep = newStringBuf();
00667 
00668     /* There are no options to %prep */
00669     if ((rc = readLine(spec, STRIP_NOTHING)) > 0)
00670         return PART_NONE;
00671     if (rc)
00672         return rc;
00673 
00674     /* Check to make sure that all sources/patches are present. */
00675     if (verify) {
00676         rc = prepFetch(spec);
00677         if (rc)
00678             return RPMERR_BADSPEC;
00679     }
00680     
00681     sb = newStringBuf();
00682     
00683     while (! (nextPart = isPart(spec->line))) {
00684         /* Need to expand the macros inline.  That way we  */
00685         /* can give good line number information on error. */
00686         appendStringBuf(sb, spec->line);
00687         if ((rc = readLine(spec, STRIP_NOTHING)) > 0) {
00688             nextPart = PART_NONE;
00689             break;
00690         }
00691         if (rc)
00692             return rc;
00693     }
00694 
00695     saveLines = splitString(getStringBuf(sb), strlen(getStringBuf(sb)), '\n');
00696     /*@-usereleased@*/
00697     for (lines = saveLines; *lines; lines++) {
00698         res = 0;
00699 /*@-boundsread@*/
00700         if (! strncmp(*lines, "%setup", sizeof("%setup")-1)) {
00701             res = doSetupMacro(spec, *lines);
00702         } else if (! strncmp(*lines, "%patch", sizeof("%patch")-1)) {
00703             res = doPatchMacro(spec, *lines);
00704         } else {
00705             appendLineStringBuf(spec->prep, *lines);
00706         }
00707 /*@=boundsread@*/
00708         if (res && !spec->force) {
00709             freeSplitString(saveLines);
00710             sb = freeStringBuf(sb);
00711             return res;
00712         }
00713     }
00714     /*@=usereleased@*/
00715 
00716     freeSplitString(saveLines);
00717     sb = freeStringBuf(sb);
00718 
00719     return nextPart;
00720 }

Generated on Wed Feb 6 22:32:28 2008 for rpm by  doxygen 1.5.1