10 #include "repo_rpmmd.h"
11 #include "repo_deltainfoxml.h"
12 #include "repo_updateinfoxml.h"
13 #include "repo_repomdxml.h"
15 #include "repo_appdata.h"
19 #include "repoinfo_cache.h"
20 #include "repoinfo_download.h"
21 #include "repoinfo_type_rpmmd.h"
26 repomd_find(Repo *repo, const char *what, const unsigned char **chksump, Id *chksumtypep)
28 Pool *pool = repo->pool;
35 dataiterator_init(&di, pool, repo, SOLVID_META, REPOSITORY_REPOMD_TYPE, what, SEARCH_STRING);
36 dataiterator_prepend_keyname(&di, REPOSITORY_REPOMD);
37 if (dataiterator_step(&di))
39 dataiterator_setpos_parent(&di);
40 filename = pool_lookup_str(pool, SOLVID_POS, REPOSITORY_REPOMD_LOCATION);
41 *chksump = pool_lookup_bin_checksum(pool, SOLVID_POS, REPOSITORY_REPOMD_CHECKSUM, chksumtypep);
43 dataiterator_free(&di);
44 if (filename && !*chksumtypep)
46 printf("no %s file checksum!\n", what);
53 repomd_add_ext(Repo *repo, Repodata *data, const char *what, const char *ext)
55 Id chksumtype, handle;
56 const unsigned char *chksum;
59 filename = repomd_find(repo, what, &chksum, &chksumtype);
60 if (!filename && !strcmp(what, "deltainfo"))
61 filename = repomd_find(repo, "prestodelta", &chksum, &chksumtype);
64 handle = repodata_new_handle(data);
65 repodata_set_poolstr(data, handle, REPOSITORY_REPOMD_TYPE, what);
66 repodata_set_str(data, handle, REPOSITORY_REPOMD_LOCATION, filename);
67 repodata_set_bin_checksum(data, handle, REPOSITORY_REPOMD_CHECKSUM, chksumtype, chksum);
68 add_ext_keys(data, handle, ext);
69 repodata_add_flexarray(data, SOLVID_META, REPOSITORY_EXTERNAL, handle);
73 repomd_load_ext(Repo *repo, Repodata *data)
75 const char *filename, *repomdtype;
78 struct repoinfo *cinfo;
79 const unsigned char *filechksum;
83 cinfo = repo->appdata;
84 repomdtype = repodata_lookup_str(data, SOLVID_META, REPOSITORY_REPOMD_TYPE);
87 if (!strcmp(repomdtype, "filelists"))
89 else if (!strcmp(repomdtype, "deltainfo"))
93 printf("[%s:%s", repo->name, ext);
94 if (usecachedrepo(cinfo, ext, 0))
96 printf(" cached]\n"); fflush(stdout);
99 printf(" fetching]\n"); fflush(stdout);
100 filename = repodata_lookup_str(data, SOLVID_META, REPOSITORY_REPOMD_LOCATION);
102 filechksum = repodata_lookup_bin_checksum(data, SOLVID_META, REPOSITORY_REPOMD_CHECKSUM, &filechksumtype);
103 if ((fp = curlfopen(cinfo, filename, 1, filechksum, filechksumtype, 0)) == 0)
105 if (!strcmp(ext, "FL"))
106 r = repo_add_rpmmd(repo, fp, ext, REPO_USE_LOADING|REPO_EXTEND_SOLVABLES|REPO_LOCALPOOL);
107 else if (!strcmp(ext, "DL"))
108 r = repo_add_deltainfoxml(repo, fp, REPO_USE_LOADING);
112 printf("%s\n", pool_errstr(repo->pool));
115 if (cinfo->extcookieset)
116 writecachedrepo(cinfo, ext, data);
121 repomd_load(struct repoinfo *cinfo, Pool **sigpoolp)
123 Repo *repo = cinfo->repo;
124 Pool *pool = repo->pool;
126 const char *filename;
127 const unsigned char *filechksum;
131 printf("rpmmd repo '%s':", cinfo->alias);
133 if ((fp = curlfopen(cinfo, "repodata/repomd.xml", 0, 0, 0, 0)) == 0)
135 printf(" no repomd.xml file\n");
136 cinfo->incomplete = 1;
139 calc_cookie_fp(fp, REPOKEY_TYPE_SHA256, cinfo->cookie);
140 cinfo->cookieset = 1;
141 if (usecachedrepo(cinfo, 0, 1))
147 if (cinfo->repo_gpgcheck && !downloadchecksig(cinfo, fp, "repodata/repomd.xml.asc", sigpoolp))
150 cinfo->incomplete = 1;
153 if (repo_add_repomdxml(repo, fp, 0))
155 printf("repomd.xml: %s\n", pool_errstr(pool));
156 cinfo->incomplete = 1;
161 printf(" fetching\n");
162 filename = repomd_find(repo, "primary", &filechksum, &filechksumtype);
163 if (filename && (fp = curlfopen(cinfo, filename, 1, filechksum, filechksumtype, 1)) != 0)
165 if (repo_add_rpmmd(repo, fp, 0, 0))
167 printf("primary: %s\n", pool_errstr(pool));
168 cinfo->incomplete = 1;
172 if (cinfo->incomplete)
173 return 0; /* hopeless */
175 filename = repomd_find(repo, "updateinfo", &filechksum, &filechksumtype);
176 if (filename && (fp = curlfopen(cinfo, filename, 1, filechksum, filechksumtype, 1)) != 0)
178 if (repo_add_updateinfoxml(repo, fp, 0))
180 printf("updateinfo: %s\n", pool_errstr(pool));
181 cinfo->incomplete = 1;
186 #ifdef ENABLE_APPDATA
187 filename = repomd_find(repo, "appdata", &filechksum, &filechksumtype);
188 if (filename && (fp = curlfopen(cinfo, filename, 1, filechksum, filechksumtype, 1)) != 0)
190 if (repo_add_appdata(repo, fp, 0))
192 printf("appdata: %s\n", pool_errstr(pool));
193 cinfo->incomplete = 1;
198 data = repo_add_repodata(repo, 0);
199 repodata_extend_block(data, repo->start, repo->end - repo->start);
200 repomd_add_ext(repo, data, "deltainfo", "DL");
201 repomd_add_ext(repo, data, "filelists", "FL");
202 repodata_internalize(data);
203 writecachedrepo(cinfo, 0, 0);
204 repodata_create_stubs(repo_last_repodata(repo));