10 #include "repo_content.h"
11 #include "repo_susetags.h"
13 #include "repo_appdata.h"
17 #include "repoinfo_cache.h"
18 #include "repoinfo_download.h"
19 #include "repoinfo_type_susetags.h"
21 /* susetags helpers */
24 susetags_find(Repo *repo, const char *what, const unsigned char **chksump, Id *chksumtypep)
26 Pool *pool = repo->pool;
33 dataiterator_init(&di, pool, repo, SOLVID_META, SUSETAGS_FILE_NAME, what, SEARCH_STRING);
34 dataiterator_prepend_keyname(&di, SUSETAGS_FILE);
35 if (dataiterator_step(&di))
37 dataiterator_setpos_parent(&di);
38 *chksump = pool_lookup_bin_checksum(pool, SOLVID_POS, SUSETAGS_FILE_CHECKSUM, chksumtypep);
41 dataiterator_free(&di);
42 if (filename && !*chksumtypep)
44 printf("no %s file checksum!\n", what);
51 susetags_add_ext(Repo *repo, Repodata *data)
53 Pool *pool = repo->pool;
56 Id handle, filechksumtype;
57 const unsigned char *filechksum;
59 dataiterator_init(&di, pool, repo, SOLVID_META, SUSETAGS_FILE_NAME, 0, 0);
60 dataiterator_prepend_keyname(&di, SUSETAGS_FILE);
61 while (dataiterator_step(&di))
63 if (strncmp(di.kv.str, "packages.", 9) != 0)
65 if (!strcmp(di.kv.str + 9, "gz"))
67 if (!di.kv.str[9] || !di.kv.str[10] || (di.kv.str[11] && di.kv.str[11] != '.'))
69 ext[0] = di.kv.str[9];
70 ext[1] = di.kv.str[10];
72 if (!strcmp(ext, "en"))
74 if (!susetags_find(repo, di.kv.str, &filechksum, &filechksumtype))
76 handle = repodata_new_handle(data);
77 repodata_set_str(data, handle, SUSETAGS_FILE_NAME, di.kv.str);
79 repodata_set_bin_checksum(data, handle, SUSETAGS_FILE_CHECKSUM, filechksumtype, filechksum);
80 add_ext_keys(data, handle, ext);
81 repodata_add_flexarray(data, SOLVID_META, REPOSITORY_EXTERNAL, handle);
83 dataiterator_free(&di);
87 susetags_load_ext(Repo *repo, Repodata *data)
89 const char *filename, *descrdir;
93 struct repoinfo *cinfo;
94 const unsigned char *filechksum;
98 cinfo = repo->appdata;
99 filename = repodata_lookup_str(data, SOLVID_META, SUSETAGS_FILE_NAME);
103 ext[0] = filename[9];
104 ext[1] = filename[10];
106 printf("[%s:%s", repo->name, ext);
107 if (usecachedrepo(cinfo, ext, 0))
109 printf(" cached]\n"); fflush(stdout);
112 printf(" fetching]\n"); fflush(stdout);
113 defvendor = repo_lookup_id(repo, SOLVID_META, SUSETAGS_DEFAULTVENDOR);
114 descrdir = repo_lookup_str(repo, SOLVID_META, SUSETAGS_DESCRDIR);
116 descrdir = "suse/setup/descr";
118 filechksum = repodata_lookup_bin_checksum(data, SOLVID_META, SUSETAGS_FILE_CHECKSUM, &filechksumtype);
119 if ((fp = curlfopen(cinfo, pool_tmpjoin(repo->pool, descrdir, "/", filename), 1, filechksum, filechksumtype, 0)) == 0)
121 flags = REPO_USE_LOADING|REPO_EXTEND_SOLVABLES;
122 if (strcmp(ext, "DL") != 0)
123 flags |= REPO_LOCALPOOL;
124 if (repo_add_susetags(repo, fp, defvendor, ext, flags))
127 printf("%s\n", pool_errstr(repo->pool));
131 writecachedrepo(cinfo, ext, data);
136 susetags_load(struct repoinfo *cinfo, Pool **sigpoolp)
138 Repo *repo = cinfo->repo;
139 Pool *pool = repo->pool;
141 const char *filename;
142 const unsigned char *filechksum;
145 const char *descrdir;
148 printf("susetags repo '%s':", cinfo->alias);
152 if ((fp = curlfopen(cinfo, "content", 0, 0, 0, 0)) == 0)
154 printf(" no content file\n");
155 cinfo->incomplete = 1;
158 calc_cookie_fp(fp, REPOKEY_TYPE_SHA256, cinfo->cookie);
159 cinfo->cookieset = 1;
160 if (usecachedrepo(cinfo, 0, 1))
166 if (cinfo->repo_gpgcheck && !downloadchecksig(cinfo, fp, "content.asc", sigpoolp))
169 cinfo->incomplete = 1;
172 if (repo_add_content(repo, fp, 0))
174 printf("content: %s\n", pool_errstr(pool));
176 cinfo->incomplete = 1;
180 defvendor = repo_lookup_id(repo, SOLVID_META, SUSETAGS_DEFAULTVENDOR);
181 descrdir = repo_lookup_str(repo, SOLVID_META, SUSETAGS_DESCRDIR);
183 descrdir = "suse/setup/descr";
184 filename = susetags_find(repo, "packages.gz", &filechksum, &filechksumtype);
186 filename = susetags_find(repo, "packages", &filechksum, &filechksumtype);
189 printf(" no packages file entry, skipped\n");
190 cinfo->incomplete = 1;
193 printf(" fetching\n");
194 if ((fp = curlfopen(cinfo, pool_tmpjoin(pool, descrdir, "/", filename), 1, filechksum, filechksumtype, 1)) == 0)
196 cinfo->incomplete = 1;
197 return 0; /* hopeless */
199 if (repo_add_susetags(repo, fp, defvendor, 0, REPO_NO_INTERNALIZE|SUSETAGS_RECORD_SHARES))
201 printf("packages: %s\n", pool_errstr(pool));
203 cinfo->incomplete = 1;
204 return 0; /* hopeless */
207 /* add default language */
208 filename = susetags_find(repo, "packages.en.gz", &filechksum, &filechksumtype);
210 filename = susetags_find(repo, "packages.en", &filechksum, &filechksumtype);
213 if ((fp = curlfopen(cinfo, pool_tmpjoin(pool, descrdir, "/", filename), 1, filechksum, filechksumtype, 1)) != 0)
215 if (repo_add_susetags(repo, fp, defvendor, 0, REPO_NO_INTERNALIZE|REPO_REUSE_REPODATA|REPO_EXTEND_SOLVABLES))
217 printf("packages.en: %s\n", pool_errstr(pool));
218 cinfo->incomplete = 1;
223 filename = susetags_find(repo, "patterns", &filechksum, &filechksumtype);
226 if ((fp = curlfopen(cinfo, pool_tmpjoin(pool, descrdir, "/", filename), 1, filechksum, filechksumtype, 1)) != 0)
229 while (fgets(pbuf, sizeof(pbuf), fp))
231 int l = strlen(pbuf);
233 if (l && pbuf[l - 1] == '\n')
235 if (!*pbuf || *pbuf == '.' || strchr(pbuf, '/') != 0)
237 filename = susetags_find(repo, pbuf, &filechksum, &filechksumtype);
238 if (filename && (fp2 = curlfopen(cinfo, pool_tmpjoin(pool, descrdir, "/", filename), 1, filechksum, filechksumtype, 1)) != 0)
240 if (repo_add_susetags(repo, fp2, defvendor, 0, REPO_NO_INTERNALIZE))
242 printf("%s: %s\n", pbuf, pool_errstr(pool));
243 cinfo->incomplete = 1;
251 #ifdef ENABLE_APPDATA
252 filename = susetags_find(repo, "appdata.xml.gz", &filechksum, &filechksumtype);
254 filename = susetags_find(repo, "appdata.xml", &filechksum, &filechksumtype);
255 if (filename && (fp = curlfopen(cinfo, pool_tmpjoin(pool, descrdir, "/", filename), 1, filechksum, filechksumtype, 1)) != 0)
257 if (repo_add_appdata(repo, fp, 0))
259 printf("appdata: %s\n", pool_errstr(pool));
260 cinfo->incomplete = 1;
265 repo_internalize(repo);
266 data = repo_add_repodata(repo, 0);
267 repodata_extend_block(data, repo->start, repo->end - repo->start);
268 susetags_add_ext(repo, data);
269 repodata_internalize(data);
270 writecachedrepo(cinfo, 0, 0);
271 repodata_create_stubs(repo_last_repodata(repo));