1995-11-28 06:31:21 +08:00
|
|
|
/* This converts an old style (rpm 1.x) database to the new style */
|
|
|
|
|
1998-07-26 05:00:26 +08:00
|
|
|
#include "system.h"
|
1995-12-14 04:09:47 +08:00
|
|
|
|
1998-07-31 06:09:42 +08:00
|
|
|
#include "build/rpmbuild.h"
|
|
|
|
|
1995-12-14 04:09:47 +08:00
|
|
|
#include "falloc.h"
|
|
|
|
#include "oldrpmdb.h"
|
1996-01-06 08:07:13 +08:00
|
|
|
#include "oldheader.h"
|
1995-12-14 04:09:47 +08:00
|
|
|
|
1996-01-15 07:07:54 +08:00
|
|
|
int convertDB(void);
|
1995-12-27 11:37:38 +08:00
|
|
|
|
1996-01-15 07:07:54 +08:00
|
|
|
int convertDB(void) {
|
1995-12-28 04:05:14 +08:00
|
|
|
struct oldrpmdb olddb;
|
1996-01-09 03:18:14 +08:00
|
|
|
rpmdb db;
|
1995-12-28 04:05:14 +08:00
|
|
|
struct oldrpmdbLabel * packageLabels, * label;
|
|
|
|
struct oldrpmdbPackageInfo package;
|
1995-12-14 04:09:47 +08:00
|
|
|
Header dbentry;
|
|
|
|
char * group;
|
1995-12-20 00:09:38 +08:00
|
|
|
char * gif;
|
|
|
|
int gifSize;
|
1995-12-14 04:09:47 +08:00
|
|
|
char ** fileList;
|
|
|
|
char ** fileMD5List;
|
|
|
|
char ** fileLinktoList;
|
|
|
|
int_32 * fileSizeList;
|
|
|
|
int_32 * fileUIDList;
|
|
|
|
int_32 * fileGIDList;
|
|
|
|
int_32 * fileMtimesList;
|
|
|
|
int_32 * fileFlagsList;
|
|
|
|
int_16 * fileModesList;
|
|
|
|
int_16 * fileRDevsList;
|
|
|
|
char * fileStatesList;
|
1996-01-09 03:18:14 +08:00
|
|
|
char * preun, * postun;
|
1996-01-30 03:30:49 +08:00
|
|
|
int i, j;
|
1995-12-14 04:09:47 +08:00
|
|
|
|
1996-03-29 09:43:10 +08:00
|
|
|
if (exists("/var/lib/rpm/packages.rpm")) {
|
1998-09-28 06:03:52 +08:00
|
|
|
rpmError(RPMERR_NOCREATEDB, _("RPM database already exists"));
|
1995-12-14 04:09:47 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
1996-03-29 09:43:10 +08:00
|
|
|
if (oldrpmdbOpen(&olddb)) {
|
1998-09-28 06:03:52 +08:00
|
|
|
rpmError(RPMERR_OLDDBMISSING, _("Old db is missing"));
|
1995-12-14 04:09:47 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
1995-12-27 11:37:38 +08:00
|
|
|
/* if any of the indexes exist, get rid of them */
|
|
|
|
unlink("/var/lib/rpm/nameindex.rpm");
|
|
|
|
unlink("/var/lib/rpm/groupindex.rpm");
|
|
|
|
unlink("/var/lib/rpm/packageindex.rpm");
|
|
|
|
unlink("/var/lib/rpm/fileindex.rpm");
|
|
|
|
|
1997-10-04 00:05:46 +08:00
|
|
|
if (rpmdbOpen("", &db, O_RDWR | O_CREAT, 0644)) {
|
1998-09-28 06:03:52 +08:00
|
|
|
rpmError(RPMERR_DBOPEN, _("failed to create RPM database /var/lib/rpm"));
|
1995-12-14 04:09:47 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
1995-12-28 04:05:14 +08:00
|
|
|
packageLabels = oldrpmdbGetAllLabels(&olddb);
|
1995-12-14 04:09:47 +08:00
|
|
|
if (!packageLabels) {
|
1998-09-28 06:03:52 +08:00
|
|
|
rpmError(RPMERR_OLDDBCORRUPT, _("Old db is corrupt"));
|
1996-01-09 03:18:14 +08:00
|
|
|
rpmdbClose(db);
|
1995-12-14 04:09:47 +08:00
|
|
|
unlink("/var/lib/rpm/packages.rpm");
|
1995-12-28 04:05:14 +08:00
|
|
|
oldrpmdbClose(&olddb);
|
1995-12-14 04:09:47 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (label = packageLabels; label; label = label->next) {
|
1995-12-28 04:05:14 +08:00
|
|
|
if (oldrpmdbGetPackageInfo(&olddb, *label, &package)) {
|
1998-09-28 06:03:52 +08:00
|
|
|
fprintf(stderr, _("oldrpmdbGetPackageInfo failed &olddb = %p olddb.packages = %p\n"), &olddb, olddb.packages);
|
1995-12-14 04:09:47 +08:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
1995-12-28 04:05:14 +08:00
|
|
|
group = oldrpmdbGetPackageGroup(&olddb, *label);
|
1996-01-09 03:18:14 +08:00
|
|
|
preun = oldrpmdbGetPackagePreun(&olddb, *label);
|
|
|
|
postun = oldrpmdbGetPackagePostun(&olddb, *label);
|
1995-12-14 04:09:47 +08:00
|
|
|
|
1996-11-19 02:02:36 +08:00
|
|
|
dbentry = headerNew();
|
|
|
|
headerAddEntry(dbentry, RPMTAG_NAME, RPM_STRING_TYPE, package.name, 1);
|
|
|
|
headerAddEntry(dbentry, RPMTAG_VERSION, RPM_STRING_TYPE, package.version, 1);
|
|
|
|
headerAddEntry(dbentry, RPMTAG_RELEASE, RPM_STRING_TYPE, package.release, 1);
|
|
|
|
headerAddEntry(dbentry, RPMTAG_DESCRIPTION, RPM_STRING_TYPE,
|
1995-12-14 04:09:47 +08:00
|
|
|
package.description, 1);
|
1996-11-19 02:02:36 +08:00
|
|
|
headerAddEntry(dbentry, RPMTAG_BUILDTIME, RPM_INT32_TYPE, &package.buildTime, 1);
|
|
|
|
headerAddEntry(dbentry, RPMTAG_BUILDHOST, RPM_STRING_TYPE, package.buildHost, 1);
|
|
|
|
headerAddEntry(dbentry, RPMTAG_INSTALLTIME, RPM_INT32_TYPE,
|
1995-12-14 04:09:47 +08:00
|
|
|
&package.installTime, 1);
|
1996-11-19 02:02:36 +08:00
|
|
|
headerAddEntry(dbentry, RPMTAG_DISTRIBUTION, RPM_STRING_TYPE,
|
1995-12-14 04:09:47 +08:00
|
|
|
package.distribution, 1);
|
1996-11-19 02:02:36 +08:00
|
|
|
headerAddEntry(dbentry, RPMTAG_VENDOR, RPM_STRING_TYPE, package.vendor, 1);
|
|
|
|
headerAddEntry(dbentry, RPMTAG_SIZE, RPM_INT32_TYPE, &package.size, 1);
|
1998-09-05 00:17:46 +08:00
|
|
|
headerAddEntry(dbentry, RPMTAG_LICENSE, RPM_STRING_TYPE, package.copyright, 1);
|
1996-11-19 02:02:36 +08:00
|
|
|
headerAddEntry(dbentry, RPMTAG_GROUP, RPM_STRING_TYPE, group, 1);
|
1995-12-14 04:09:47 +08:00
|
|
|
|
1996-01-09 03:18:14 +08:00
|
|
|
if (preun) {
|
1996-11-19 02:02:36 +08:00
|
|
|
headerAddEntry(dbentry, RPMTAG_PREUN, RPM_STRING_TYPE, preun, 1);
|
1996-01-09 03:18:14 +08:00
|
|
|
free(preun);
|
|
|
|
}
|
|
|
|
if (postun) {
|
1996-11-19 02:02:36 +08:00
|
|
|
headerAddEntry(dbentry, RPMTAG_POSTUN, RPM_STRING_TYPE, postun, 1);
|
1996-01-09 03:18:14 +08:00
|
|
|
free(postun);
|
|
|
|
}
|
|
|
|
|
1995-12-28 04:05:14 +08:00
|
|
|
gif = oldrpmdbGetPackageGif(&olddb, *label, &gifSize);
|
1995-12-20 00:09:38 +08:00
|
|
|
if (gif) {
|
1996-11-19 02:02:36 +08:00
|
|
|
headerAddEntry(dbentry, RPMTAG_GIF, RPM_BIN_TYPE, gif, gifSize);
|
1995-12-20 00:09:38 +08:00
|
|
|
free(gif);
|
|
|
|
}
|
|
|
|
|
1995-12-14 04:09:47 +08:00
|
|
|
if (package.fileCount) {
|
|
|
|
/* some packages have no file lists */
|
|
|
|
|
|
|
|
fileList = malloc(sizeof(char *) * package.fileCount);
|
|
|
|
fileLinktoList = malloc(sizeof(char *) * package.fileCount);
|
|
|
|
fileMD5List = malloc(sizeof(char *) * package.fileCount);
|
|
|
|
fileSizeList = malloc(sizeof(int_32) * package.fileCount);
|
|
|
|
fileUIDList = malloc(sizeof(int_32) * package.fileCount);
|
|
|
|
fileGIDList = malloc(sizeof(int_32) * package.fileCount);
|
|
|
|
fileMtimesList = malloc(sizeof(int_32) * package.fileCount);
|
|
|
|
fileFlagsList = malloc(sizeof(int_32) * package.fileCount);
|
|
|
|
fileModesList = malloc(sizeof(int_16) * package.fileCount);
|
|
|
|
fileRDevsList = malloc(sizeof(int_16) * package.fileCount);
|
|
|
|
fileStatesList = malloc(sizeof(char) * package.fileCount);
|
|
|
|
|
1996-01-30 03:30:49 +08:00
|
|
|
/* reverse the file list while we're at it */
|
|
|
|
j = package.fileCount - 1;
|
|
|
|
for (i = 0; i < package.fileCount; i++, j--) {
|
|
|
|
fileList[j] = package.files[i].path;
|
|
|
|
fileMD5List[j] = package.files[i].md5;
|
|
|
|
fileSizeList[j] = package.files[i].size;
|
|
|
|
fileUIDList[j] = package.files[i].uid;
|
|
|
|
fileGIDList[j] = package.files[i].gid;
|
|
|
|
fileMtimesList[j] = package.files[i].mtime;
|
|
|
|
fileModesList[j] = package.files[i].mode;
|
|
|
|
fileRDevsList[j] = package.files[i].rdev;
|
|
|
|
fileStatesList[j] = package.files[i].state;
|
1995-12-14 04:09:47 +08:00
|
|
|
|
|
|
|
if (package.files[i].linkto)
|
1996-01-30 03:30:49 +08:00
|
|
|
fileLinktoList[j] = package.files[i].linkto;
|
1995-12-14 04:09:47 +08:00
|
|
|
else
|
1996-01-30 03:30:49 +08:00
|
|
|
fileLinktoList[j] = "";
|
1995-12-14 04:09:47 +08:00
|
|
|
|
1996-01-30 03:30:49 +08:00
|
|
|
fileFlagsList[j] = 0;
|
1995-12-14 04:09:47 +08:00
|
|
|
if (package.files[i].isdoc)
|
1996-01-30 03:30:49 +08:00
|
|
|
fileFlagsList[j] |= RPMFILE_DOC;
|
1995-12-14 04:09:47 +08:00
|
|
|
if (package.files[i].isconf)
|
1996-01-30 03:30:49 +08:00
|
|
|
fileFlagsList[j] |= RPMFILE_CONFIG;
|
1995-12-14 04:09:47 +08:00
|
|
|
}
|
|
|
|
|
1996-11-19 02:02:36 +08:00
|
|
|
headerAddEntry(dbentry, RPMTAG_FILENAMES, RPM_STRING_ARRAY_TYPE, fileList,
|
1995-12-14 04:09:47 +08:00
|
|
|
package.fileCount);
|
1996-11-19 02:02:36 +08:00
|
|
|
headerAddEntry(dbentry, RPMTAG_FILELINKTOS, RPM_STRING_ARRAY_TYPE,
|
1995-12-27 11:37:38 +08:00
|
|
|
fileLinktoList, package.fileCount);
|
1996-11-19 02:02:36 +08:00
|
|
|
headerAddEntry(dbentry, RPMTAG_FILEMD5S, RPM_STRING_ARRAY_TYPE, fileMD5List,
|
1995-12-14 04:09:47 +08:00
|
|
|
package.fileCount);
|
1996-11-19 02:02:36 +08:00
|
|
|
headerAddEntry(dbentry, RPMTAG_FILESIZES, RPM_INT32_TYPE, fileSizeList,
|
1995-12-14 04:09:47 +08:00
|
|
|
package.fileCount);
|
1996-11-19 02:02:36 +08:00
|
|
|
headerAddEntry(dbentry, RPMTAG_FILEUIDS, RPM_INT32_TYPE, fileUIDList,
|
1995-12-14 04:09:47 +08:00
|
|
|
package.fileCount);
|
1996-11-19 02:02:36 +08:00
|
|
|
headerAddEntry(dbentry, RPMTAG_FILEGIDS, RPM_INT32_TYPE, fileGIDList,
|
1995-12-14 04:09:47 +08:00
|
|
|
package.fileCount);
|
1996-11-19 02:02:36 +08:00
|
|
|
headerAddEntry(dbentry, RPMTAG_FILEMTIMES, RPM_INT32_TYPE, fileMtimesList,
|
1995-12-14 04:09:47 +08:00
|
|
|
package.fileCount);
|
1996-11-19 02:02:36 +08:00
|
|
|
headerAddEntry(dbentry, RPMTAG_FILEFLAGS, RPM_INT32_TYPE, fileFlagsList,
|
1995-12-14 04:09:47 +08:00
|
|
|
package.fileCount);
|
1996-11-19 02:02:36 +08:00
|
|
|
headerAddEntry(dbentry, RPMTAG_FILEMODES, RPM_INT16_TYPE, fileModesList,
|
1995-12-14 04:09:47 +08:00
|
|
|
package.fileCount);
|
1996-11-19 02:02:36 +08:00
|
|
|
headerAddEntry(dbentry, RPMTAG_FILERDEVS, RPM_INT16_TYPE, fileRDevsList,
|
1995-12-14 04:09:47 +08:00
|
|
|
package.fileCount);
|
1996-11-19 02:02:36 +08:00
|
|
|
headerAddEntry(dbentry, RPMTAG_FILESTATES, RPM_INT8_TYPE, fileStatesList,
|
1995-12-14 04:09:47 +08:00
|
|
|
package.fileCount);
|
|
|
|
|
|
|
|
free(fileList);
|
|
|
|
free(fileLinktoList);
|
|
|
|
free(fileMD5List);
|
|
|
|
free(fileSizeList);
|
|
|
|
free(fileUIDList);
|
|
|
|
free(fileGIDList);
|
|
|
|
free(fileMtimesList);
|
|
|
|
free(fileFlagsList);
|
|
|
|
free(fileModesList);
|
|
|
|
free(fileRDevsList);
|
|
|
|
free(fileStatesList);
|
|
|
|
}
|
|
|
|
|
1996-01-09 03:18:14 +08:00
|
|
|
rpmdbAdd(db, dbentry);
|
1995-12-27 11:37:38 +08:00
|
|
|
|
1995-12-14 04:09:47 +08:00
|
|
|
free(group);
|
1996-11-19 02:02:36 +08:00
|
|
|
headerFree(dbentry);
|
1995-12-14 04:09:47 +08:00
|
|
|
|
1995-12-28 04:05:14 +08:00
|
|
|
oldrpmdbFreePackageInfo(package);
|
1995-12-14 04:09:47 +08:00
|
|
|
}
|
|
|
|
|
1995-12-28 04:05:14 +08:00
|
|
|
oldrpmdbClose(&olddb);
|
1996-01-09 03:18:14 +08:00
|
|
|
rpmdbClose(db);
|
1995-12-27 11:37:38 +08:00
|
|
|
|
1995-12-14 04:09:47 +08:00
|
|
|
return 1;
|
1995-11-28 06:31:21 +08:00
|
|
|
}
|
1996-01-15 07:07:54 +08:00
|
|
|
|
|
|
|
int main(int argc, char ** argv) {
|
|
|
|
if (argc != 1) {
|
1998-09-28 06:03:52 +08:00
|
|
|
fprintf(stderr, _("rpmconvert: no arguments expected"));
|
1996-01-15 07:07:54 +08:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
1997-10-04 00:05:46 +08:00
|
|
|
rpmReadConfigFiles(NULL, NULL, NULL, 0);
|
|
|
|
|
1998-09-28 06:03:52 +08:00
|
|
|
printf(_("rpmconvert 1.0 - converting database in /var/lib/rpm\n"));
|
1996-01-15 07:07:54 +08:00
|
|
|
convertDB();
|
|
|
|
|
|
|
|
exit(0);
|
|
|
|
}
|