1 /* This converts an old style (rpm 1.x) database to the new style */
12 #include "oldheader.h"
19 struct oldrpmdb olddb;
21 struct oldrpmdbLabel * packageLabels, * label;
22 struct oldrpmdbPackageInfo package;
29 char ** fileLinktoList;
30 int_32 * fileSizeList;
33 int_32 * fileMtimesList;
34 int_32 * fileFlagsList;
35 int_16 * fileModesList;
36 int_16 * fileRDevsList;
37 char * fileStatesList;
38 char * preun, * postun;
41 if (oldrpmdbOpen(&olddb)) {
42 error(RPMERR_OLDDBMISSING, "");
46 if (exists("/var/lib/rpm/packages.rpm")) {
48 error(RPMERR_NOCREATEDB, "RPM database already exists");
51 unlink("/var/lib/rpm/packages.rpm");
54 /* if any of the indexes exist, get rid of them */
55 unlink("/var/lib/rpm/nameindex.rpm");
56 unlink("/var/lib/rpm/groupindex.rpm");
57 unlink("/var/lib/rpm/packageindex.rpm");
58 unlink("/var/lib/rpm/fileindex.rpm");
60 if (!rpmdbOpen("", &db, O_RDWR | O_EXCL | O_CREAT, 0644)) {
61 error(RPMERR_DBOPEN, "failed to create RPM database /var/lib/rpm");
65 packageLabels = oldrpmdbGetAllLabels(&olddb);
67 error(RPMERR_OLDDBCORRUPT, "");
69 unlink("/var/lib/rpm/packages.rpm");
70 oldrpmdbClose(&olddb);
74 for (label = packageLabels; label; label = label->next) {
75 if (oldrpmdbGetPackageInfo(&olddb, *label, &package)) {
76 fprintf(stderr, "oldrpmdbGetPackageInfo failed &olddb = %p olddb.packages = %p\n", &olddb, olddb.packages);
80 group = oldrpmdbGetPackageGroup(&olddb, *label);
81 preun = oldrpmdbGetPackagePreun(&olddb, *label);
82 postun = oldrpmdbGetPackagePostun(&olddb, *label);
84 dbentry = newHeader();
85 addEntry(dbentry, RPMTAG_NAME, STRING_TYPE, package.name, 1);
86 addEntry(dbentry, RPMTAG_VERSION, STRING_TYPE, package.version, 1);
87 addEntry(dbentry, RPMTAG_RELEASE, STRING_TYPE, package.release, 1);
88 addEntry(dbentry, RPMTAG_DESCRIPTION, STRING_TYPE,
89 package.description, 1);
90 addEntry(dbentry, RPMTAG_BUILDTIME, INT32_TYPE, &package.buildTime, 1);
91 addEntry(dbentry, RPMTAG_BUILDHOST, STRING_TYPE, package.buildHost, 1);
92 addEntry(dbentry, RPMTAG_INSTALLTIME, INT32_TYPE,
93 &package.installTime, 1);
94 addEntry(dbentry, RPMTAG_DISTRIBUTION, STRING_TYPE,
95 package.distribution, 1);
96 addEntry(dbentry, RPMTAG_VENDOR, STRING_TYPE, package.vendor, 1);
97 addEntry(dbentry, RPMTAG_SIZE, INT32_TYPE, &package.size, 1);
98 addEntry(dbentry, RPMTAG_COPYRIGHT, STRING_TYPE, package.copyright, 1);
99 addEntry(dbentry, RPMTAG_GROUP, STRING_TYPE, group, 1);
102 addEntry(dbentry, RPMTAG_PREUN, STRING_TYPE, preun, 1);
106 addEntry(dbentry, RPMTAG_POSTUN, STRING_TYPE, postun, 1);
110 gif = oldrpmdbGetPackageGif(&olddb, *label, &gifSize);
112 addEntry(dbentry, RPMTAG_GIF, BIN_TYPE, gif, gifSize);
116 if (package.fileCount) {
117 /* some packages have no file lists */
119 fileList = malloc(sizeof(char *) * package.fileCount);
120 fileLinktoList = malloc(sizeof(char *) * package.fileCount);
121 fileMD5List = malloc(sizeof(char *) * package.fileCount);
122 fileSizeList = malloc(sizeof(int_32) * package.fileCount);
123 fileUIDList = malloc(sizeof(int_32) * package.fileCount);
124 fileGIDList = malloc(sizeof(int_32) * package.fileCount);
125 fileMtimesList = malloc(sizeof(int_32) * package.fileCount);
126 fileFlagsList = malloc(sizeof(int_32) * package.fileCount);
127 fileModesList = malloc(sizeof(int_16) * package.fileCount);
128 fileRDevsList = malloc(sizeof(int_16) * package.fileCount);
129 fileStatesList = malloc(sizeof(char) * package.fileCount);
131 /* reverse the file list while we're at it */
132 j = package.fileCount - 1;
133 for (i = 0; i < package.fileCount; i++, j--) {
134 fileList[j] = package.files[i].path;
135 fileMD5List[j] = package.files[i].md5;
136 fileSizeList[j] = package.files[i].size;
137 fileUIDList[j] = package.files[i].uid;
138 fileGIDList[j] = package.files[i].gid;
139 fileMtimesList[j] = package.files[i].mtime;
140 fileModesList[j] = package.files[i].mode;
141 fileRDevsList[j] = package.files[i].rdev;
142 fileStatesList[j] = package.files[i].state;
144 if (package.files[i].linkto)
145 fileLinktoList[j] = package.files[i].linkto;
147 fileLinktoList[j] = "";
149 fileFlagsList[j] = 0;
150 if (package.files[i].isdoc)
151 fileFlagsList[j] |= RPMFILE_DOC;
152 if (package.files[i].isconf)
153 fileFlagsList[j] |= RPMFILE_CONFIG;
156 addEntry(dbentry, RPMTAG_FILENAMES, STRING_ARRAY_TYPE, fileList,
158 addEntry(dbentry, RPMTAG_FILELINKTOS, STRING_ARRAY_TYPE,
159 fileLinktoList, package.fileCount);
160 addEntry(dbentry, RPMTAG_FILEMD5S, STRING_ARRAY_TYPE, fileMD5List,
162 addEntry(dbentry, RPMTAG_FILESIZES, INT32_TYPE, fileSizeList,
164 addEntry(dbentry, RPMTAG_FILEUIDS, INT32_TYPE, fileUIDList,
166 addEntry(dbentry, RPMTAG_FILEGIDS, INT32_TYPE, fileGIDList,
168 addEntry(dbentry, RPMTAG_FILEMTIMES, INT32_TYPE, fileMtimesList,
170 addEntry(dbentry, RPMTAG_FILEFLAGS, INT32_TYPE, fileFlagsList,
172 addEntry(dbentry, RPMTAG_FILEMODES, INT16_TYPE, fileModesList,
174 addEntry(dbentry, RPMTAG_FILERDEVS, INT16_TYPE, fileRDevsList,
176 addEntry(dbentry, RPMTAG_FILESTATES, INT8_TYPE, fileStatesList,
180 free(fileLinktoList);
185 free(fileMtimesList);
189 free(fileStatesList);
192 rpmdbAdd(db, dbentry);
197 oldrpmdbFreePackageInfo(package);
200 oldrpmdbClose(&olddb);
206 int main(int argc, char ** argv) {
208 fprintf(stderr, "rpmconvert: no arguments expected");
212 printf("rpmconvert 1.0 - converting database in /var/lib/rpm\n");