2 * Copyright (c) 2007, Novell Inc.
4 * This program is licensed under the BSD license, read LICENSE.BSD
5 * for further information
17 #include "repo_write.h"
18 #include "common_write.h"
20 static Id verticals[] = {
31 static char *languagetags[] = {
33 "solvable:description:",
34 "solvable:messageins:",
35 "solvable:messagedel:",
39 static int test_separate = 0;
42 keyfilter_solv(Repo *data, Repokey *key, void *kfdata)
45 if (test_separate && key->storage != KEY_STORAGE_SOLVABLE)
46 return KEY_STORAGE_DROPPED;
47 for (i = 0; verticals[i]; i++)
48 if (key->name == verticals[i])
49 return KEY_STORAGE_VERTICAL_OFFSET;
50 return KEY_STORAGE_INCORE;
54 keyfilter_attr(Repo *data, Repokey *key, void *kfdata)
57 if (key->storage == KEY_STORAGE_SOLVABLE)
58 return KEY_STORAGE_DROPPED;
59 for (i = 0; verticals[i]; i++)
60 if (key->name == verticals[i])
61 return KEY_STORAGE_VERTICAL_OFFSET;
62 return KEY_STORAGE_INCORE;
66 keyfilter_language(Repo *repo, Repokey *key, void *kfdata)
69 char *lang = kfdata, *bname;
73 name = id2str(repo->pool, key->name);
74 p = strrchr(name, ':');
75 if (!p || strcmp(p + 1, lang) != 0)
76 return KEY_STORAGE_DROPPED;
77 /* find base name id */
80 id = str2id(repo->pool, bname, 1);
81 for (i = 0; verticals[i]; i++)
82 if (id == verticals[i])
83 return KEY_STORAGE_VERTICAL_OFFSET;
84 return KEY_STORAGE_INCORE;
88 keyfilter_DU(Repo *repo, Repokey *key, void *kfdata)
91 if (key->name != SOLVABLE_DISKUSAGE)
92 return KEY_STORAGE_DROPPED;
93 for (i = 0; verticals[i]; i++)
94 if (key->name == verticals[i])
95 return KEY_STORAGE_VERTICAL_OFFSET;
96 return KEY_STORAGE_INCORE;
100 keyfilter_FL(Repo *repo, Repokey *key, void *kfdata)
103 if (key->name != SOLVABLE_FILELIST)
104 return KEY_STORAGE_DROPPED;
105 for (i = 0; verticals[i]; i++)
106 if (key->name == verticals[i])
107 return KEY_STORAGE_VERTICAL_OFFSET;
108 return KEY_STORAGE_INCORE;
111 struct keyfilter_other_data {
117 keyfilter_other(Repo *repo, Repokey *key, void *kfdata)
119 const char *name, *p;
120 struct keyfilter_other_data *kd = kfdata;
123 if (key->name == SOLVABLE_FILELIST || key->name == SOLVABLE_DISKUSAGE)
124 return KEY_STORAGE_DROPPED;
126 name = id2str(repo->pool, key->name);
127 p = strrchr(name, ':');
130 for (i = 0; i < kd->nlanguages; i++)
131 if (!strcmp(p + 1, kd->languages[i]))
132 return KEY_STORAGE_DROPPED;
134 for (i = 0; verticals[i]; i++)
135 if (key->name == verticals[i])
136 return KEY_STORAGE_VERTICAL_OFFSET;
137 return KEY_STORAGE_INCORE;
141 * Write <repo> to stdout
142 * If <attrname> is given, write attributes to <attrname>
143 * If <basename> is given, split attributes
146 #define REPODATAFILE_BLOCK 15
149 tool_write(Repo *repo, const char *basename, const char *attrname)
153 Repodatafile *fileinfos = 0;
155 char **languages = 0;
159 fileinfos = sat_zextend(fileinfos, nfileinfos, 1, sizeof(Repodatafile), REPODATAFILE_BLOCK);
160 pool_addfileprovides_ids(repo->pool, 0, &fileinfos[nfileinfos].addedfileprovides);
161 if (fileinfos[nfileinfos].addedfileprovides)
166 struct keyfilter_other_data kd;
172 /* find languages and other info */
173 for (i = 0, data = repo->repodata; i < repo->nrepodata; i++, data++)
175 for (j = 1, key = data->keys + j; j < data->nkeys; j++, key++)
177 const char *keyname = id2str(repo->pool, key->name);
178 if (key->name == SOLVABLE_DISKUSAGE)
180 if (key->name == SOLVABLE_FILELIST)
182 for (k = 0; languagetags[k] != 0; k++)
183 if (!strncmp(keyname, languagetags[k], strlen(languagetags[k])))
185 if (!languagetags[k])
187 l = strlen(languagetags[k]);
188 if (strlen(keyname + l) > 5)
190 for (k = 0; k < nlanguages; k++)
191 if (!strcmp(languages[k], keyname + l))
195 languages = sat_realloc2(languages, nlanguages + 1, sizeof(char *));
196 languages[nlanguages++] = strdup(keyname + l);
199 fileinfos = sat_zextend(fileinfos, nfileinfos, nlanguages + 2, sizeof(Repodatafile), REPODATAFILE_BLOCK);
200 /* write language subfiles */
201 for (i = 0; i < nlanguages; i++)
203 sprintf(fn, "%s.%s.solv", basename, languages[i]);
204 if (!(fp = fopen(fn, "w")))
209 repo_write(repo, fp, keyfilter_language, languages[i], fileinfos + nfileinfos, 0);
210 fileinfos[nfileinfos].location = strdup(fn);
214 /* write DU subfile */
217 sprintf(fn, "%s.DU.solv", basename);
218 if (!(fp = fopen(fn, "w")))
223 repo_write(repo, fp, keyfilter_DU, 0, fileinfos + nfileinfos, 0);
224 fileinfos[nfileinfos].location = strdup(fn);
231 sprintf(fn, "%s.FL.solv", basename);
232 if (!(fp = fopen(fn, "w")))
237 repo_write(repo, fp, keyfilter_FL, 0, fileinfos + nfileinfos, 0);
238 fileinfos[nfileinfos].location = strdup(fn);
242 /* write everything else */
243 sprintf(fn, "%s.solv", basename);
244 if (!(fp = fopen(fn, "w")))
249 kd.languages = languages;
250 kd.nlanguages = nlanguages;
251 repo_write(repo, fp, keyfilter_other, &kd, fileinfos, nfileinfos);
253 for (i = 0; i < nlanguages; i++)
256 for (i = 0; i < nfileinfos; i++)
258 sat_free(fileinfos[i].addedfileprovides);
259 sat_free(fileinfos[i].location);
260 sat_free(fileinfos[i].keys);
267 fileinfos = sat_zextend(fileinfos, nfileinfos, 1, sizeof(Repodatafile), REPODATAFILE_BLOCK);
269 FILE *fp = fopen (attrname, "w");
270 repo_write(repo, fp, keyfilter_attr, 0, fileinfos + nfileinfos, 0);
271 fileinfos[nfileinfos].location = strdup(attrname);
275 repo_write(repo, stdout, keyfilter_solv, 0, fileinfos, nfileinfos);
276 for (i = 0; i < nfileinfos; i++)
278 sat_free(fileinfos[i].addedfileprovides);
279 sat_free(fileinfos[i].location);
280 sat_free(fileinfos[i].keys);