2 * Copyright (C) 2008 Kristian Høgsberg <krh@redhat.com>
3 * Copyright (C) 2008 Red Hat, Inc
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 #include <rpm/rpmlib.h>
25 #include <rpm/rpmdb.h>
38 rpm_to_razor_flags(uint32_t flags)
43 if (flags & RPMSENSE_LESS)
44 razor_flags |= RAZOR_PROPERTY_LESS;
45 if (flags & RPMSENSE_EQUAL)
46 razor_flags |= RAZOR_PROPERTY_EQUAL;
47 if (flags & RPMSENSE_GREATER)
48 razor_flags |= RAZOR_PROPERTY_GREATER;
50 if (flags & RPMSENSE_SCRIPT_PRE)
51 razor_flags |= RAZOR_PROPERTY_PRE;
52 if (flags & RPMSENSE_SCRIPT_POST)
53 razor_flags |= RAZOR_PROPERTY_POST;
54 if (flags & RPMSENSE_SCRIPT_PREUN)
55 razor_flags |= RAZOR_PROPERTY_PREUN;
56 if (flags & RPMSENSE_SCRIPT_POSTUN)
57 razor_flags |= RAZOR_PROPERTY_POSTUN;
63 add_properties(struct razor_importer *importer,
65 Header h, int_32 name_tag, int_32 version_tag, int_32 flags_tag)
67 union rpm_entry names, versions, flags;
68 int_32 i, type, count;
70 headerGetEntry(h, name_tag, &type, &names.p, &count);
71 headerGetEntry(h, version_tag, &type, &versions.p, &count);
72 headerGetEntry(h, flags_tag, &type, &flags.p, &count);
74 for (i = 0; i < count; i++)
75 razor_importer_add_property(importer,
77 rpm_to_razor_flags (flags.flags[i]) | type_flags,
82 razor_set_create_from_rpmdb(void)
84 struct razor_importer *importer;
85 rpmdbMatchIterator iter;
87 int_32 type, count, i;
88 union rpm_entry name, epoch, version, release, arch;
89 union rpm_entry summary, description, url, license;
90 union rpm_entry basenames, dirnames, dirindexes;
91 char filename[PATH_MAX], evr[128], buf[16];
94 rpmReadConfigFiles(NULL, NULL);
96 if (rpmdbOpen("", &db, O_RDONLY, 0644) != 0) {
97 fprintf(stderr, "cannot open rpm database\n");
101 importer = razor_importer_new();
103 iter = rpmdbInitIterator(db, 0, NULL, 0);
104 while (h = rpmdbNextIterator(iter), h != NULL) {
105 headerGetEntry(h, RPMTAG_NAME, &type, &name.p, &count);
106 headerGetEntry(h, RPMTAG_EPOCH, &type, &epoch.p, &count);
107 headerGetEntry(h, RPMTAG_VERSION, &type, &version.p, &count);
108 headerGetEntry(h, RPMTAG_RELEASE, &type, &release.p, &count);
109 headerGetEntry(h, RPMTAG_ARCH, &type, &arch.p, &count);
110 headerGetEntry(h, RPMTAG_SUMMARY, &type, &summary.p, &count);
111 headerGetEntry(h, RPMTAG_DESCRIPTION, &type, &description.p,
113 headerGetEntry(h, RPMTAG_URL, &type, &url.p, &count);
114 headerGetEntry(h, RPMTAG_LICENSE, &type, &license.p, &count);
116 if (epoch.flags != NULL) {
117 snprintf(buf, sizeof buf, "%u", *epoch.flags);
118 razor_build_evr(evr, sizeof evr,
119 buf, version.string, release.string);
121 razor_build_evr(evr, sizeof evr,
122 NULL, version.string, release.string);
125 razor_importer_begin_package(importer,
126 name.string, evr, arch.string);
127 razor_importer_add_details(importer, summary.string,
128 description.string, url.string,
131 add_properties(importer, RAZOR_PROPERTY_REQUIRES, h,
133 RPMTAG_REQUIREVERSION,
134 RPMTAG_REQUIREFLAGS);
136 add_properties(importer, RAZOR_PROPERTY_PROVIDES, h,
138 RPMTAG_PROVIDEVERSION,
139 RPMTAG_PROVIDEFLAGS);
141 add_properties(importer, RAZOR_PROPERTY_OBSOLETES, h,
143 RPMTAG_OBSOLETEVERSION,
144 RPMTAG_OBSOLETEFLAGS);
146 add_properties(importer, RAZOR_PROPERTY_CONFLICTS, h,
148 RPMTAG_CONFLICTVERSION,
149 RPMTAG_CONFLICTFLAGS);
151 headerGetEntry(h, RPMTAG_BASENAMES, &type,
152 &basenames.p, &count);
153 headerGetEntry(h, RPMTAG_DIRNAMES, &type,
154 &dirnames.p, &count);
155 headerGetEntry(h, RPMTAG_DIRINDEXES, &type,
156 &dirindexes.p, &count);
157 for (i = 0; i < count; i++) {
158 snprintf(filename, sizeof filename, "%s%s",
159 dirnames.list[dirindexes.flags[i]],
161 razor_importer_add_file(importer, filename);
164 razor_importer_finish_package(importer);
169 return razor_importer_finish(importer);