11 #include "solv_xfopen.h"
16 #include "repoinfo_download.h"
24 strcpy(tmpl, "/var/tmp/solvXXXXXX");
36 verify_checksum(int fd, const char *file, const unsigned char *chksum, Id chksumtype)
39 const unsigned char *sum;
43 h = solv_chksum_create(chksumtype);
46 printf("%s: unknown checksum type\n", file);
49 while ((l = read(fd, buf, sizeof(buf))) > 0)
50 solv_chksum_add(h, buf, l);
51 lseek(fd, 0, SEEK_SET);
53 sum = solv_chksum_get(h, &l);
54 if (memcmp(sum, chksum, l))
56 printf("%s: checksum mismatch\n", file);
57 solv_chksum_free(h, 0);
60 solv_chksum_free(h, 0);
65 curlfopen(struct repoinfo *cinfo, const char *file, int uncompress, const unsigned char *chksum, Id chksumtype, int markincomplete)
72 const char *baseurl = cinfo->baseurl;
76 if (!cinfo->metalink && !cinfo->mirrorlist)
78 if (file != cinfo->metalink && file != cinfo->mirrorlist)
80 unsigned char mlchksum[32];
82 fp = curlfopen(cinfo, cinfo->metalink ? cinfo->metalink : cinfo->mirrorlist, 0, 0, 0, 0);
86 cinfo->baseurl = findmetalinkurl(fp, mlchksum, &mlchksumtype);
88 cinfo->baseurl = findmirrorlisturl(fp);
93 if (strchr(cinfo->baseurl, '$'))
95 char *b = yum_substitute(cinfo->repo->pool, cinfo->baseurl);
97 cinfo->baseurl = strdup(b);
100 if (!chksumtype && mlchksumtype && !strcmp(file, "repodata/repomd.xml"))
102 chksumtype = mlchksumtype;
105 return curlfopen(cinfo, file, uncompress, chksum, chksumtype, markincomplete);
107 snprintf(url, sizeof(url), "%s", file);
111 const char *path = cinfo->path && strcmp(cinfo->path, "/") != 0 ? cinfo->path : "";
112 int l = strlen(baseurl);
113 int pl = strlen(path);
114 const char *sep = l && baseurl[l - 1] == '/' ? "" : "/";
115 const char *psep = pl && cinfo->path[pl - 1] == '/' ? "" : "/";
116 snprintf(url, sizeof(url), "%s%s%s%s%s", baseurl, sep, path, psep, file);
119 // printf("url: %s\n", url);
120 if ((pid = fork()) == (pid_t)-1)
132 execlp("curl", "curl", "-f", "-s", "-L", url, (char *)0);
137 while (waitpid(pid, &status, 0) != pid)
139 if (lseek(fd, 0, SEEK_END) == 0 && (!status || !chksumtype))
145 lseek(fd, 0, SEEK_SET);
148 printf("%s: download error %d\n", file, status >> 8 ? status >> 8 : status);
150 cinfo->incomplete = 1;
154 if (chksumtype && !verify_checksum(fd, file, chksum, chksumtype))
157 cinfo->incomplete = 1;
161 fcntl(fd, F_SETFD, FD_CLOEXEC);
164 if (solv_xfopen_iscompressed(file) < 0)
166 printf("%s: unsupported compression\n", file);
168 cinfo->incomplete = 1;
172 fp = solv_xfopen_fd(file, fd, "r");
175 fp = fdopen(fd, "r");
182 downloadpackage(Solvable *s, const char *loc)
184 const unsigned char *chksum;
186 struct repoinfo *cinfo = s->repo->appdata;
188 #ifdef ENABLE_SUSEREPO
189 if (cinfo->type == TYPE_SUSETAGS)
191 const char *datadir = repo_lookup_str(cinfo->repo, SOLVID_META, SUSETAGS_DATADIR);
192 loc = pool_tmpjoin(s->repo->pool, datadir ? datadir : "suse", "/", loc);
196 chksum = solvable_lookup_bin_checksum(s, SOLVABLE_CHECKSUM, &chksumtype);
197 return curlfopen(cinfo, loc, 0, chksum, chksumtype, 0);
201 downloadchecksig(struct repoinfo *cinfo, FILE *fp, const char *sigurl, Pool **sigpool)
204 sigfp = curlfopen(cinfo, sigurl, 0, 0, 0, 0);
207 printf(" unsigned, skipped\n");
211 *sigpool = read_sigs();
212 if (!checksig(*sigpool, fp, sigfp))
214 printf(" checksig failed, skipped\n");