Handle NULL dirnames when importing rpms into a set.
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>
37 static enum razor_version_relation
38 rpm_to_razor_flags (uint_32 flags)
40 switch (flags & (RPMSENSE_LESS | RPMSENSE_EQUAL | RPMSENSE_GREATER)) {
42 return RAZOR_VERSION_LESS;
43 case RPMSENSE_LESS|RPMSENSE_EQUAL:
44 return RAZOR_VERSION_LESS_OR_EQUAL;
46 return RAZOR_VERSION_EQUAL;
47 case RPMSENSE_GREATER|RPMSENSE_EQUAL:
48 return RAZOR_VERSION_GREATER_OR_EQUAL;
49 case RPMSENSE_GREATER:
50 return RAZOR_VERSION_GREATER;
54 return RAZOR_VERSION_EQUAL;
58 add_properties(struct razor_importer *importer,
59 enum razor_property_type property_type,
60 Header h, int_32 name_tag, int_32 version_tag, int_32 flags_tag)
62 union rpm_entry names, versions, flags;
63 int_32 i, type, count;
65 headerGetEntry(h, name_tag, &type, &names.p, &count);
66 headerGetEntry(h, version_tag, &type, &versions.p, &count);
67 headerGetEntry(h, flags_tag, &type, &flags.p, &count);
69 for (i = 0; i < count; i++)
70 razor_importer_add_property(importer,
72 rpm_to_razor_flags (flags.flags[i]),
78 razor_set_create_from_rpmdb(void)
80 struct razor_importer *importer;
81 rpmdbMatchIterator iter;
83 int_32 type, count, i;
84 union rpm_entry name, epoch, version, release, arch;
85 union rpm_entry basenames, dirnames, dirindexes;
86 char filename[PATH_MAX], evr[128], buf[16];
89 rpmReadConfigFiles(NULL, NULL);
91 if (rpmdbOpen("", &db, O_RDONLY, 0644) != 0) {
92 fprintf(stderr, "cannot open rpm database\n");
96 importer = razor_importer_new();
98 iter = rpmdbInitIterator(db, 0, NULL, 0);
99 while (h = rpmdbNextIterator(iter), h != NULL) {
100 headerGetEntry(h, RPMTAG_NAME, &type, &name.p, &count);
101 headerGetEntry(h, RPMTAG_EPOCH, &type, &epoch.p, &count);
102 headerGetEntry(h, RPMTAG_VERSION, &type, &version.p, &count);
103 headerGetEntry(h, RPMTAG_RELEASE, &type, &release.p, &count);
104 headerGetEntry(h, RPMTAG_ARCH, &type, &arch.p, &count);
106 if (epoch.flags != NULL) {
107 snprintf(buf, sizeof buf, "%u", *epoch.flags);
108 razor_build_evr(evr, sizeof evr,
109 buf, version.string, release.string);
111 razor_build_evr(evr, sizeof evr,
112 NULL, version.string, release.string);
115 razor_importer_begin_package(importer,
116 name.string, evr, arch.string);
118 add_properties(importer, RAZOR_PROPERTY_REQUIRES, h,
120 RPMTAG_REQUIREVERSION,
121 RPMTAG_REQUIREFLAGS);
123 add_properties(importer, RAZOR_PROPERTY_PROVIDES, h,
125 RPMTAG_PROVIDEVERSION,
126 RPMTAG_PROVIDEFLAGS);
128 add_properties(importer, RAZOR_PROPERTY_OBSOLETES, h,
130 RPMTAG_OBSOLETEVERSION,
131 RPMTAG_OBSOLETEFLAGS);
133 add_properties(importer, RAZOR_PROPERTY_CONFLICTS, h,
135 RPMTAG_CONFLICTVERSION,
136 RPMTAG_CONFLICTFLAGS);
138 headerGetEntry(h, RPMTAG_BASENAMES, &type,
139 &basenames.p, &count);
140 headerGetEntry(h, RPMTAG_DIRNAMES, &type,
141 &dirnames.p, &count);
142 headerGetEntry(h, RPMTAG_DIRINDEXES, &type,
143 &dirindexes.p, &count);
144 for (i = 0; i < count; i++) {
145 snprintf(filename, sizeof filename, "%s%s",
146 dirnames.list[dirindexes.flags[i]],
148 razor_importer_add_file(importer, filename);
151 razor_importer_finish_package(importer);
156 return razor_importer_finish(importer);