11 #include "solv_xfopen.h"
16 #if defined(FEDORA) || defined(MAGEIA)
17 #include "repoinfo_config_yum.h"
19 #include "repoinfo_download.h"
27 strcpy(tmpl, "/var/tmp/solvXXXXXX");
39 verify_checksum(int fd, const char *file, const unsigned char *chksum, Id chksumtype)
42 const unsigned char *sum;
46 h = solv_chksum_create(chksumtype);
49 printf("%s: unknown checksum type\n", file);
52 while ((l = read(fd, buf, sizeof(buf))) > 0)
53 solv_chksum_add(h, buf, l);
54 lseek(fd, 0, SEEK_SET);
56 sum = solv_chksum_get(h, &l);
57 if (memcmp(sum, chksum, l))
59 printf("%s: checksum mismatch\n", file);
60 solv_chksum_free(h, 0);
63 solv_chksum_free(h, 0);
68 curlfopen(struct repoinfo *cinfo, const char *file, int uncompress, const unsigned char *chksum, Id chksumtype, int markincomplete)
75 const char *baseurl = cinfo->baseurl;
79 if (!cinfo->metalink && !cinfo->mirrorlist)
81 if (file != cinfo->metalink && file != cinfo->mirrorlist)
83 unsigned char mlchksum[32];
85 fp = curlfopen(cinfo, cinfo->metalink ? cinfo->metalink : cinfo->mirrorlist, 0, 0, 0, 0);
89 cinfo->baseurl = findmetalinkurl(fp, mlchksum, &mlchksumtype);
91 cinfo->baseurl = findmirrorlisturl(fp);
95 #if defined(FEDORA) || defined(MAGEIA)
96 if (strchr(cinfo->baseurl, '$'))
98 char *b = yum_substitute(cinfo->repo->pool, cinfo->baseurl);
100 cinfo->baseurl = strdup(b);
103 if (!chksumtype && mlchksumtype && !strcmp(file, "repodata/repomd.xml"))
105 chksumtype = mlchksumtype;
108 return curlfopen(cinfo, file, uncompress, chksum, chksumtype, markincomplete);
110 snprintf(url, sizeof(url), "%s", file);
114 const char *path = cinfo->path && strcmp(cinfo->path, "/") != 0 ? cinfo->path : "";
115 int l = strlen(baseurl);
116 int pl = strlen(path);
117 const char *sep = l && baseurl[l - 1] == '/' ? "" : "/";
118 const char *psep = pl && cinfo->path[pl - 1] == '/' ? "" : "/";
119 snprintf(url, sizeof(url), "%s%s%s%s%s", baseurl, sep, path, psep, file);
122 // printf("url: %s\n", url);
123 if ((pid = fork()) == (pid_t)-1)
135 execlp("curl", "curl", "-f", "-s", "-L", url, (char *)0);
140 while (waitpid(pid, &status, 0) != pid)
142 if (lseek(fd, 0, SEEK_END) == 0 && (!status || !chksumtype))
148 lseek(fd, 0, SEEK_SET);
151 printf("%s: download error %d\n", file, status >> 8 ? status >> 8 : status);
153 cinfo->incomplete = 1;
157 if (chksumtype && !verify_checksum(fd, file, chksum, chksumtype))
160 cinfo->incomplete = 1;
164 fcntl(fd, F_SETFD, FD_CLOEXEC);
167 if (solv_xfopen_iscompressed(file) < 0)
169 printf("%s: unsupported compression\n", file);
171 cinfo->incomplete = 1;
175 fp = solv_xfopen_fd(file, fd, "r");
178 fp = fdopen(fd, "r");
185 downloadpackage(Solvable *s, const char *loc)
187 const unsigned char *chksum;
189 struct repoinfo *cinfo = s->repo->appdata;
191 #ifdef ENABLE_SUSEREPO
192 if (cinfo->type == TYPE_SUSETAGS)
194 const char *datadir = repo_lookup_str(cinfo->repo, SOLVID_META, SUSETAGS_DATADIR);
195 loc = pool_tmpjoin(s->repo->pool, datadir ? datadir : "suse", "/", loc);
199 chksum = solvable_lookup_bin_checksum(s, SOLVABLE_CHECKSUM, &chksumtype);
200 return curlfopen(cinfo, loc, 0, chksum, chksumtype, 0);
204 downloadchecksig(struct repoinfo *cinfo, FILE *fp, const char *sigurl, Pool **sigpool)
207 sigfp = curlfopen(cinfo, sigurl, 0, 0, 0, 0);
210 printf(" unsigned, skipped\n");
214 *sigpool = read_sigs();
215 if (!checksig(*sigpool, fp, sigfp))
217 printf(" checksig failed, skipped\n");