1 /* This converts an old style (rpm 1.x) database to the new style */
11 #include "oldrpmfile.h"
15 int reindexDB(char * dbprefix) {
19 int convertDB(char * dbprefix) {
22 struct rpmdbLabel * packageLabels, * label;
23 struct rpmdbPackageInfo package;
25 unsigned int dboffset;
31 char ** fileLinktoList;
32 int_32 * fileSizeList;
35 int_32 * fileMtimesList;
36 int_32 * fileFlagsList;
37 int_16 * fileModesList;
38 int_16 * fileRDevsList;
39 char * fileStatesList;
42 if (rpmdbOpen(&olddb)) {
43 error(RPMERR_OLDDBMISSING);
47 if (exists("/var/lib/rpm/packages.rpm")) {
49 error(RPMERR_NOCREATEDB);
52 unlink("/var/lib/rpm/packages.rpm");
55 pkgs = faOpen("/var/lib/rpm/packages.rpm", O_RDWR | O_CREAT, 0644);
62 packageLabels = rpmdbGetAllLabels(&olddb);
64 error(RPMERR_OLDDBCORRUPT);
66 unlink("/var/lib/rpm/packages.rpm");
71 for (label = packageLabels; label; label = label->next) {
72 if (rpmdbGetPackageInfo(&olddb, *label, &package)) {
73 printf("rpmdbGetPackageInfo failed &olddb = %p olddb.packages = %p\n", &olddb, olddb.packages);
77 group = rpmdbGetPackageGroup(&olddb, *label);
79 dbentry = newHeader();
80 addEntry(dbentry, RPMTAG_NAME, STRING_TYPE, package.name, 1);
81 addEntry(dbentry, RPMTAG_VERSION, STRING_TYPE, package.version, 1);
82 addEntry(dbentry, RPMTAG_RELEASE, STRING_TYPE, package.release, 1);
83 addEntry(dbentry, RPMTAG_DESCRIPTION, STRING_TYPE,
84 package.description, 1);
85 addEntry(dbentry, RPMTAG_BUILDTIME, INT32_TYPE, &package.buildTime, 1);
86 addEntry(dbentry, RPMTAG_BUILDHOST, STRING_TYPE, package.buildHost, 1);
87 addEntry(dbentry, RPMTAG_INSTALLTIME, INT32_TYPE,
88 &package.installTime, 1);
89 addEntry(dbentry, RPMTAG_DISTRIBUTION, STRING_TYPE,
90 package.distribution, 1);
91 addEntry(dbentry, RPMTAG_VENDOR, STRING_TYPE, package.vendor, 1);
92 addEntry(dbentry, RPMTAG_SIZE, INT32_TYPE, &package.size, 1);
93 addEntry(dbentry, RPMTAG_COPYRIGHT, STRING_TYPE, package.copyright, 1);
94 addEntry(dbentry, RPMTAG_GROUP, STRING_TYPE, group, 1);
96 gif = rpmdbGetPackageGif(&olddb, *label, &gifSize);
98 /*addEntry(dbentry, RPMTAG_GIF, BIN_TYPE, gif, gifSize);*/
102 if (package.fileCount) {
103 /* some packages have no file lists */
105 fileList = malloc(sizeof(char *) * package.fileCount);
106 fileLinktoList = malloc(sizeof(char *) * package.fileCount);
107 fileMD5List = malloc(sizeof(char *) * package.fileCount);
108 fileSizeList = malloc(sizeof(int_32) * package.fileCount);
109 fileUIDList = malloc(sizeof(int_32) * package.fileCount);
110 fileGIDList = malloc(sizeof(int_32) * package.fileCount);
111 fileMtimesList = malloc(sizeof(int_32) * package.fileCount);
112 fileFlagsList = malloc(sizeof(int_32) * package.fileCount);
113 fileModesList = malloc(sizeof(int_16) * package.fileCount);
114 fileRDevsList = malloc(sizeof(int_16) * package.fileCount);
115 fileStatesList = malloc(sizeof(char) * package.fileCount);
117 for (i = 0; i < package.fileCount; i++) {
118 fileList[i] = package.files[i].path;
119 fileMD5List[i] = package.files[i].md5;
120 fileSizeList[i] = package.files[i].size;
121 fileUIDList[i] = package.files[i].uid;
122 fileGIDList[i] = package.files[i].gid;
123 fileMtimesList[i] = package.files[i].mtime;
124 fileModesList[i] = package.files[i].mode;
125 fileRDevsList[i] = package.files[i].rdev;
126 fileStatesList[i] = package.files[i].state;
128 if (package.files[i].linkto)
129 fileLinktoList[i] = package.files[i].linkto;
131 fileLinktoList[i] = "";
133 fileFlagsList[i] = 0;
134 if (package.files[i].isdoc)
135 fileFlagsList[i] |= RPMFILE_DOC;
136 if (package.files[i].isconf)
137 fileFlagsList[i] |= RPMFILE_CONFIG;
140 addEntry(dbentry, RPMTAG_FILENAMES, STRING_TYPE, fileList,
142 addEntry(dbentry, RPMTAG_FILELINKTOS, STRING_TYPE, fileLinktoList,
144 addEntry(dbentry, RPMTAG_FILEMD5S, STRING_TYPE, fileMD5List,
146 addEntry(dbentry, RPMTAG_FILESIZES, INT32_TYPE, fileSizeList,
148 addEntry(dbentry, RPMTAG_FILEUIDS, INT32_TYPE, fileUIDList,
150 addEntry(dbentry, RPMTAG_FILEGIDS, INT32_TYPE, fileGIDList,
152 addEntry(dbentry, RPMTAG_FILEMTIMES, INT32_TYPE, fileMtimesList,
154 addEntry(dbentry, RPMTAG_FILEFLAGS, INT32_TYPE, fileFlagsList,
156 addEntry(dbentry, RPMTAG_FILEMODES, INT16_TYPE, fileModesList,
158 addEntry(dbentry, RPMTAG_FILERDEVS, INT16_TYPE, fileRDevsList,
160 addEntry(dbentry, RPMTAG_FILESTATES, INT8_TYPE, fileStatesList,
164 free(fileLinktoList);
169 free(fileMtimesList);
173 free(fileStatesList);
176 dboffset = faAlloc(pkgs, sizeofHeader(dbentry));
177 lseek(pkgs->fd, dboffset, SEEK_SET);
179 writeHeader(pkgs->fd, dbentry);
184 rpmdbFreePackageInfo(package);