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;
125 name = id2str(repo->pool, key->name);
126 p = strrchr(name, ':');
129 for (i = 0; i < kd->nlanguages; i++)
130 if (!strcmp(p + 1, kd->languages[i]))
131 return KEY_STORAGE_DROPPED;
133 for (i = 0; verticals[i]; i++)
134 if (key->name == verticals[i])
135 return KEY_STORAGE_VERTICAL_OFFSET;
136 return KEY_STORAGE_INCORE;
140 * Write <repo> to stdout
141 * If <attrname> is given, write attributes to <attrname>
142 * If <basename> is given, split attributes
146 tool_write(Repo *repo, const char *basename, const char *attrname)
150 Repodatafile *fileinfos = 0;
152 char **languages = 0;
158 struct keyfilter_other_data kd;
164 /* find languages and other info */
165 for (i = 0, data = repo->repodata; i < repo->nrepodata; i++, data++)
167 for (j = 1, key = data->keys + j; j < data->nkeys; j++, key++)
169 const char *keyname = id2str(repo->pool, key->name);
170 if (key->name == SOLVABLE_DISKUSAGE)
172 if (key->name == SOLVABLE_FILELIST)
174 for (k = 0; languagetags[k] != 0; k++)
175 if (!strncmp(keyname, languagetags[k], strlen(languagetags[k])))
177 if (!languagetags[k])
179 l = strlen(languagetags[k]);
180 if (strlen(keyname + l) > 5)
182 for (k = 0; k < nlanguages; k++)
183 if (!strcmp(languages[k], keyname + l))
187 languages = sat_realloc2(languages, nlanguages + 1, sizeof(char *));
188 languages[nlanguages++] = strdup(keyname + l);
191 fileinfos = sat_calloc(nlanguages + 2, sizeof(Repodatafile));
192 /* write language subfiles */
193 for (i = 0; i < nlanguages; i++)
195 sprintf(fn, "%s.%s.solv", basename, languages[i]);
196 if (!(fp = fopen(fn, "w")))
201 repo_write(repo, fp, keyfilter_language, languages[i], fileinfos + nfileinfos, 0);
202 fileinfos[nfileinfos++].location = strdup(fn);
205 /* write DU subfile */
208 sprintf(fn, "%s.DU.solv", basename);
209 if (!(fp = fopen(fn, "w")))
214 repo_write(repo, fp, keyfilter_DU, 0, fileinfos + nfileinfos, 0);
215 fileinfos[nfileinfos++].location = strdup(fn);
221 sprintf(fn, "%s.FL.solv", basename);
222 if (!(fp = fopen(fn, "w")))
227 repo_write(repo, fp, keyfilter_FL, 0, fileinfos + nfileinfos, 0);
228 fileinfos[nfileinfos++].location = strdup(fn);
231 /* write everything else */
232 sprintf(fn, "%s.solv", basename);
233 if (!(fp = fopen(fn, "w")))
238 kd.languages = languages;
239 kd.nlanguages = nlanguages;
240 repo_write(repo, fp, keyfilter_other, &kd, fileinfos, nfileinfos);
242 for (i = 0; i < nlanguages; i++)
245 for (i = 0; i < nfileinfos; i++)
247 sat_free(fileinfos[i].location);
248 sat_free(fileinfos[i].keys);
255 fileinfos = sat_calloc(1, sizeof(Repodatafile));
257 FILE *fp = fopen (attrname, "w");
258 repo_write(repo, fp, keyfilter_attr, 0, fileinfos + nfileinfos++, 0);
259 fileinfos[nfileinfos - 1].location = strdup(attrname);
262 repo_write(repo, stdout, keyfilter_solv, 0, fileinfos, nfileinfos);
265 free(fileinfos[0].location);
266 free(fileinfos[0].keys);