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"
18 #include "repo_autopattern.h"
22 #include "repoinfo_cache.h"
23 #include "repoinfo_download.h"
24 #include "repoinfo_type_rpmmd.h"
29 repomd_find(Repo *repo, const char *what, const unsigned char **chksump, Id *chksumtypep)
31 Pool *pool = repo->pool;
38 dataiterator_init(&di, pool, repo, SOLVID_META, REPOSITORY_REPOMD_TYPE, what, SEARCH_STRING);
39 dataiterator_prepend_keyname(&di, REPOSITORY_REPOMD);
40 if (dataiterator_step(&di))
42 dataiterator_setpos_parent(&di);
43 filename = pool_lookup_str(pool, SOLVID_POS, REPOSITORY_REPOMD_LOCATION);
44 *chksump = pool_lookup_bin_checksum(pool, SOLVID_POS, REPOSITORY_REPOMD_CHECKSUM, chksumtypep);
46 dataiterator_free(&di);
47 if (filename && !*chksumtypep)
49 printf("no %s file checksum!\n", what);
56 repomd_add_ext(Repo *repo, Repodata *data, const char *what, const char *ext)
58 Id chksumtype, handle;
59 const unsigned char *chksum;
62 filename = repomd_find(repo, what, &chksum, &chksumtype);
63 if (!filename && !strcmp(what, "deltainfo"))
64 filename = repomd_find(repo, "prestodelta", &chksum, &chksumtype);
67 handle = repodata_new_handle(data);
68 repodata_set_poolstr(data, handle, REPOSITORY_REPOMD_TYPE, what);
69 repodata_set_str(data, handle, REPOSITORY_REPOMD_LOCATION, filename);
70 repodata_set_bin_checksum(data, handle, REPOSITORY_REPOMD_CHECKSUM, chksumtype, chksum);
71 add_ext_keys(data, handle, ext);
72 repodata_add_flexarray(data, SOLVID_META, REPOSITORY_EXTERNAL, handle);
76 repomd_load_ext(Repo *repo, Repodata *data)
78 const char *filename, *repomdtype;
81 struct repoinfo *cinfo;
82 const unsigned char *filechksum;
86 cinfo = repo->appdata;
87 repomdtype = repodata_lookup_str(data, SOLVID_META, REPOSITORY_REPOMD_TYPE);
90 if (!strcmp(repomdtype, "filelists"))
92 else if (!strcmp(repomdtype, "deltainfo"))
96 printf("[%s:%s", repo->name, ext);
97 if (usecachedrepo(cinfo, ext, 0))
99 printf(" cached]\n"); fflush(stdout);
102 printf(" fetching]\n"); fflush(stdout);
103 filename = repodata_lookup_str(data, SOLVID_META, REPOSITORY_REPOMD_LOCATION);
105 filechksum = repodata_lookup_bin_checksum(data, SOLVID_META, REPOSITORY_REPOMD_CHECKSUM, &filechksumtype);
106 if ((fp = curlfopen(cinfo, filename, 1, filechksum, filechksumtype, 0)) == 0)
108 if (!strcmp(ext, "FL"))
109 r = repo_add_rpmmd(repo, fp, ext, REPO_USE_LOADING|REPO_EXTEND_SOLVABLES|REPO_LOCALPOOL);
110 else if (!strcmp(ext, "DL"))
111 r = repo_add_deltainfoxml(repo, fp, REPO_USE_LOADING);
115 printf("%s\n", pool_errstr(repo->pool));
118 if (cinfo->extcookieset)
119 writecachedrepo(cinfo, ext, data);
124 repomd_load(struct repoinfo *cinfo, Pool **sigpoolp)
126 Repo *repo = cinfo->repo;
127 Pool *pool = repo->pool;
129 const char *filename;
130 const unsigned char *filechksum;
134 printf("rpmmd repo '%s':", cinfo->alias);
136 if ((fp = curlfopen(cinfo, "repodata/repomd.xml", 0, 0, 0, 0)) == 0)
138 printf(" no repomd.xml file\n");
139 cinfo->incomplete = 1;
142 calc_cookie_fp(fp, REPOKEY_TYPE_SHA256, cinfo->cookie);
143 cinfo->cookieset = 1;
144 if (usecachedrepo(cinfo, 0, 1))
150 if (cinfo->repo_gpgcheck && !downloadchecksig(cinfo, fp, "repodata/repomd.xml.asc", sigpoolp))
153 cinfo->incomplete = 1;
156 if (repo_add_repomdxml(repo, fp, 0))
158 printf("repomd.xml: %s\n", pool_errstr(pool));
159 cinfo->incomplete = 1;
164 printf(" fetching\n");
165 filename = repomd_find(repo, "primary", &filechksum, &filechksumtype);
166 if (filename && (fp = curlfopen(cinfo, filename, 1, filechksum, filechksumtype, 1)) != 0)
168 if (repo_add_rpmmd(repo, fp, 0, 0))
170 printf("primary: %s\n", pool_errstr(pool));
171 cinfo->incomplete = 1;
175 if (cinfo->incomplete)
176 return 0; /* hopeless */
178 filename = repomd_find(repo, "updateinfo", &filechksum, &filechksumtype);
179 if (filename && (fp = curlfopen(cinfo, filename, 1, filechksum, filechksumtype, 1)) != 0)
181 if (repo_add_updateinfoxml(repo, fp, 0))
183 printf("updateinfo: %s\n", pool_errstr(pool));
184 cinfo->incomplete = 1;
189 #ifdef ENABLE_APPDATA
190 filename = repomd_find(repo, "appdata", &filechksum, &filechksumtype);
191 if (filename && (fp = curlfopen(cinfo, filename, 1, filechksum, filechksumtype, 1)) != 0)
193 if (repo_add_appdata(repo, fp, 0))
195 printf("appdata: %s\n", pool_errstr(pool));
196 cinfo->incomplete = 1;
202 repo_add_autopattern(repo, 0);
204 data = repo_add_repodata(repo, 0);
205 repodata_extend_block(data, repo->start, repo->end - repo->start);
206 repomd_add_ext(repo, data, "deltainfo", "DL");
207 repomd_add_ext(repo, data, "filelists", "FL");
208 repodata_internalize(data);
209 writecachedrepo(cinfo, 0, 0);
210 repodata_create_stubs(repo_last_repodata(repo));