Split install root creation out into command_init().
15 /* Import a yum filelist as a razor package set. */
19 YUM_STATE_PACKAGE_NAME,
29 XML_Parser primary_parser;
30 XML_Parser filelists_parser;
31 XML_Parser current_parser;
33 struct razor_importer *importer;
34 struct import_property_context *current_property_context;
35 char name[256], buffer[512], *p;
40 static enum razor_version_relation
41 yum_to_razor_flags (const char *flags)
45 return RAZOR_VERSION_EQUAL;
47 if (flags[0] == 'L') {
49 return RAZOR_VERSION_LESS;
51 return RAZOR_VERSION_LESS_OR_EQUAL;
52 } else if (flags[0] == 'G') {
54 return RAZOR_VERSION_GREATER;
56 return RAZOR_VERSION_GREATER_OR_EQUAL;
58 return RAZOR_VERSION_EQUAL;
62 yum_primary_start_element(void *data, const char *name, const char **atts)
64 struct yum_context *ctx = data;
65 const char *n, *epoch, *version, *release, *flags;
69 if (strcmp(name, "name") == 0) {
70 ctx->state = YUM_STATE_PACKAGE_NAME;
72 } else if (strcmp(name, "version") == 0) {
76 for (i = 0; atts[i]; i += 2) {
77 if (strcmp(atts[i], "epoch") == 0)
79 else if (strcmp(atts[i], "ver") == 0)
80 version = atts[i + 1];
81 else if (strcmp(atts[i], "rel") == 0)
82 release = atts[i + 1];
84 if (version == NULL || release == NULL) {
85 fprintf(stderr, "invalid version tag, "
86 "missing version or release attribute\n");
90 razor_build_evr(buffer, sizeof buffer, epoch, version, release);
91 razor_importer_begin_package(ctx->importer, ctx->name, buffer);
92 } else if (strcmp(name, "checksum") == 0) {
94 ctx->state = YUM_STATE_CHECKSUM;
95 } else if (strcmp(name, "rpm:requires") == 0) {
96 ctx->state = YUM_STATE_REQUIRES;
97 } else if (strcmp(name, "rpm:provides") == 0) {
98 ctx->state = YUM_STATE_PROVIDES;
99 } else if (strcmp(name, "rpm:obsoletes") == 0) {
100 ctx->state = YUM_STATE_OBSOLETES;
101 } else if (strcmp(name, "rpm:conflicts") == 0) {
102 ctx->state = YUM_STATE_CONFLICTS;
103 } else if (strcmp(name, "rpm:entry") == 0 &&
104 ctx->state != YUM_STATE_BEGIN) {
110 for (i = 0; atts[i]; i += 2) {
111 if (strcmp(atts[i], "name") == 0)
113 else if (strcmp(atts[i], "epoch") == 0)
115 else if (strcmp(atts[i], "ver") == 0)
116 version = atts[i + 1];
117 else if (strcmp(atts[i], "rel") == 0)
118 release = atts[i + 1];
119 else if (strcmp(atts[i], "flags") == 0)
124 fprintf(stderr, "invalid rpm:entry, "
125 "missing name or version attributes\n");
129 razor_build_evr(buffer, sizeof buffer, epoch, version, release);
130 switch (ctx->state) {
131 case YUM_STATE_REQUIRES:
132 razor_importer_add_property(ctx->importer, n,
133 yum_to_razor_flags (flags),
135 RAZOR_PROPERTY_REQUIRES);
137 case YUM_STATE_PROVIDES:
138 razor_importer_add_property(ctx->importer, n,
139 yum_to_razor_flags (flags),
141 RAZOR_PROPERTY_PROVIDES);
143 case YUM_STATE_OBSOLETES:
144 razor_importer_add_property(ctx->importer, n,
145 yum_to_razor_flags (flags),
147 RAZOR_PROPERTY_OBSOLETES);
149 case YUM_STATE_CONFLICTS:
150 razor_importer_add_property(ctx->importer, n,
151 yum_to_razor_flags (flags),
153 RAZOR_PROPERTY_CONFLICTS);
160 yum_primary_end_element (void *data, const char *name)
162 struct yum_context *ctx = data;
164 switch (ctx->state) {
165 case YUM_STATE_PACKAGE_NAME:
166 case YUM_STATE_CHECKSUM:
168 ctx->state = YUM_STATE_BEGIN;
172 if (strcmp(name, "package") == 0) {
173 XML_StopParser(ctx->current_parser, XML_TRUE);
174 ctx->current_parser = ctx->filelists_parser;
179 yum_character_data (void *data, const XML_Char *s, int len)
181 struct yum_context *ctx = data;
183 switch (ctx->state) {
184 case YUM_STATE_PACKAGE_NAME:
185 case YUM_STATE_CHECKSUM:
187 memcpy(ctx->p, s, len);
195 yum_filelists_start_element(void *data, const char *name, const char **atts)
197 struct yum_context *ctx = data;
198 const char *pkg, *pkgid;
201 if (strcmp(name, "package") == 0) {
204 for (i = 0; atts[i]; i += 2) {
205 if (strcmp(atts[i], "name") == 0)
207 else if (strcmp(atts[i], "pkgid") == 0)
210 if (strcmp(pkgid, ctx->pkgid) != 0)
211 fprintf(stderr, "primary.xml and filelists.xml "
212 "mismatch for %s: %s vs %s",
213 pkg, pkgid, ctx->pkgid);
214 } else if (strcmp(name, "file") == 0) {
215 ctx->state = YUM_STATE_FILE;
216 ctx->p = ctx->buffer;
222 yum_filelists_end_element (void *data, const char *name)
224 struct yum_context *ctx = data;
226 ctx->state = YUM_STATE_BEGIN;
227 if (strcmp(name, "package") == 0) {
228 XML_StopParser(ctx->current_parser, XML_TRUE);
229 ctx->current_parser = ctx->primary_parser;
230 razor_importer_finish_package(ctx->importer);
231 } else if (strcmp(name, "file") == 0)
232 razor_importer_add_file(ctx->importer, ctx->buffer);
236 #define XML_BUFFER_SIZE 4096
239 razor_set_create_from_yum(void)
241 struct yum_context ctx;
244 gzFile primary, filelists;
245 XML_ParsingStatus status;
247 ctx.importer = razor_importer_new();
248 ctx.state = YUM_STATE_BEGIN;
250 ctx.primary_parser = XML_ParserCreate(NULL);
251 XML_SetUserData(ctx.primary_parser, &ctx);
252 XML_SetElementHandler(ctx.primary_parser,
253 yum_primary_start_element,
254 yum_primary_end_element);
255 XML_SetCharacterDataHandler(ctx.primary_parser,
258 ctx.filelists_parser = XML_ParserCreate(NULL);
259 XML_SetUserData(ctx.filelists_parser, &ctx);
260 XML_SetElementHandler(ctx.filelists_parser,
261 yum_filelists_start_element,
262 yum_filelists_end_element);
263 XML_SetCharacterDataHandler(ctx.filelists_parser,
266 primary = gzopen("primary.xml.gz", "rb");
269 filelists = gzopen("filelists.xml.gz", "rb");
270 if (filelists == NULL)
273 ctx.current_parser = ctx.primary_parser;
276 XML_GetParsingStatus(ctx.current_parser, &status);
277 switch (status.parsing) {
279 ret = XML_ResumeParser(ctx.current_parser);
282 case XML_INITIALIZED:
283 buf = XML_GetBuffer(ctx.current_parser,
285 if (ctx.current_parser == ctx.primary_parser)
286 len = gzread(primary, buf, XML_BUFFER_SIZE);
288 len = gzread(filelists, buf, XML_BUFFER_SIZE);
291 "couldn't read input: %s\n",
296 XML_ParseBuffer(ctx.current_parser, len, len == 0);
301 } while (status.parsing != XML_FINISHED);
304 XML_ParserFree(ctx.primary_parser);
305 XML_ParserFree(ctx.filelists_parser);
310 return razor_importer_finish(ctx.importer);