Introduce install/remove iterators.
These iterator constructors lets you pass in two sets and creates
an iterator for the packages to remove or the packages to install.
The iterators will step through the packages in a sequence that respects
the pre, post, preun and postun modifiers.
Right now, the install order isn't actually implemented, this patch just
implements the API changes and updates the applications.
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 basenames, dirnames, dirindexes;
90 char filename[PATH_MAX], evr[128], buf[16];
93 rpmReadConfigFiles(NULL, NULL);
95 if (rpmdbOpen("", &db, O_RDONLY, 0644) != 0) {
96 fprintf(stderr, "cannot open rpm database\n");
100 importer = razor_importer_create();
102 iter = rpmdbInitIterator(db, 0, NULL, 0);
103 while (h = rpmdbNextIterator(iter), h != NULL) {
104 headerGetEntry(h, RPMTAG_NAME, &type, &name.p, &count);
105 headerGetEntry(h, RPMTAG_EPOCH, &type, &epoch.p, &count);
106 headerGetEntry(h, RPMTAG_VERSION, &type, &version.p, &count);
107 headerGetEntry(h, RPMTAG_RELEASE, &type, &release.p, &count);
108 headerGetEntry(h, RPMTAG_ARCH, &type, &arch.p, &count);
110 if (epoch.flags != NULL) {
111 snprintf(buf, sizeof buf, "%u", *epoch.flags);
112 razor_build_evr(evr, sizeof evr,
113 buf, version.string, release.string);
115 razor_build_evr(evr, sizeof evr,
116 NULL, version.string, release.string);
119 razor_importer_begin_package(importer,
120 name.string, evr, arch.string);
122 add_properties(importer, RAZOR_PROPERTY_REQUIRES, h,
124 RPMTAG_REQUIREVERSION,
125 RPMTAG_REQUIREFLAGS);
127 add_properties(importer, RAZOR_PROPERTY_PROVIDES, h,
129 RPMTAG_PROVIDEVERSION,
130 RPMTAG_PROVIDEFLAGS);
132 add_properties(importer, RAZOR_PROPERTY_OBSOLETES, h,
134 RPMTAG_OBSOLETEVERSION,
135 RPMTAG_OBSOLETEFLAGS);
137 add_properties(importer, RAZOR_PROPERTY_CONFLICTS, h,
139 RPMTAG_CONFLICTVERSION,
140 RPMTAG_CONFLICTFLAGS);
142 headerGetEntry(h, RPMTAG_BASENAMES, &type,
143 &basenames.p, &count);
144 headerGetEntry(h, RPMTAG_DIRNAMES, &type,
145 &dirnames.p, &count);
146 headerGetEntry(h, RPMTAG_DIRINDEXES, &type,
147 &dirindexes.p, &count);
148 for (i = 0; i < count; i++) {
149 snprintf(filename, sizeof filename, "%s%s",
150 dirnames.list[dirindexes.flags[i]],
152 razor_importer_add_file(importer, filename);
155 razor_importer_finish_package(importer);
160 return razor_importer_finish(importer);