Parse filelists.xml.gz too, so we import the yum files too.
1.1 --- a/Makefile Sun Nov 04 00:58:57 2007 -0400
1.2 +++ b/Makefile Sun Nov 04 01:11:53 2007 -0400
1.3 @@ -1,5 +1,5 @@
1.4 CFLAGS = -Wall -g -O2
1.5 -LDLIBS = -lexpat -g -lrpm
1.6 +LDLIBS = -lexpat -lz -g -lrpm
1.7
1.8 razor : razor.o import.o sha1.o main.o
1.9
2.1 --- a/TODO Sun Nov 04 00:58:57 2007 -0400
2.2 +++ b/TODO Sun Nov 04 01:11:53 2007 -0400
2.3 @@ -18,6 +18,11 @@
2.4
2.5 - figure out how to canonically represent empty string... ~0?
2.6
2.7 +- space calculation before transaction, but ideally, do a number of
2.8 + smaller transactions.
2.9 +
2.10 +- pre-link changing binaries and libs on disk screwing up checksum?
2.11 +
2.12 Misc ideas:
2.13
2.14 - eliminate duplicate entries in package property lists.
3.1 --- a/import.c Sun Nov 04 00:58:57 2007 -0400
3.2 +++ b/import.c Sun Nov 04 01:11:53 2007 -0400
3.3 @@ -9,6 +9,7 @@
3.4 #include <errno.h>
3.5
3.6 #include <expat.h>
3.7 +#include <zlib.h>
3.8 #include <rpm/rpmlib.h>
3.9 #include <rpm/rpmdb.h>
3.10 #include "sha1.h"
3.11 @@ -157,6 +158,7 @@
3.12 enum {
3.13 YUM_STATE_BEGIN,
3.14 YUM_STATE_PACKAGE_NAME,
3.15 + YUM_STATE_CHECKSUM,
3.16 YUM_STATE_REQUIRES,
3.17 YUM_STATE_PROVIDES,
3.18 YUM_STATE_OBSOLETES,
3.19 @@ -165,14 +167,19 @@
3.20 };
3.21
3.22 struct yum_context {
3.23 + XML_Parser primary_parser;
3.24 + XML_Parser filelists_parser;
3.25 + XML_Parser current_parser;
3.26 +
3.27 struct razor_importer *importer;
3.28 struct import_property_context *current_property_context;
3.29 char name[256], buffer[512], *p;
3.30 + char pkgid[128];
3.31 int state;
3.32 };
3.33
3.34 static void
3.35 -yum_start_element(void *data, const char *name, const char **atts)
3.36 +yum_primary_start_element(void *data, const char *name, const char **atts)
3.37 {
3.38 struct yum_context *ctx = data;
3.39 const char *n, *version, *release;
3.40 @@ -199,6 +206,9 @@
3.41
3.42 snprintf(buffer, sizeof buffer, "%s-%s", version, release);
3.43 razor_importer_begin_package(ctx->importer, ctx->name, buffer);
3.44 + } else if (strcmp(name, "checksum") == 0) {
3.45 + ctx->p = ctx->pkgid;
3.46 + ctx->state = YUM_STATE_CHECKSUM;
3.47 } else if (strcmp(name, "rpm:requires") == 0) {
3.48 ctx->state = YUM_STATE_REQUIRES;
3.49 } else if (strcmp(name, "rpm:provides") == 0) {
3.50 @@ -253,28 +263,26 @@
3.51 RAZOR_PROPERTY_CONFLICTS);
3.52 break;
3.53 }
3.54 - } else if (strcmp(name, "file") == 0) {
3.55 - ctx->state = YUM_STATE_FILE;
3.56 - ctx->p = ctx->buffer;
3.57 }
3.58 }
3.59
3.60 static void
3.61 -yum_end_element (void *data, const char *name)
3.62 +yum_primary_end_element (void *data, const char *name)
3.63 {
3.64 struct yum_context *ctx = data;
3.65
3.66 switch (ctx->state) {
3.67 case YUM_STATE_PACKAGE_NAME:
3.68 + case YUM_STATE_CHECKSUM:
3.69 case YUM_STATE_FILE:
3.70 ctx->state = YUM_STATE_BEGIN;
3.71 break;
3.72 }
3.73
3.74 - if (strcmp(name, "package") == 0)
3.75 - razor_importer_finish_package(ctx->importer);
3.76 - else if (strcmp(name, "file") == 0)
3.77 - razor_importer_add_file(ctx->importer, ctx->buffer);
3.78 + if (strcmp(name, "package") == 0) {
3.79 + XML_StopParser(ctx->current_parser, XML_TRUE);
3.80 + ctx->current_parser = ctx->filelists_parser;
3.81 + }
3.82 }
3.83
3.84 static void
3.85 @@ -284,6 +292,7 @@
3.86
3.87 switch (ctx->state) {
3.88 case YUM_STATE_PACKAGE_NAME:
3.89 + case YUM_STATE_CHECKSUM:
3.90 case YUM_STATE_FILE:
3.91 memcpy(ctx->p, s, len);
3.92 ctx->p += len;
3.93 @@ -292,41 +301,121 @@
3.94 }
3.95 }
3.96
3.97 +static void
3.98 +yum_filelists_start_element(void *data, const char *name, const char **atts)
3.99 +{
3.100 + struct yum_context *ctx = data;
3.101 + const char *pkg, *pkgid;
3.102 + int i;
3.103 +
3.104 + if (strcmp(name, "package") == 0) {
3.105 + pkg = NULL;
3.106 + pkgid = NULL;
3.107 + for (i = 0; atts[i]; i += 2) {
3.108 + if (strcmp(atts[i], "name") == 0)
3.109 + pkg = atts[i + 1];
3.110 + else if (strcmp(atts[i], "pkgid") == 0)
3.111 + pkgid = atts[i + 1];
3.112 + }
3.113 + if (strcmp(pkgid, ctx->pkgid) != 0)
3.114 + fprintf(stderr, "primary.xml and filelists.xml "
3.115 + "mismatch for %s: %s vs %s",
3.116 + pkg, pkgid, ctx->pkgid);
3.117 + } else if (strcmp(name, "file") == 0) {
3.118 + ctx->state = YUM_STATE_FILE;
3.119 + ctx->p = ctx->buffer;
3.120 + }
3.121 +}
3.122 +
3.123 +
3.124 +static void
3.125 +yum_filelists_end_element (void *data, const char *name)
3.126 +{
3.127 + struct yum_context *ctx = data;
3.128 +
3.129 + ctx->state = YUM_STATE_BEGIN;
3.130 + if (strcmp(name, "package") == 0) {
3.131 + XML_StopParser(ctx->current_parser, XML_TRUE);
3.132 + ctx->current_parser = ctx->primary_parser;
3.133 + razor_importer_finish_package(ctx->importer);
3.134 + } else if (strcmp(name, "file") == 0)
3.135 + razor_importer_add_file(ctx->importer, ctx->buffer);
3.136 +
3.137 +}
3.138 +
3.139 +#define XML_BUFFER_SIZE 4096
3.140 +
3.141 struct razor_set *
3.142 -razor_set_create_from_yum_filelist(int fd)
3.143 +razor_set_create_from_yum(void)
3.144 {
3.145 struct yum_context ctx;
3.146 - XML_Parser parser;
3.147 - char buf[4096];
3.148 - int len;
3.149 + void *buf;
3.150 + int len, ret;
3.151 + gzFile primary, filelists;
3.152 + XML_ParsingStatus status;
3.153
3.154 ctx.importer = razor_importer_new();
3.155 ctx.state = YUM_STATE_BEGIN;
3.156
3.157 - parser = XML_ParserCreate(NULL);
3.158 - XML_SetUserData(parser, &ctx);
3.159 - XML_SetElementHandler(parser, yum_start_element, yum_end_element);
3.160 - XML_SetCharacterDataHandler(parser, yum_character_data);
3.161 + ctx.primary_parser = XML_ParserCreate(NULL);
3.162 + XML_SetUserData(ctx.primary_parser, &ctx);
3.163 + XML_SetElementHandler(ctx.primary_parser,
3.164 + yum_primary_start_element,
3.165 + yum_primary_end_element);
3.166 + XML_SetCharacterDataHandler(ctx.primary_parser,
3.167 + yum_character_data);
3.168
3.169 - while (1) {
3.170 - len = read(fd, buf, sizeof buf);
3.171 - if (len < 0) {
3.172 - fprintf(stderr,
3.173 - "couldn't read input: %s\n", strerror(errno));
3.174 - return NULL;
3.175 - } else if (len == 0)
3.176 + ctx.filelists_parser = XML_ParserCreate(NULL);
3.177 + XML_SetUserData(ctx.filelists_parser, &ctx);
3.178 + XML_SetElementHandler(ctx.filelists_parser,
3.179 + yum_filelists_start_element,
3.180 + yum_filelists_end_element);
3.181 + XML_SetCharacterDataHandler(ctx.filelists_parser,
3.182 + yum_character_data);
3.183 +
3.184 + primary = gzopen("primary.xml.gz", "rb");
3.185 + if (primary == NULL)
3.186 + return NULL;
3.187 + filelists = gzopen("filelists.xml.gz", "rb");
3.188 + if (filelists == NULL)
3.189 + return NULL;
3.190 +
3.191 + ctx.current_parser = ctx.primary_parser;
3.192 +
3.193 + do {
3.194 + XML_GetParsingStatus(ctx.current_parser, &status);
3.195 + switch (status.parsing) {
3.196 + case XML_SUSPENDED:
3.197 + ret = XML_ResumeParser(ctx.current_parser);
3.198 break;
3.199 + case XML_PARSING:
3.200 + case XML_INITIALIZED:
3.201 + buf = XML_GetBuffer(ctx.current_parser,
3.202 + XML_BUFFER_SIZE);
3.203 + if (ctx.current_parser == ctx.primary_parser)
3.204 + len = gzread(primary, buf, XML_BUFFER_SIZE);
3.205 + else
3.206 + len = gzread(filelists, buf, XML_BUFFER_SIZE);
3.207 + if (len < 0) {
3.208 + fprintf(stderr,
3.209 + "couldn't read input: %s\n",
3.210 + strerror(errno));
3.211 + return NULL;
3.212 + }
3.213
3.214 - if (XML_Parse(parser, buf, len, 0) == XML_STATUS_ERROR) {
3.215 - fprintf(stderr,
3.216 - "%s at line %ld\n",
3.217 - XML_ErrorString(XML_GetErrorCode(parser)),
3.218 - XML_GetCurrentLineNumber(parser));
3.219 - return NULL;
3.220 + XML_ParseBuffer(ctx.current_parser, len, len == 0);
3.221 + break;
3.222 + case XML_FINISHED:
3.223 + break;
3.224 }
3.225 - }
3.226 + } while (status.parsing != XML_FINISHED);
3.227
3.228 - XML_ParserFree(parser);
3.229 +
3.230 + XML_ParserFree(ctx.primary_parser);
3.231 + XML_ParserFree(ctx.filelists_parser);
3.232 +
3.233 + gzclose(primary);
3.234 + gzclose(filelists);
3.235
3.236 return razor_importer_finish(ctx.importer);
3.237 }
4.1 --- a/main.c Sun Nov 04 00:58:57 2007 -0400
4.2 +++ b/main.c Sun Nov 04 01:11:53 2007 -0400
4.3 @@ -143,7 +143,7 @@
4.4 {
4.5 struct razor_set *set;
4.6
4.7 - set = razor_set_create_from_yum_filelist(STDIN_FILENO);
4.8 + set = razor_set_create_from_yum();
4.9 if (set == NULL)
4.10 return 1;
4.11 razor_set_write(set, rawhide_repo_filename);
5.1 --- a/razor.h Sun Nov 04 00:58:57 2007 -0400
5.2 +++ b/razor.h Sun Nov 04 01:11:53 2007 -0400
5.3 @@ -58,7 +58,7 @@
5.4 struct razor_set *razor_importer_finish(struct razor_importer *importer);
5.5
5.6 struct razor_set *razor_import_rzr_files(int count, const char **files);
5.7 -struct razor_set *razor_set_create_from_yum_filelist(int fd);
5.8 +struct razor_set *razor_set_create_from_yum(void);
5.9 struct razor_set *razor_set_create_from_rpmdb(void);
5.10
5.11 #endif /* _RAZOR_H_ */