Use strings to identify section types in the on-disk repo format.
Previously, a given razor file type had a fixed number of sections in a
fixed order, identified by an integer type. Now, sections are identified
by a named string (stored in a string pool after the section lists).
This will allow for razor files to contain arbitrary sections.
For bonus points, also drop the 4k section alignment and change the
magic byte string to "RZDB".
committer: Kristian H?gsberg <krh@redhat.com>
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];
93 int imported_count = 0;
95 rpmReadConfigFiles(NULL, NULL);
97 if (rpmdbOpen("", &db, O_RDONLY, 0644) != 0) {
98 fprintf(stderr, "cannot open rpm database\n");
102 importer = razor_importer_create();
104 iter = rpmdbInitIterator(db, 0, NULL, 0);
105 while (h = rpmdbNextIterator(iter), h != NULL) {
106 headerGetEntry(h, RPMTAG_NAME, &type, &name.p, &count);
107 headerGetEntry(h, RPMTAG_EPOCH, &type, &epoch.p, &count);
108 headerGetEntry(h, RPMTAG_VERSION, &type, &version.p, &count);
109 headerGetEntry(h, RPMTAG_RELEASE, &type, &release.p, &count);
110 headerGetEntry(h, RPMTAG_ARCH, &type, &arch.p, &count);
111 headerGetEntry(h, RPMTAG_SUMMARY, &type, &summary.p, &count);
112 headerGetEntry(h, RPMTAG_DESCRIPTION, &type, &description.p,
114 headerGetEntry(h, RPMTAG_URL, &type, &url.p, &count);
115 headerGetEntry(h, RPMTAG_LICENSE, &type, &license.p, &count);
117 if (epoch.flags != NULL) {
118 snprintf(buf, sizeof buf, "%u", *epoch.flags);
119 razor_build_evr(evr, sizeof evr,
120 buf, version.string, release.string);
122 razor_build_evr(evr, sizeof evr,
123 NULL, version.string, release.string);
126 razor_importer_begin_package(importer,
127 name.string, evr, arch.string);
128 razor_importer_add_details(importer, summary.string,
129 description.string, url.string,
132 add_properties(importer, RAZOR_PROPERTY_REQUIRES, h,
134 RPMTAG_REQUIREVERSION,
135 RPMTAG_REQUIREFLAGS);
137 add_properties(importer, RAZOR_PROPERTY_PROVIDES, h,
139 RPMTAG_PROVIDEVERSION,
140 RPMTAG_PROVIDEFLAGS);
142 add_properties(importer, RAZOR_PROPERTY_OBSOLETES, h,
144 RPMTAG_OBSOLETEVERSION,
145 RPMTAG_OBSOLETEFLAGS);
147 add_properties(importer, RAZOR_PROPERTY_CONFLICTS, h,
149 RPMTAG_CONFLICTVERSION,
150 RPMTAG_CONFLICTFLAGS);
152 headerGetEntry(h, RPMTAG_BASENAMES, &type,
153 &basenames.p, &count);
154 headerGetEntry(h, RPMTAG_DIRNAMES, &type,
155 &dirnames.p, &count);
156 headerGetEntry(h, RPMTAG_DIRINDEXES, &type,
157 &dirindexes.p, &count);
158 for (i = 0; i < count; i++) {
159 snprintf(filename, sizeof filename, "%s%s",
160 dirnames.list[dirindexes.flags[i]],
162 razor_importer_add_file(importer, filename);
165 razor_importer_finish_package(importer);
167 printf("\rimporting %d", ++imported_count);
173 printf("\nsaving\n");
174 return razor_importer_finish(importer);