1 /* This converts an old style (rpm 1.x) database to the new style */
12 #include "oldheader.h"
18 struct oldrpmdb olddb;
20 struct oldrpmdbLabel * packageLabels, * label;
21 struct oldrpmdbPackageInfo package;
28 char ** fileLinktoList;
29 int_32 * fileSizeList;
32 int_32 * fileMtimesList;
33 int_32 * fileFlagsList;
34 int_16 * fileModesList;
35 int_16 * fileRDevsList;
36 char * fileStatesList;
37 char * preun, * postun;
40 if (exists("/var/lib/rpm/packages.rpm")) {
41 rpmError(RPMERR_NOCREATEDB, "RPM database already exists");
45 if (oldrpmdbOpen(&olddb)) {
46 rpmError(RPMERR_OLDDBMISSING, "");
50 /* if any of the indexes exist, get rid of them */
51 unlink("/var/lib/rpm/nameindex.rpm");
52 unlink("/var/lib/rpm/groupindex.rpm");
53 unlink("/var/lib/rpm/packageindex.rpm");
54 unlink("/var/lib/rpm/fileindex.rpm");
56 if (rpmdbOpen("", &db, O_RDWR | O_CREAT, 0644)) {
57 rpmError(RPMERR_DBOPEN, "failed to create RPM database /var/lib/rpm");
61 packageLabels = oldrpmdbGetAllLabels(&olddb);
63 rpmError(RPMERR_OLDDBCORRUPT, "");
65 unlink("/var/lib/rpm/packages.rpm");
66 oldrpmdbClose(&olddb);
70 for (label = packageLabels; label; label = label->next) {
71 if (oldrpmdbGetPackageInfo(&olddb, *label, &package)) {
72 fprintf(stderr, "oldrpmdbGetPackageInfo failed &olddb = %p olddb.packages = %p\n", &olddb, olddb.packages);
76 group = oldrpmdbGetPackageGroup(&olddb, *label);
77 preun = oldrpmdbGetPackagePreun(&olddb, *label);
78 postun = oldrpmdbGetPackagePostun(&olddb, *label);
80 dbentry = headerNew();
81 headerAddEntry(dbentry, RPMTAG_NAME, RPM_STRING_TYPE, package.name, 1);
82 headerAddEntry(dbentry, RPMTAG_VERSION, RPM_STRING_TYPE, package.version, 1);
83 headerAddEntry(dbentry, RPMTAG_RELEASE, RPM_STRING_TYPE, package.release, 1);
84 headerAddEntry(dbentry, RPMTAG_DESCRIPTION, RPM_STRING_TYPE,
85 package.description, 1);
86 headerAddEntry(dbentry, RPMTAG_BUILDTIME, RPM_INT32_TYPE, &package.buildTime, 1);
87 headerAddEntry(dbentry, RPMTAG_BUILDHOST, RPM_STRING_TYPE, package.buildHost, 1);
88 headerAddEntry(dbentry, RPMTAG_INSTALLTIME, RPM_INT32_TYPE,
89 &package.installTime, 1);
90 headerAddEntry(dbentry, RPMTAG_DISTRIBUTION, RPM_STRING_TYPE,
91 package.distribution, 1);
92 headerAddEntry(dbentry, RPMTAG_VENDOR, RPM_STRING_TYPE, package.vendor, 1);
93 headerAddEntry(dbentry, RPMTAG_SIZE, RPM_INT32_TYPE, &package.size, 1);
94 headerAddEntry(dbentry, RPMTAG_COPYRIGHT, RPM_STRING_TYPE, package.copyright, 1);
95 headerAddEntry(dbentry, RPMTAG_GROUP, RPM_STRING_TYPE, group, 1);
98 headerAddEntry(dbentry, RPMTAG_PREUN, RPM_STRING_TYPE, preun, 1);
102 headerAddEntry(dbentry, RPMTAG_POSTUN, RPM_STRING_TYPE, postun, 1);
106 gif = oldrpmdbGetPackageGif(&olddb, *label, &gifSize);
108 headerAddEntry(dbentry, RPMTAG_GIF, RPM_BIN_TYPE, gif, gifSize);
112 if (package.fileCount) {
113 /* some packages have no file lists */
115 fileList = malloc(sizeof(char *) * package.fileCount);
116 fileLinktoList = malloc(sizeof(char *) * package.fileCount);
117 fileMD5List = malloc(sizeof(char *) * package.fileCount);
118 fileSizeList = malloc(sizeof(int_32) * package.fileCount);
119 fileUIDList = malloc(sizeof(int_32) * package.fileCount);
120 fileGIDList = malloc(sizeof(int_32) * package.fileCount);
121 fileMtimesList = malloc(sizeof(int_32) * package.fileCount);
122 fileFlagsList = malloc(sizeof(int_32) * package.fileCount);
123 fileModesList = malloc(sizeof(int_16) * package.fileCount);
124 fileRDevsList = malloc(sizeof(int_16) * package.fileCount);
125 fileStatesList = malloc(sizeof(char) * package.fileCount);
127 /* reverse the file list while we're at it */
128 j = package.fileCount - 1;
129 for (i = 0; i < package.fileCount; i++, j--) {
130 fileList[j] = package.files[i].path;
131 fileMD5List[j] = package.files[i].md5;
132 fileSizeList[j] = package.files[i].size;
133 fileUIDList[j] = package.files[i].uid;
134 fileGIDList[j] = package.files[i].gid;
135 fileMtimesList[j] = package.files[i].mtime;
136 fileModesList[j] = package.files[i].mode;
137 fileRDevsList[j] = package.files[i].rdev;
138 fileStatesList[j] = package.files[i].state;
140 if (package.files[i].linkto)
141 fileLinktoList[j] = package.files[i].linkto;
143 fileLinktoList[j] = "";
145 fileFlagsList[j] = 0;
146 if (package.files[i].isdoc)
147 fileFlagsList[j] |= RPMFILE_DOC;
148 if (package.files[i].isconf)
149 fileFlagsList[j] |= RPMFILE_CONFIG;
152 headerAddEntry(dbentry, RPMTAG_FILENAMES, RPM_STRING_ARRAY_TYPE, fileList,
154 headerAddEntry(dbentry, RPMTAG_FILELINKTOS, RPM_STRING_ARRAY_TYPE,
155 fileLinktoList, package.fileCount);
156 headerAddEntry(dbentry, RPMTAG_FILEMD5S, RPM_STRING_ARRAY_TYPE, fileMD5List,
158 headerAddEntry(dbentry, RPMTAG_FILESIZES, RPM_INT32_TYPE, fileSizeList,
160 headerAddEntry(dbentry, RPMTAG_FILEUIDS, RPM_INT32_TYPE, fileUIDList,
162 headerAddEntry(dbentry, RPMTAG_FILEGIDS, RPM_INT32_TYPE, fileGIDList,
164 headerAddEntry(dbentry, RPMTAG_FILEMTIMES, RPM_INT32_TYPE, fileMtimesList,
166 headerAddEntry(dbentry, RPMTAG_FILEFLAGS, RPM_INT32_TYPE, fileFlagsList,
168 headerAddEntry(dbentry, RPMTAG_FILEMODES, RPM_INT16_TYPE, fileModesList,
170 headerAddEntry(dbentry, RPMTAG_FILERDEVS, RPM_INT16_TYPE, fileRDevsList,
172 headerAddEntry(dbentry, RPMTAG_FILESTATES, RPM_INT8_TYPE, fileStatesList,
176 free(fileLinktoList);
181 free(fileMtimesList);
185 free(fileStatesList);
188 rpmdbAdd(db, dbentry);
193 oldrpmdbFreePackageInfo(package);
196 oldrpmdbClose(&olddb);
202 int main(int argc, char ** argv) {
204 fprintf(stderr, "rpmconvert: no arguments expected");
208 rpmReadConfigFiles(NULL, NULL, NULL, 0);
210 printf("rpmconvert 1.0 - converting database in /var/lib/rpm\n");