1.1 --- a/import.c Tue Sep 18 15:02:04 2007 -0400
1.2 +++ b/import.c Wed Sep 19 14:09:03 2007 -0400
1.3 @@ -9,6 +9,8 @@
1.4 #include <errno.h>
1.5
1.6 #include <expat.h>
1.7 +#include <rpm/rpmlib.h>
1.8 +#include <rpm/rpmdb.h>
1.9 #include "sha1.h"
1.10 #include "razor.h"
1.11
1.12 @@ -257,3 +259,62 @@
1.13
1.14 return razor_finish_import(&ctx.ctx);
1.15 }
1.16 +
1.17 +struct razor_set *
1.18 +razor_set_create_from_rpmdb(void)
1.19 +{
1.20 + struct import_context ctx;
1.21 + rpmdbMatchIterator iter;
1.22 + Header h;
1.23 + int_32 type, count, i;
1.24 + char *name, *version, *release;
1.25 + char **properties, **property_versions;
1.26 + rpmdb db;
1.27 +
1.28 + rpmReadConfigFiles(NULL, NULL);
1.29 +
1.30 + if (rpmdbOpen("", &db, O_RDONLY, 0644) != 0) {
1.31 + fprintf(stderr, "cannot open rpm database\n");
1.32 + exit(1);
1.33 + }
1.34 +
1.35 + razor_prepare_import(&ctx);
1.36 +
1.37 + iter = rpmdbInitIterator(db, 0, NULL, 0);
1.38 + while (h = rpmdbNextIterator(iter), h != NULL) {
1.39 + headerGetEntry(h, RPMTAG_NAME, &type,
1.40 + (void **) &name, &count);
1.41 + headerGetEntry(h, RPMTAG_VERSION, &type,
1.42 + (void **) &version, &count);
1.43 + headerGetEntry(h, RPMTAG_RELEASE, &type,
1.44 + (void **) &release, &count);
1.45 + import_context_add_package(&ctx, name, version);
1.46 +
1.47 +
1.48 + headerGetEntry(h, RPMTAG_REQUIRES, &type,
1.49 + (void **) &properties, &count);
1.50 + headerGetEntry(h, RPMTAG_REQUIREVERSION, &type,
1.51 + (void **) &property_versions, &count);
1.52 + for (i = 0; i < count; i++)
1.53 + import_context_add_property(&ctx,
1.54 + &ctx.requires,
1.55 + properties[i],
1.56 + property_versions[i]);
1.57 +
1.58 + headerGetEntry(h, RPMTAG_PROVIDES, &type,
1.59 + (void **) &properties, &count);
1.60 + headerGetEntry(h, RPMTAG_PROVIDEVERSION, &type,
1.61 + (void **) &property_versions, &count);
1.62 + for (i = 0; i < count; i++)
1.63 + import_context_add_property(&ctx,
1.64 + &ctx.provides,
1.65 + properties[i],
1.66 + property_versions[i]);
1.67 +
1.68 + import_context_finish_package(&ctx);
1.69 + }
1.70 +
1.71 + rpmdbClose(db);
1.72 +
1.73 + return razor_finish_import(&ctx);
1.74 +}