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.
25 #include <rpm/rpmlib.h>
26 #include <rpm/rpmdb.h>
39 rpm_to_razor_flags(uint32_t flags)
44 if (flags & RPMSENSE_LESS)
45 razor_flags |= RAZOR_PROPERTY_LESS;
46 if (flags & RPMSENSE_EQUAL)
47 razor_flags |= RAZOR_PROPERTY_EQUAL;
48 if (flags & RPMSENSE_GREATER)
49 razor_flags |= RAZOR_PROPERTY_GREATER;
51 if (flags & RPMSENSE_SCRIPT_PRE)
52 razor_flags |= RAZOR_PROPERTY_PRE;
53 if (flags & RPMSENSE_SCRIPT_POST)
54 razor_flags |= RAZOR_PROPERTY_POST;
55 if (flags & RPMSENSE_SCRIPT_PREUN)
56 razor_flags |= RAZOR_PROPERTY_PREUN;
57 if (flags & RPMSENSE_SCRIPT_POSTUN)
58 razor_flags |= RAZOR_PROPERTY_POSTUN;
64 add_properties(struct razor_importer *importer,
65 uint32_t type_flags, Header h,
66 int32_t name_tag, int32_t version_tag, int32_t flags_tag)
68 union rpm_entry names, versions, flags;
69 int32_t i, type, count;
71 headerGetEntry(h, name_tag, &type, &names.p, &count);
72 headerGetEntry(h, version_tag, &type, &versions.p, &count);
73 headerGetEntry(h, flags_tag, &type, &flags.p, &count);
75 for (i = 0; i < count; i++)
76 razor_importer_add_property(importer,
78 rpm_to_razor_flags (flags.flags[i]) | type_flags,
83 razor_set_create_from_rpmdb(void)
85 struct razor_importer *importer;
86 rpmdbMatchIterator iter;
88 int32_t type, count, i;
89 union rpm_entry name, epoch, version, release, arch;
90 union rpm_entry summary, description, url, license;
91 union rpm_entry basenames, dirnames, dirindexes;
92 char filename[PATH_MAX], evr[128], buf[16];
94 int imported_count = 0;
96 rpmReadConfigFiles(NULL, NULL);
98 if (rpmdbOpen("", &db, O_RDONLY, 0644) != 0) {
99 fprintf(stderr, "cannot open rpm database\n");
103 importer = razor_importer_create();
105 iter = rpmdbInitIterator(db, 0, NULL, 0);
106 while (h = rpmdbNextIterator(iter), h != NULL) {
107 headerGetEntry(h, RPMTAG_NAME, &type, &name.p, &count);
108 headerGetEntry(h, RPMTAG_EPOCH, &type, &epoch.p, &count);
109 headerGetEntry(h, RPMTAG_VERSION, &type, &version.p, &count);
110 headerGetEntry(h, RPMTAG_RELEASE, &type, &release.p, &count);
111 headerGetEntry(h, RPMTAG_ARCH, &type, &arch.p, &count);
112 headerGetEntry(h, RPMTAG_SUMMARY, &type, &summary.p, &count);
113 headerGetEntry(h, RPMTAG_DESCRIPTION, &type, &description.p,
115 headerGetEntry(h, RPMTAG_URL, &type, &url.p, &count);
116 headerGetEntry(h, RPMTAG_LICENSE, &type, &license.p, &count);
118 if (epoch.flags != NULL) {
119 snprintf(buf, sizeof buf, "%u", *epoch.flags);
120 razor_build_evr(evr, sizeof evr,
121 buf, version.string, release.string);
123 razor_build_evr(evr, sizeof evr,
124 NULL, version.string, release.string);
127 razor_importer_begin_package(importer,
128 name.string, evr, arch.string);
129 razor_importer_add_details(importer, summary.string,
130 description.string, url.string,
133 add_properties(importer, RAZOR_PROPERTY_REQUIRES, h,
135 RPMTAG_REQUIREVERSION,
136 RPMTAG_REQUIREFLAGS);
138 add_properties(importer, RAZOR_PROPERTY_PROVIDES, h,
140 RPMTAG_PROVIDEVERSION,
141 RPMTAG_PROVIDEFLAGS);
143 add_properties(importer, RAZOR_PROPERTY_OBSOLETES, h,
145 RPMTAG_OBSOLETEVERSION,
146 RPMTAG_OBSOLETEFLAGS);
148 add_properties(importer, RAZOR_PROPERTY_CONFLICTS, h,
150 RPMTAG_CONFLICTVERSION,
151 RPMTAG_CONFLICTFLAGS);
153 headerGetEntry(h, RPMTAG_BASENAMES, &type,
154 &basenames.p, &count);
155 headerGetEntry(h, RPMTAG_DIRNAMES, &type,
156 &dirnames.p, &count);
157 headerGetEntry(h, RPMTAG_DIRINDEXES, &type,
158 &dirindexes.p, &count);
159 for (i = 0; i < count; i++) {
160 snprintf(filename, sizeof filename, "%s%s",
161 dirnames.list[dirindexes.flags[i]],
163 razor_importer_add_file(importer, filename);
166 razor_importer_finish_package(importer);
168 printf("\rimporting %d", ++imported_count);
174 printf("\nsaving\n");
175 return razor_importer_finish(importer);