11 #include "solv_xfopen.h"
14 #include "repoinfo_cache.h"
15 #include "repoinfo_download.h"
16 #include "repoinfo_type_mdk.h"
19 mdk_find(const char *md5sums, const char *what, unsigned char *chksum)
22 int wl = strlen(what);
23 for (sp = md5sums; (ep = strchr(sp, '\n')) != 0; sp = ep + 1)
28 if (sp[32] != ' ' || sp[33] != ' ')
30 if (wl != l - 34 || strncmp(what, sp + 34, wl) != 0)
32 if (solv_hex2bin(&sp, chksum, 16) != 16)
46 for (l = 0; ; l += ll)
51 buf = solv_realloc(buf, bufl);
53 ll = fread(buf + l, 1, bufl - l, fp);
70 mdk_load_ext(Repo *repo, Repodata *data)
72 struct repoinfo *cinfo = repo->appdata;
73 const char *type, *ext, *filename;
74 const unsigned char *filechksum;
79 type = repodata_lookup_str(data, SOLVID_META, REPOSITORY_REPOMD_TYPE);
80 if (strcmp(type, "filelists") != 0)
83 printf("[%s:%s", repo->name, ext);
84 if (usecachedrepo(cinfo, ext, 0))
86 printf(" cached]\n"); fflush(stdout);
89 printf(" fetching]\n"); fflush(stdout);
90 filename = repodata_lookup_str(data, SOLVID_META, REPOSITORY_REPOMD_LOCATION);
92 filechksum = repodata_lookup_bin_checksum(data, SOLVID_META, REPOSITORY_REPOMD_CHECKSUM, &filechksumtype);
93 if ((fp = curlfopen(cinfo, filename, 1, filechksum, filechksumtype, 0)) == 0)
95 r = repo_add_mdk_info(repo, fp, REPO_USE_LOADING|REPO_EXTEND_SOLVABLES|REPO_LOCALPOOL);
99 printf("%s\n", pool_errstr(repo->pool));
102 writecachedrepo(cinfo, ext, data);
107 mdk_add_ext(Repo *repo, Repodata *data, const char *what, const char *ext, const char *filename, Id chksumtype, const unsigned char *chksum)
109 Id handle = repodata_new_handle(data);
110 /* we mis-use the repomd ids here... need something generic in the future */
111 repodata_set_poolstr(data, handle, REPOSITORY_REPOMD_TYPE, what);
112 repodata_set_str(data, handle, REPOSITORY_REPOMD_LOCATION, filename);
113 repodata_set_bin_checksum(data, handle, REPOSITORY_REPOMD_CHECKSUM, chksumtype, chksum);
114 add_ext_keys(data, handle, ext);
115 repodata_add_flexarray(data, SOLVID_META, REPOSITORY_EXTERNAL, handle);
119 mdk_load(struct repoinfo *cinfo, Pool **sigpoolp)
121 Repo *repo = cinfo->repo;
122 Pool *pool = repo->pool;
124 const char *compression;
127 unsigned char probe[5];
128 unsigned char md5[16];
130 printf("mdk repo '%s':", cinfo->alias);
132 if ((fp = curlfopen(cinfo, "media_info/MD5SUM", 0, 0, 0, 0)) == 0)
134 printf(" no media_info/MD5SUM file\n");
135 cinfo->incomplete = 1;
138 calc_cookie_fp(fp, REPOKEY_TYPE_SHA256, cinfo->cookie);
139 cinfo->cookieset = 1;
140 if (usecachedrepo(cinfo, 0, 1))
148 printf(" fetching\n");
149 if (!mdk_find(md5sums, "synthesis.hdlist.cz", md5))
152 cinfo->incomplete = 1;
153 return 0; /* hopeless */
155 if ((fp = curlfopen(cinfo, "media_info/synthesis.hdlist.cz", 0, md5, REPOKEY_TYPE_MD5, 1)) == 0)
158 cinfo->incomplete = 1;
159 return 0; /* hopeless */
161 /* probe compression */
162 if (fread(probe, 5, 1, fp) != 1)
166 cinfo->incomplete = 1;
167 return 0; /* hopeless */
169 if (probe[0] == 0xfd && memcmp(probe + 1, "7zXZ", 4) == 0)
170 compression = "synthesis.hdlist.xz";
172 compression = "synthesis.hdlist.gz";
173 lseek(fileno(fp), 0, SEEK_SET);
174 cfp = solv_xfopen_fd(compression, dup(fileno(fp)), "r");
180 cinfo->incomplete = 1;
181 return 0; /* hopeless */
183 if (repo_add_mdk(repo, fp, REPO_NO_INTERNALIZE))
185 printf("synthesis.hdlist.cz: %s\n", pool_errstr(pool));
188 cinfo->incomplete = 1;
189 return 0; /* hopeless */
192 /* add info, could do this on demand, but always having the summary is nice */
193 if (mdk_find(md5sums, "info.xml.lzma", md5))
195 if ((fp = curlfopen(cinfo, "media_info/info.xml.lzma", 1, md5, REPOKEY_TYPE_MD5, 1)) != 0)
197 if (repo_add_mdk_info(repo, fp, REPO_NO_INTERNALIZE|REPO_REUSE_REPODATA|REPO_EXTEND_SOLVABLES))
199 printf("info.xml.lzma: %s\n", pool_errstr(pool));
200 cinfo->incomplete = 1;
205 repo_internalize(repo);
206 data = repo_add_repodata(repo, 0);
207 /* setup on-demand loading of filelist data */
208 if (mdk_find(md5sums, "files.xml.lzma", md5))
210 repodata_extend_block(data, repo->start, repo->end - repo->start);
211 mdk_add_ext(repo, data, "filelists", "FL", "media_info/files.xml.lzma", REPOKEY_TYPE_MD5, md5);
214 repodata_internalize(data);
215 writecachedrepo(cinfo, 0, 0);
216 repodata_create_stubs(repo_last_repodata(repo));