summaryrefslogtreecommitdiff
path: root/build/parsePreamble.c
diff options
context:
space:
mode:
authorJindrich Novy <jnovy@redhat.com>2011-04-19 13:24:34 +0200
committerJindrich Novy <jnovy@redhat.com>2011-04-19 13:24:34 +0200
commite0c941ab51f1ec905003ccc0926216ab49f2d058 (patch)
tree03ebe56a6155eef3a3b90b9d26ee9c5ce98e407c /build/parsePreamble.c
parent7ea4fcd87f9f313099f983380e9ece93149a0271 (diff)
downloadlibrpm-tizen-e0c941ab51f1ec905003ccc0926216ab49f2d058.tar.gz
librpm-tizen-e0c941ab51f1ec905003ccc0926216ab49f2d058.tar.bz2
librpm-tizen-e0c941ab51f1ec905003ccc0926216ab49f2d058.zip
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
Diffstat (limited to 'build/parsePreamble.c')
-rw-r--r--build/parsePreamble.c25
1 files changed, 25 insertions, 0 deletions
diff --git a/build/parsePreamble.c b/build/parsePreamble.c
index d9f2fdb02..4ca5df548 100644
--- a/build/parsePreamble.c
+++ b/build/parsePreamble.c
@@ -6,9 +6,11 @@
#include "system.h"
#include <ctype.h>
+#include <errno.h>
#include <rpm/header.h>
#include <rpm/rpmlog.h>
+#include <rpm/rpmurl.h>
#include <rpm/rpmfileutil.h>
#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);