From: Jindrich Novy Date: Tue, 19 Apr 2011 11:24:34 +0000 (+0200) Subject: Attempt to fetch sources/patches when they are missing from %_sourcedir X-Git-Tag: tznext/4.11.0.1.tizen20130304~1193 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=e0c941ab51f1ec905003ccc0926216ab49f2d058;p=tools%2Flibrpm-tizen.git Attempt to fetch sources/patches when they are missing from %_sourcedir - use _default_source_url macro to specify default URL when it is missing from the spec Source/Patch line - this feature can be disabled by defining _disable_source_fetch to 1 --- diff --git a/build/parsePreamble.c b/build/parsePreamble.c index d9f2fdb..4ca5df5 100644 --- a/build/parsePreamble.c +++ b/build/parsePreamble.c @@ -6,9 +6,11 @@ #include "system.h" #include +#include #include #include +#include #include #include "rpmio/rpmlua.h" #include "build/rpmbuild_internal.h" @@ -252,6 +254,7 @@ static int addSource(rpmSpec spec, Package pkg, const char *field, rpmTagVal tag p->flags = flag; p->source = strrchr(p->fullSource, '/'); if (p->source) { + if ((buf = strrchr(p->source,'='))) p->source = buf; p->source++; } else { p->source = p->fullSource; @@ -269,6 +272,28 @@ static int addSource(rpmSpec spec, Package pkg, const char *field, rpmTagVal tag if (tag != RPMTAG_ICON) { char *body = rpmGetPath("%{_sourcedir}/", p->source, NULL); + struct stat st; + + /* try to download source/patch if it's missing */ + if (lstat(body, &st) != 0 && errno == ENOENT && !rpmExpandNumeric("%{_disable_source_fetch}")) { + char *url = NULL; + if (urlIsURL(p->fullSource) != URL_IS_UNKNOWN) { + url = rstrdup(p->fullSource); + } else { + url = rpmExpand("%{_default_source_url}", NULL); + rstrcat(&url, p->source); + if (*url == '%') url = _free(url); + } + if (url) { + rpmlog(RPMLOG_WARNING, _("Downloading %s to %s\n"), url, body); + if (urlGetFile(url, body) != 0) { + free(url); + rpmlog(RPMLOG_ERR, _("Couldn't download %s\n"), p->fullSource); + return RPMRC_FAIL; + } + free(url); + } + } rasprintf(&buf, "%s%d", (flag & RPMBUILD_ISPATCH) ? "PATCH" : "SOURCE", num); diff --git a/build/parsePrep.c b/build/parsePrep.c index 1a9ee6a..de2b2a0 100644 --- a/build/parsePrep.c +++ b/build/parsePrep.c @@ -158,26 +158,6 @@ static char *doUntar(rpmSpec spec, uint32_t c, int quietly) fn = rpmGetPath("%{_sourcedir}/", sp->source, NULL); -#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->flags & RPMSPEC_FORCE) && (rpmFileIsCompressed(fn, &compressed) || checkOwners(fn))) { fn = _free(fn);