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