/** * Execute macro primitives. * @param mb macro expansion state * @param negate should logic be inverted? * @param f beginning of field f * @param fn length of field f * @param g beginning of field g * @param gn length of field g */ static void doFoo(MacroBuf mb, int negate, const char * f, size_t fn, const char * g, size_t gn) { size_t blen = MACROBUFSIZ + fn + gn; char *buf = xmalloc(blen); char *b = NULL, *be; int c; buf[0] = '\0'; if (g != NULL) { strncpy(buf, g, gn); buf[gn] = '\0'; (void) expandU(mb, buf, blen); } if (STREQ("basename", f, fn)) { if ((b = strrchr(buf, '/')) == NULL) b = buf; else b++; #if NOTYET /* XXX watchout for conflict with %dir */ } else if (STREQ("dirname", f, fn)) { if ((b = strrchr(buf, '/')) != NULL) *b = '\0'; b = buf; #endif } else if (STREQ("suffix", f, fn)) { if ((b = strrchr(buf, '.')) != NULL) b++; } else if (STREQ("expand", f, fn)) { b = buf; } else if (STREQ("verbose", f, fn)) { if (negate) b = (rpmIsVerbose() ? NULL : buf); else b = (rpmIsVerbose() ? buf : NULL); } else if (STREQ("url2path", f, fn) || STREQ("u2p", f, fn)) { (void)urlPath(buf, (const char **)&b); if (*b == '\0') b = "/"; } else if (STREQ("uncompress", f, fn)) { rpmCompressedMagic compressed = COMPRESSED_OTHER; for (b = buf; (c = *b) && isblank(c);) b++; for (be = b; (c = *be) && !isblank(c);) be++; *be++ = '\0'; (void) rpmFileIsCompressed(b, &compressed); switch(compressed) { default: case COMPRESSED_NOT: sprintf(be, "%%__cat %s", b); break; case COMPRESSED_OTHER: sprintf(be, "%%__gzip -dc %s", b); break; case COMPRESSED_BZIP2: sprintf(be, "%%__bzip2 -dc %s", b); break; case COMPRESSED_ZIP: sprintf(be, "%%__unzip %s", b); break; case COMPRESSED_LZMA: sprintf(be, "%%__lzma -dc %s", b); break; } b = be; } else if (STREQ("getenv", f, fn)) { b = getenv(buf); } else if (STREQ("S", f, fn)) { for (b = buf; (c = *b) && risdigit(c);) b++; if (!c) { /* digit index */ b++; sprintf(b, "%%SOURCE%s", buf); } else b = buf; } else if (STREQ("P", f, fn)) { for (b = buf; (c = *b) && risdigit(c);) b++; if (!c) { /* digit index */ b++; sprintf(b, "%%PATCH%s", buf); } else b = buf; } else if (STREQ("F", f, fn)) { b = buf + strlen(buf) + 1; sprintf(b, "file%s.file", buf); } if (b) { (void) expandT(mb, b, strlen(b)); } free(buf); }
/** * Expand %setup macro into %prep scriptlet. * @param spec build info * @param c source index * @param quietly should -vv be omitted from tar? * @return expanded %setup macro (NULL on error) */ static char *doUntar(rpmSpec spec, uint32_t c, int quietly) { char *fn; char *buf = NULL; char *tar, *taropts; struct Source *sp; rpmCompressedMagic compressed = COMPRESSED_NOT; for (sp = spec->sources; sp != NULL; sp = sp->next) { if ((sp->flags & RPMBUILD_ISSOURCE) && (sp->num == c)) { break; } } if (sp == NULL) { if (c) { rpmlog(RPMLOG_ERR, _("No source number %u\n"), c); } else { rpmlog(RPMLOG_ERR, _("No \"Source:\" tag in the spec file\n")); } return NULL; } fn = rpmGetPath("%{_sourcedir}/", sp->source, NULL); /* FIX: shrug */ taropts = ((rpmIsVerbose() && !quietly) ? "-xvvf" : "-xf"); #ifdef AUTOFETCH_NOT /* XXX don't expect this code to be enabled */ /* XXX * XXX If nosource file doesn't exist, try to fetch from url. * XXX TODO: add a "--fetch" enabler. */ if (sp->flags & RPMTAG_NOSOURCE && autofetchnosource) { struct stat st; int rc; if (lstat(fn, &st) != 0 && errno == ENOENT && urlIsUrl(sp->fullSource) != URL_IS_UNKNOWN) { if ((rc = urlGetFile(sp->fullSource, fn)) != 0) { rpmlog(RPMLOG_ERR, _("Couldn't download nosource %s: %s\n"), sp->fullSource); return NULL; } } } #endif /* XXX On non-build parse's, file cannot be stat'd or read */ if (!spec->force && (rpmFileIsCompressed(fn, &compressed) || checkOwners(fn))) { fn = _free(fn); return NULL; } tar = rpmGetPath("%{__tar}", NULL); if (compressed != COMPRESSED_NOT) { char *zipper, *t = NULL; int needtar = 1; switch (compressed) { case COMPRESSED_NOT: /* XXX can't happen */ case COMPRESSED_OTHER: t = "%{__gzip} -dc"; break; case COMPRESSED_BZIP2: t = "%{__bzip2} -dc"; break; case COMPRESSED_ZIP: if (rpmIsVerbose() && !quietly) t = "%{__unzip}"; else t = "%{__unzip} -qq"; needtar = 0; break; case COMPRESSED_LZMA: case COMPRESSED_XZ: t = "%{__xz} -dc"; break; } zipper = rpmGetPath(t, NULL); if (needtar) { rasprintf(&buf, "%s '%s' | %s %s - \n" "STATUS=$?\n" "if [ $STATUS -ne 0 ]; then\n" " exit $STATUS\n" "fi", zipper, fn, tar, taropts); } else { rasprintf(&buf, "%s '%s'\n" "STATUS=$?\n" "if [ $STATUS -ne 0 ]; then\n" " exit $STATUS\n" "fi", zipper, fn); } zipper = _free(zipper); } else { rasprintf(&buf, "%s %s %s", tar, taropts, fn); } fn = _free(fn); tar = _free(tar); return buf; }