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

Generated on Fri Aug 31 12:48:23 2007 for rpm by  doxygen 1.5.1