Handle arch correctly in command_download() and print some status at the end.
15 /* Import a yum filelist as a razor package set. */
19 YUM_STATE_PACKAGE_NAME,
20 YUM_STATE_PACKAGE_ARCH,
30 XML_Parser primary_parser;
31 XML_Parser filelists_parser;
32 XML_Parser current_parser;
34 struct razor_importer *importer;
35 struct import_property_context *current_property_context;
36 char name[256], arch[64], buffer[512], *p;
41 static enum razor_version_relation
42 yum_to_razor_flags (const char *flags)
46 return RAZOR_VERSION_EQUAL;
48 if (flags[0] == 'L') {
50 return RAZOR_VERSION_LESS;
52 return RAZOR_VERSION_LESS_OR_EQUAL;
53 } else if (flags[0] == 'G') {
55 return RAZOR_VERSION_GREATER;
57 return RAZOR_VERSION_GREATER_OR_EQUAL;
59 return RAZOR_VERSION_EQUAL;
63 yum_primary_start_element(void *data, const char *name, const char **atts)
65 struct yum_context *ctx = data;
66 const char *n, *epoch, *version, *release, *flags;
70 if (strcmp(name, "name") == 0) {
71 ctx->state = YUM_STATE_PACKAGE_NAME;
73 } else if (strcmp(name, "arch") == 0) {
74 ctx->state = YUM_STATE_PACKAGE_ARCH;
76 } else if (strcmp(name, "version") == 0) {
80 for (i = 0; atts[i]; i += 2) {
81 if (strcmp(atts[i], "epoch") == 0)
83 else if (strcmp(atts[i], "ver") == 0)
84 version = atts[i + 1];
85 else if (strcmp(atts[i], "rel") == 0)
86 release = atts[i + 1];
88 if (version == NULL || release == NULL) {
89 fprintf(stderr, "invalid version tag, "
90 "missing version or release attribute\n");
94 razor_build_evr(buffer, sizeof buffer, epoch, version, release);
95 razor_importer_begin_package(ctx->importer,
96 ctx->name, buffer, ctx->arch);
97 } else if (strcmp(name, "checksum") == 0) {
99 ctx->state = YUM_STATE_CHECKSUM;
100 } else if (strcmp(name, "rpm:requires") == 0) {
101 ctx->state = YUM_STATE_REQUIRES;
102 } else if (strcmp(name, "rpm:provides") == 0) {
103 ctx->state = YUM_STATE_PROVIDES;
104 } else if (strcmp(name, "rpm:obsoletes") == 0) {
105 ctx->state = YUM_STATE_OBSOLETES;
106 } else if (strcmp(name, "rpm:conflicts") == 0) {
107 ctx->state = YUM_STATE_CONFLICTS;
108 } else if (strcmp(name, "rpm:entry") == 0 &&
109 ctx->state != YUM_STATE_BEGIN) {
115 for (i = 0; atts[i]; i += 2) {
116 if (strcmp(atts[i], "name") == 0)
118 else if (strcmp(atts[i], "epoch") == 0)
120 else if (strcmp(atts[i], "ver") == 0)
121 version = atts[i + 1];
122 else if (strcmp(atts[i], "rel") == 0)
123 release = atts[i + 1];
124 else if (strcmp(atts[i], "flags") == 0)
129 fprintf(stderr, "invalid rpm:entry, "
130 "missing name or version attributes\n");
134 razor_build_evr(buffer, sizeof buffer, epoch, version, release);
135 switch (ctx->state) {
136 case YUM_STATE_REQUIRES:
137 razor_importer_add_property(ctx->importer, n,
138 yum_to_razor_flags (flags),
140 RAZOR_PROPERTY_REQUIRES);
142 case YUM_STATE_PROVIDES:
143 razor_importer_add_property(ctx->importer, n,
144 yum_to_razor_flags (flags),
146 RAZOR_PROPERTY_PROVIDES);
148 case YUM_STATE_OBSOLETES:
149 razor_importer_add_property(ctx->importer, n,
150 yum_to_razor_flags (flags),
152 RAZOR_PROPERTY_OBSOLETES);
154 case YUM_STATE_CONFLICTS:
155 razor_importer_add_property(ctx->importer, n,
156 yum_to_razor_flags (flags),
158 RAZOR_PROPERTY_CONFLICTS);
165 yum_primary_end_element (void *data, const char *name)
167 struct yum_context *ctx = data;
169 switch (ctx->state) {
170 case YUM_STATE_PACKAGE_NAME:
171 case YUM_STATE_PACKAGE_ARCH:
172 case YUM_STATE_CHECKSUM:
174 ctx->state = YUM_STATE_BEGIN;
178 if (strcmp(name, "package") == 0) {
179 XML_StopParser(ctx->current_parser, XML_TRUE);
180 ctx->current_parser = ctx->filelists_parser;
185 yum_character_data (void *data, const XML_Char *s, int len)
187 struct yum_context *ctx = data;
189 switch (ctx->state) {
190 case YUM_STATE_PACKAGE_NAME:
191 case YUM_STATE_PACKAGE_ARCH:
192 case YUM_STATE_CHECKSUM:
194 memcpy(ctx->p, s, len);
202 yum_filelists_start_element(void *data, const char *name, const char **atts)
204 struct yum_context *ctx = data;
205 const char *pkg, *pkgid;
208 if (strcmp(name, "package") == 0) {
211 for (i = 0; atts[i]; i += 2) {
212 if (strcmp(atts[i], "name") == 0)
214 else if (strcmp(atts[i], "pkgid") == 0)
217 if (strcmp(pkgid, ctx->pkgid) != 0)
218 fprintf(stderr, "primary.xml and filelists.xml "
219 "mismatch for %s: %s vs %s",
220 pkg, pkgid, ctx->pkgid);
221 } else if (strcmp(name, "file") == 0) {
222 ctx->state = YUM_STATE_FILE;
223 ctx->p = ctx->buffer;
229 yum_filelists_end_element (void *data, const char *name)
231 struct yum_context *ctx = data;
233 ctx->state = YUM_STATE_BEGIN;
234 if (strcmp(name, "package") == 0) {
235 XML_StopParser(ctx->current_parser, XML_TRUE);
236 ctx->current_parser = ctx->primary_parser;
237 razor_importer_finish_package(ctx->importer);
238 } else if (strcmp(name, "file") == 0)
239 razor_importer_add_file(ctx->importer, ctx->buffer);
243 #define XML_BUFFER_SIZE 4096
246 razor_set_create_from_yum(void)
248 struct yum_context ctx;
251 gzFile primary, filelists;
252 XML_ParsingStatus status;
254 ctx.importer = razor_importer_new();
255 ctx.state = YUM_STATE_BEGIN;
257 ctx.primary_parser = XML_ParserCreate(NULL);
258 XML_SetUserData(ctx.primary_parser, &ctx);
259 XML_SetElementHandler(ctx.primary_parser,
260 yum_primary_start_element,
261 yum_primary_end_element);
262 XML_SetCharacterDataHandler(ctx.primary_parser,
265 ctx.filelists_parser = XML_ParserCreate(NULL);
266 XML_SetUserData(ctx.filelists_parser, &ctx);
267 XML_SetElementHandler(ctx.filelists_parser,
268 yum_filelists_start_element,
269 yum_filelists_end_element);
270 XML_SetCharacterDataHandler(ctx.filelists_parser,
273 primary = gzopen("primary.xml.gz", "rb");
276 filelists = gzopen("filelists.xml.gz", "rb");
277 if (filelists == NULL)
280 ctx.current_parser = ctx.primary_parser;
283 XML_GetParsingStatus(ctx.current_parser, &status);
284 switch (status.parsing) {
286 ret = XML_ResumeParser(ctx.current_parser);
289 case XML_INITIALIZED:
290 buf = XML_GetBuffer(ctx.current_parser,
292 if (ctx.current_parser == ctx.primary_parser)
293 len = gzread(primary, buf, XML_BUFFER_SIZE);
295 len = gzread(filelists, buf, XML_BUFFER_SIZE);
298 "couldn't read input: %s\n",
303 XML_ParseBuffer(ctx.current_parser, len, len == 0);
308 } while (status.parsing != XML_FINISHED);
311 XML_ParserFree(ctx.primary_parser);
312 XML_ParserFree(ctx.filelists_parser);
317 return razor_importer_finish(ctx.importer);