10 #include "repo_content.h"
11 #include "repo_susetags.h"
13 #include "repo_appdata.h"
16 #include "repo_autopattern.h"
20 #include "repoinfo_cache.h"
21 #include "repoinfo_download.h"
22 #include "repoinfo_type_susetags.h"
24 /* susetags helpers */
27 susetags_find(Repo *repo, const char *what, const unsigned char **chksump, Id *chksumtypep)
29 Pool *pool = repo->pool;
36 dataiterator_init(&di, pool, repo, SOLVID_META, SUSETAGS_FILE_NAME, what, SEARCH_STRING);
37 dataiterator_prepend_keyname(&di, SUSETAGS_FILE);
38 if (dataiterator_step(&di))
40 dataiterator_setpos_parent(&di);
41 *chksump = pool_lookup_bin_checksum(pool, SOLVID_POS, SUSETAGS_FILE_CHECKSUM, chksumtypep);
44 dataiterator_free(&di);
45 if (filename && !*chksumtypep)
47 printf("no %s file checksum!\n", what);
54 susetags_add_ext(Repo *repo, Repodata *data)
56 Pool *pool = repo->pool;
59 Id handle, filechksumtype;
60 const unsigned char *filechksum;
62 dataiterator_init(&di, pool, repo, SOLVID_META, SUSETAGS_FILE_NAME, 0, 0);
63 dataiterator_prepend_keyname(&di, SUSETAGS_FILE);
64 while (dataiterator_step(&di))
66 if (strncmp(di.kv.str, "packages.", 9) != 0)
68 if (!strcmp(di.kv.str + 9, "gz"))
70 if (!di.kv.str[9] || !di.kv.str[10] || (di.kv.str[11] && di.kv.str[11] != '.'))
72 ext[0] = di.kv.str[9];
73 ext[1] = di.kv.str[10];
75 if (!strcmp(ext, "en"))
77 if (!susetags_find(repo, di.kv.str, &filechksum, &filechksumtype))
79 handle = repodata_new_handle(data);
80 repodata_set_str(data, handle, SUSETAGS_FILE_NAME, di.kv.str);
82 repodata_set_bin_checksum(data, handle, SUSETAGS_FILE_CHECKSUM, filechksumtype, filechksum);
83 add_ext_keys(data, handle, ext);
84 repodata_add_flexarray(data, SOLVID_META, REPOSITORY_EXTERNAL, handle);
86 dataiterator_free(&di);
90 susetags_load_ext(Repo *repo, Repodata *data)
92 const char *filename, *descrdir;
96 struct repoinfo *cinfo;
97 const unsigned char *filechksum;
101 cinfo = repo->appdata;
102 filename = repodata_lookup_str(data, SOLVID_META, SUSETAGS_FILE_NAME);
106 ext[0] = filename[9];
107 ext[1] = filename[10];
109 printf("[%s:%s", repo->name, ext);
110 if (usecachedrepo(cinfo, ext, 0))
112 printf(" cached]\n"); fflush(stdout);
115 printf(" fetching]\n"); fflush(stdout);
116 defvendor = repo_lookup_id(repo, SOLVID_META, SUSETAGS_DEFAULTVENDOR);
117 descrdir = repo_lookup_str(repo, SOLVID_META, SUSETAGS_DESCRDIR);
119 descrdir = "suse/setup/descr";
121 filechksum = repodata_lookup_bin_checksum(data, SOLVID_META, SUSETAGS_FILE_CHECKSUM, &filechksumtype);
122 if ((fp = curlfopen(cinfo, pool_tmpjoin(repo->pool, descrdir, "/", filename), 1, filechksum, filechksumtype, 0)) == 0)
124 flags = REPO_USE_LOADING|REPO_EXTEND_SOLVABLES;
125 if (strcmp(ext, "DL") != 0)
126 flags |= REPO_LOCALPOOL;
127 if (repo_add_susetags(repo, fp, defvendor, ext, flags))
130 printf("%s\n", pool_errstr(repo->pool));
134 writecachedrepo(cinfo, ext, data);
139 susetags_load(struct repoinfo *cinfo, Pool **sigpoolp)
141 Repo *repo = cinfo->repo;
142 Pool *pool = repo->pool;
144 const char *filename;
145 const unsigned char *filechksum;
148 const char *descrdir;
151 printf("susetags repo '%s':", cinfo->alias);
155 if ((fp = curlfopen(cinfo, "content", 0, 0, 0, 0)) == 0)
157 printf(" no content file\n");
158 cinfo->incomplete = 1;
161 calc_cookie_fp(fp, REPOKEY_TYPE_SHA256, cinfo->cookie);
162 cinfo->cookieset = 1;
163 if (usecachedrepo(cinfo, 0, 1))
169 if (cinfo->repo_gpgcheck && !downloadchecksig(cinfo, fp, "content.asc", sigpoolp))
172 cinfo->incomplete = 1;
175 if (repo_add_content(repo, fp, 0))
177 printf("content: %s\n", pool_errstr(pool));
179 cinfo->incomplete = 1;
183 defvendor = repo_lookup_id(repo, SOLVID_META, SUSETAGS_DEFAULTVENDOR);
184 descrdir = repo_lookup_str(repo, SOLVID_META, SUSETAGS_DESCRDIR);
186 descrdir = "suse/setup/descr";
187 filename = susetags_find(repo, "packages.gz", &filechksum, &filechksumtype);
189 filename = susetags_find(repo, "packages", &filechksum, &filechksumtype);
192 printf(" no packages file entry, skipped\n");
193 cinfo->incomplete = 1;
196 printf(" fetching\n");
197 if ((fp = curlfopen(cinfo, pool_tmpjoin(pool, descrdir, "/", filename), 1, filechksum, filechksumtype, 1)) == 0)
199 cinfo->incomplete = 1;
200 return 0; /* hopeless */
202 if (repo_add_susetags(repo, fp, defvendor, 0, REPO_NO_INTERNALIZE|SUSETAGS_RECORD_SHARES))
204 printf("packages: %s\n", pool_errstr(pool));
206 cinfo->incomplete = 1;
207 return 0; /* hopeless */
210 /* add default language */
211 filename = susetags_find(repo, "packages.en.gz", &filechksum, &filechksumtype);
213 filename = susetags_find(repo, "packages.en", &filechksum, &filechksumtype);
216 if ((fp = curlfopen(cinfo, pool_tmpjoin(pool, descrdir, "/", filename), 1, filechksum, filechksumtype, 1)) != 0)
218 if (repo_add_susetags(repo, fp, defvendor, 0, REPO_NO_INTERNALIZE|REPO_REUSE_REPODATA|REPO_EXTEND_SOLVABLES))
220 printf("packages.en: %s\n", pool_errstr(pool));
221 cinfo->incomplete = 1;
226 filename = susetags_find(repo, "patterns", &filechksum, &filechksumtype);
229 if ((fp = curlfopen(cinfo, pool_tmpjoin(pool, descrdir, "/", filename), 1, filechksum, filechksumtype, 1)) != 0)
232 while (fgets(pbuf, sizeof(pbuf), fp))
234 int l = strlen(pbuf);
236 if (l && pbuf[l - 1] == '\n')
238 if (!*pbuf || *pbuf == '.' || strchr(pbuf, '/') != 0)
240 filename = susetags_find(repo, pbuf, &filechksum, &filechksumtype);
241 if (filename && (fp2 = curlfopen(cinfo, pool_tmpjoin(pool, descrdir, "/", filename), 1, filechksum, filechksumtype, 1)) != 0)
243 if (repo_add_susetags(repo, fp2, defvendor, 0, REPO_NO_INTERNALIZE))
245 printf("%s: %s\n", pbuf, pool_errstr(pool));
246 cinfo->incomplete = 1;
254 #ifdef ENABLE_APPDATA
255 filename = susetags_find(repo, "appdata.xml.gz", &filechksum, &filechksumtype);
257 filename = susetags_find(repo, "appdata.xml", &filechksum, &filechksumtype);
258 if (filename && (fp = curlfopen(cinfo, pool_tmpjoin(pool, descrdir, "/", filename), 1, filechksum, filechksumtype, 1)) != 0)
260 if (repo_add_appdata(repo, fp, 0))
262 printf("appdata: %s\n", pool_errstr(pool));
263 cinfo->incomplete = 1;
268 repo_internalize(repo);
270 repo_add_autopattern(repo, 0);
272 data = repo_add_repodata(repo, 0);
273 repodata_extend_block(data, repo->start, repo->end - repo->start);
274 susetags_add_ext(repo, data);
275 repodata_internalize(data);
276 writecachedrepo(cinfo, 0, 0);
277 repodata_create_stubs(repo_last_repodata(repo));