#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"
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;
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);
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);