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_load(struct repoinfo *cinfo, Pool **sigpoolp)
109 Repo *repo = cinfo->repo;
110 Pool *pool = repo->pool;
112 const char *compression;
115 unsigned char probe[5];
116 unsigned char md5[16];
118 printf("mdk repo '%s':", cinfo->alias);
120 if ((fp = curlfopen(cinfo, "media_info/MD5SUM", 0, 0, 0, 0)) == 0)
122 printf(" no media_info/MD5SUM file\n");
123 cinfo->incomplete = 1;
126 calc_cookie_fp(fp, REPOKEY_TYPE_SHA256, cinfo->cookie);
127 cinfo->cookieset = 1;
128 if (usecachedrepo(cinfo, 0, 1))
136 printf(" fetching\n");
137 if (!mdk_find(md5sums, "synthesis.hdlist.cz", md5))
140 cinfo->incomplete = 1;
141 return 0; /* hopeless */
143 if ((fp = curlfopen(cinfo, "media_info/synthesis.hdlist.cz", 0, md5, REPOKEY_TYPE_MD5, 1)) == 0)
146 cinfo->incomplete = 1;
147 return 0; /* hopeless */
149 /* probe compression */
150 if (fread(probe, 5, 1, fp) != 1)
154 cinfo->incomplete = 1;
155 return 0; /* hopeless */
157 if (probe[0] == 0xfd && memcmp(probe + 1, "7zXZ", 4) == 0)
158 compression = "synthesis.hdlist.xz";
160 compression = "synthesis.hdlist.gz";
161 lseek(fileno(fp), 0, SEEK_SET);
162 cfp = solv_xfopen_fd(compression, dup(fileno(fp)), "r");
168 cinfo->incomplete = 1;
169 return 0; /* hopeless */
171 if (repo_add_mdk(repo, fp, REPO_NO_INTERNALIZE))
173 printf("synthesis.hdlist.cz: %s\n", pool_errstr(pool));
176 cinfo->incomplete = 1;
177 return 0; /* hopeless */
180 /* add info, could do this on demand, but always having the summary is nice */
181 if (mdk_find(md5sums, "info.xml.lzma", md5))
183 if ((fp = curlfopen(cinfo, "media_info/info.xml.lzma", 1, md5, REPOKEY_TYPE_MD5, 1)) != 0)
185 if (repo_add_mdk_info(repo, fp, REPO_NO_INTERNALIZE|REPO_REUSE_REPODATA|REPO_EXTEND_SOLVABLES))
187 printf("info.xml.lzma: %s\n", pool_errstr(pool));
188 cinfo->incomplete = 1;
193 repo_internalize(repo);
194 data = repo_add_repodata(repo, 0);
195 /* setup on-demand loading of filelist data */
196 if (mdk_find(md5sums, "files.xml.lzma", md5))
198 Id handle = repodata_new_handle(data);
199 /* we mis-use the repomd ids here... need something generic in the future */
200 repodata_set_poolstr(data, handle, REPOSITORY_REPOMD_TYPE, "filelists");
201 repodata_set_str(data, handle, REPOSITORY_REPOMD_LOCATION, "media_info/files.xml.lzma");
202 repodata_set_bin_checksum(data, handle, REPOSITORY_REPOMD_CHECKSUM, REPOKEY_TYPE_MD5, md5);
203 add_ext_keys(data, handle, "FL");
204 repodata_add_flexarray(data, SOLVID_META, REPOSITORY_EXTERNAL, handle);
207 repodata_internalize(data);
208 writecachedrepo(cinfo, 0, 0);
209 repodata_create_stubs(repo_last_repodata(repo));