summaryrefslogtreecommitdiff
path: root/lib/install.c
diff options
context:
space:
mode:
authorjbj <devnull@localhost>1999-07-13 22:53:46 +0000
committerjbj <devnull@localhost>1999-07-13 22:53:46 +0000
commit348fcc286d45687fc7d00312a13c1f9f20bcd661 (patch)
tree0e1d91994cfe7d78d37fafb36e2ba630c091d8f6 /lib/install.c
parent05dc5eaccf810133472f31223784419321490bb3 (diff)
downloadlibrpm-tizen-348fcc286d45687fc7d00312a13c1f9f20bcd661.tar.gz
librpm-tizen-348fcc286d45687fc7d00312a13c1f9f20bcd661.tar.bz2
librpm-tizen-348fcc286d45687fc7d00312a13c1f9f20bcd661.zip
Eliminate static prototypes.
CVS patchset: 3150 CVS date: 1999/07/13 22:53:46
Diffstat (limited to 'lib/install.c')
-rw-r--r--lib/install.c744
1 files changed, 371 insertions, 373 deletions
diff --git a/lib/install.c b/lib/install.c
index 0f1883a48..67fca5517 100644
--- a/lib/install.c
+++ b/lib/install.c
@@ -36,21 +36,6 @@ struct fileInfo {
int install;
} ;
-static int installArchive(FD_t fd, struct fileInfo * files,
- int fileCount, rpmCallbackFunction notify,
- void * notifydb, const void * pkgKey, Header h,
- char ** specFile, int archiveSize);
-static int installSources(Header h, const char * rootdir, FD_t fd,
- const char ** specFilePtr, rpmCallbackFunction notify,
- void * notifyData);
-static int assembleFileList(Header h, struct fileMemory * mem,
- int * fileCountPtr, struct fileInfo ** filesPtr,
- int stripPrefixLength, enum fileActions * actions);
-static void setFileOwners(Header h, struct fileInfo * files, int fileCount);
-static void freeFileMemory(struct fileMemory fileMem);
-static void trimChangelog(Header h);
-static int markReplacedFiles(rpmdb db, struct sharedFileInfo * replList);
-
/* XXX add more tags */
static struct tagMacro {
const char * macroname;
@@ -62,7 +47,8 @@ static struct tagMacro {
{ NULL, 0 }
};
-static int rpmInstallLoadMacros(Header h) {
+static int rpmInstallLoadMacros(Header h)
+{
struct tagMacro *tagm;
const char *body;
int type;
@@ -76,48 +62,8 @@ static int rpmInstallLoadMacros(Header h) {
return 0;
}
-/* 0 success */
-/* 1 bad magic */
-/* 2 error */
-int rpmInstallSourcePackage(const char * rootdir, FD_t fd,
- const char ** specFile, rpmCallbackFunction notify,
- void * notifyData, char ** cookie) {
- int rc, isSource;
- Header h;
- int major, minor;
-
- rc = rpmReadPackageHeader(fd, &h, &isSource, &major, &minor);
- if (rc) return rc;
-
- if (!isSource) {
- rpmError(RPMERR_NOTSRPM, _("source package expected, binary found"));
- return 2;
- }
-
-#if defined(ENABLE_V1_PACKAGES)
- if (major == 1) {
- notify = NULL;
- h = NULL;
- }
-#endif /* ENABLE_V1_PACKAGES */
-
- if (cookie) {
- *cookie = NULL;
- if (h && headerGetEntry(h, RPMTAG_COOKIE, NULL, (void **) cookie,
- NULL)) {
- *cookie = strdup(*cookie);
- }
- }
-
- rpmInstallLoadMacros(h);
-
- rc = installSources(h, rootdir, fd, specFile, notify, notifyData);
- if (h != NULL) headerFree(h);
-
- return rc;
-}
-
-static void freeFileMemory(struct fileMemory fileMem) {
+static void freeFileMemory(struct fileMemory fileMem)
+{
free(fileMem.files);
free(fileMem.names);
free(fileMem.cpioNames);
@@ -127,7 +73,8 @@ static void freeFileMemory(struct fileMemory fileMem) {
static int assembleFileList(Header h, struct fileMemory * mem,
int * fileCountPtr, struct fileInfo ** filesPtr,
int stripPrefixLength,
- enum fileActions * actions) {
+ enum fileActions * actions)
+{
uint_32 * fileFlags;
uint_32 * fileSizes;
uint_16 * fileModes;
@@ -175,7 +122,8 @@ static int assembleFileList(Header h, struct fileMemory * mem,
return 0;
}
-static void setFileOwners(Header h, struct fileInfo * files, int fileCount) {
+static void setFileOwners(Header h, struct fileInfo * files, int fileCount)
+{
char ** fileOwners;
char ** fileGroups;
int i;
@@ -205,7 +153,8 @@ static void setFileOwners(Header h, struct fileInfo * files, int fileCount) {
free(fileGroups);
}
-static void trimChangelog(Header h) {
+static void trimChangelog(Header h)
+{
int * times;
char ** names, ** texts;
long numToKeep;
@@ -254,285 +203,55 @@ static void trimChangelog(Header h) {
free(texts);
}
-/* 0 success */
-/* 1 bad magic */
-/* 2 error */
-int installBinaryPackage(const char * rootdir, rpmdb db, FD_t fd, Header h,
- int flags, rpmCallbackFunction notify,
- void * notifyData, const void * pkgKey,
- enum fileActions * actions,
- struct sharedFileInfo * sharedList, FD_t scriptFd) {
- int rc;
- char * name, * version, * release;
- int fileCount, type, count;
- struct fileInfo * files;
- int_32 installTime;
- char * fileStates;
- int i;
- int installFile = 0;
- int otherOffset = 0;
- char * ext = NULL, * newpath;
- char * defaultPrefix;
- dbiIndexSet matches;
- int scriptArg;
- int stripSize = 1; /* strip at least first / for cpio */
- uint_32 * archiveSizePtr;
- struct fileMemory fileMem;
- int freeFileMem = 0;
- char * currDir = NULL, * tmpptr;
-
- if (flags & RPMTRANS_FLAG_JUSTDB)
- flags |= RPMTRANS_FLAG_NOSCRIPTS;
-
- headerGetEntry(h, RPMTAG_NAME, &type, (void **) &name, &fileCount);
- headerGetEntry(h, RPMTAG_VERSION, &type, (void **) &version, &fileCount);
- headerGetEntry(h, RPMTAG_RELEASE, &type, (void **) &release, &fileCount);
-
- rpmMessage(RPMMESS_DEBUG, _("package: %s-%s-%s files test = %d\n"),
- name, version, release, flags & RPMTRANS_FLAG_TEST);
-
- rc = rpmdbFindPackage(db, name, &matches);
- if (rc == -1) return 2;
- if (rc) {
- scriptArg = 1;
- } else {
- scriptArg = dbiIndexSetCount(matches) + 1;
- dbiFreeIndexRecord(matches);
- }
-
- if (!rpmdbFindByHeader(db, h, &matches)) {
- otherOffset = matches.recs[0].recOffset;
- dbiFreeIndexRecord(matches);
- }
-
- if (rootdir) {
- /* this loads all of the name services libraries, in case we
- don't have access to them in the chroot() */
- (void)getpwnam("root");
- endpwent();
-
- tmpptr = currentDirectory();
- currDir = alloca(strlen(tmpptr) + 1);
- strcpy(currDir, tmpptr);
- free(tmpptr);
-
- chdir("/");
- chroot(rootdir);
- }
-
- if (!(flags & RPMTRANS_FLAG_JUSTDB) && headerIsEntry(h, RPMTAG_FILENAMES)) {
- /* old format relocateable packages need the entire default
- prefix stripped to form the cpio list, while all other packages
- need the leading / stripped */
- if (headerGetEntry(h, RPMTAG_DEFAULTPREFIX, NULL, (void **)
- &defaultPrefix, NULL)) {
- stripSize = strlen(defaultPrefix) + 1;
- } else {
- stripSize = 1;
- }
-
- if (assembleFileList(h, &fileMem, &fileCount, &files, stripSize,
- actions)) {
- if (rootdir) {
- chroot(".");
- chdir(currDir);
- }
- return 2;
- }
-
- freeFileMem = 1;
- } else {
- files = NULL;
- }
+static int markReplacedFiles(rpmdb db, struct sharedFileInfo * replList)
+{
+ struct sharedFileInfo * fileInfo;
+ Header secHeader = NULL, sh;
+ char * secStates;
+ int type, count;
- if (flags & RPMTRANS_FLAG_TEST) {
- if (rootdir) {
- chroot(".");
- chdir(currDir);
- }
-
- rpmMessage(RPMMESS_DEBUG, _("stopping install as we're running --test\n"));
- if (freeFileMem) freeFileMemory(fileMem);
- return 0;
- }
-
- rpmMessage(RPMMESS_DEBUG, _("running preinstall script (if any)\n"));
- if (runInstScript("/", h, RPMTAG_PREIN, RPMTAG_PREINPROG, scriptArg,
- flags & RPMTRANS_FLAG_NOSCRIPTS, scriptFd)) {
- if (freeFileMem) freeFileMemory(fileMem);
-
- if (rootdir) {
- chroot(".");
- chdir(currDir);
- }
-
- return 2;
- }
-
- if (files) {
- setFileOwners(h, files, fileCount);
-
- for (i = 0; i < fileCount; i++) {
- switch (files[i].action) {
- case FA_BACKUP:
- ext = ".rpmorig";
- installFile = 1;
- break;
-
- case FA_ALTNAME:
- ext = NULL;
- installFile = 1;
-
- newpath = alloca(strlen(files[i].relativePath) + 20);
- strcpy(newpath, files[i].relativePath);
- strcat(newpath, ".rpmnew");
- rpmError(RPMMESS_ALTNAME, _("warning: %s created as %s"),
- files[i].relativePath, newpath);
- files[i].relativePath = newpath;
-
- break;
-
- case FA_SAVE:
- ext = ".rpmsave";
- installFile = 1;
- break;
-
- case FA_CREATE:
- installFile = 1;
- ext = NULL;
- break;
-
- case FA_SKIP:
- installFile = 0;
- ext = NULL;
- break;
-
- case FA_SKIPNSTATE:
- installFile = 0;
- ext = NULL;
- files[i].state = RPMFILE_STATE_NOTINSTALLED;
- break;
-
- case FA_UNKNOWN:
- case FA_REMOVE:
- break;
- }
-
- if (ext) {
- newpath = alloca(strlen(files[i].relativePath) + 20);
- strcpy(newpath, files[i].relativePath);
- strcat(newpath, ext);
- rpmError(RPMMESS_BACKUP, _("warning: %s saved as %s"),
- files[i].relativePath, newpath);
-
- if (rename(files[i].relativePath, newpath)) {
- rpmError(RPMERR_RENAME, _("rename of %s to %s failed: %s"),
- files[i].relativePath, newpath, strerror(errno));
- if (freeFileMem) freeFileMemory(fileMem);
+ int secOffset = 0;
- if (rootdir) {
- chroot(".");
- chdir(currDir);
- }
+ for (fileInfo = replList; fileInfo->otherPkg; fileInfo++) {
+ if (secOffset != fileInfo->otherPkg) {
+ if (secHeader != NULL) {
+ /* ignore errors here - just do the best we can */
- return 2;
- }
+ rpmdbUpdateRecord(db, secOffset, secHeader);
+ headerFree(secHeader);
}
- if (!installFile) {
- files[i].install = 0;
- }
- }
-
- if (!headerGetEntry(h, RPMTAG_ARCHIVESIZE, &type,
- (void **) &archiveSizePtr, &count))
- archiveSizePtr = NULL;
-
- if (notify) {
- notify(h, RPMCALLBACK_INST_START, 0, 0, pkgKey, notifyData);
- }
-
- /* the file pointer for fd is pointing at the cpio archive */
- if (installArchive(fd, files, fileCount, notify, notifyData, pkgKey, h,
- NULL, archiveSizePtr ? *archiveSizePtr : 0)) {
- headerFree(h);
- if (freeFileMem) freeFileMemory(fileMem);
-
- if (rootdir) {
- chroot(".");
- chdir(currDir);
+ secOffset = fileInfo->otherPkg;
+ sh = rpmdbGetRecord(db, secOffset);
+ if (sh == NULL) {
+ secOffset = 0;
+ } else {
+ secHeader = headerCopy(sh); /* so we can modify it */
+ headerFree(sh);
}
- return 2;
- }
-
- fileStates = malloc(sizeof(*fileStates) * fileCount);
- for (i = 0; i < fileCount; i++)
- fileStates[i] = files[i].state;
-
- headerAddEntry(h, RPMTAG_FILESTATES, RPM_CHAR_TYPE, fileStates,
- fileCount);
-
- free(fileStates);
- if (freeFileMem) freeFileMemory(fileMem);
- } else if (flags & RPMTRANS_FLAG_JUSTDB) {
- if (headerGetEntry(h, RPMTAG_FILENAMES, NULL, NULL, &fileCount)) {
- fileStates = malloc(sizeof(*fileStates) * fileCount);
- memset(fileStates, RPMFILE_STATE_NORMAL, fileCount);
- headerAddEntry(h, RPMTAG_FILESTATES, RPM_CHAR_TYPE, fileStates,
- fileCount);
- free(fileStates);
+ headerGetEntry(secHeader, RPMTAG_FILESTATES, &type,
+ (void **) &secStates, &count);
}
- }
-
- installTime = time(NULL);
- headerAddEntry(h, RPMTAG_INSTALLTIME, RPM_INT32_TYPE, &installTime, 1);
-
- if (rootdir) {
- chroot(".");
- chdir(currDir);
- }
-
- trimChangelog(h);
- /* if this package has already been installed, remove it from the database
- before adding the new one */
- if (otherOffset) {
- rpmdbRemove(db, otherOffset, 1);
- }
-
- if (rpmdbAdd(db, h)) {
- headerFree(h);
- return 2;
- }
-
- rpmMessage(RPMMESS_DEBUG, _("running postinstall script (if any)\n"));
-
- if (runInstScript(rootdir, h, RPMTAG_POSTIN, RPMTAG_POSTINPROG, scriptArg,
- flags & RPMTRANS_FLAG_NOSCRIPTS, scriptFd)) {
- return 2;
+ /* by now, secHeader is the right header to modify, secStates is
+ the right states list to modify */
+
+ secStates[fileInfo->otherFileNum] = RPMFILE_STATE_REPLACED;
}
- if (!(flags & RPMTRANS_FLAG_NOTRIGGERS)) {
- /* Run triggers this package sets off */
- if (runTriggers(rootdir, db, RPMSENSE_TRIGGERIN, h, 0, scriptFd)) {
- return 2;
- }
+ if (secHeader != NULL) {
+ /* ignore errors here - just do the best we can */
- /* Run triggers in this package which are set off by other things in
- the database. */
- if (runImmedTriggers(rootdir, db, RPMSENSE_TRIGGERIN, h, 0, scriptFd)) {
- return 2;
- }
+ rpmdbUpdateRecord(db, secOffset, secHeader);
+ headerFree(secHeader);
}
- if (sharedList)
- markReplacedFiles(db, sharedList);
-
return 0;
}
-static void callback(struct cpioCallbackInfo * cpioInfo, void * data) {
+static void callback(struct cpioCallbackInfo * cpioInfo, void * data)
+{
struct callbackInfo * ourInfo = data;
char * chptr;
@@ -553,7 +272,8 @@ static void callback(struct cpioCallbackInfo * cpioInfo, void * data) {
static int installArchive(FD_t fd, struct fileInfo * files,
int fileCount, rpmCallbackFunction notify,
void * notifyData, const void * pkgKey, Header h,
- char ** specFile, int archiveSize) {
+ char ** specFile, int archiveSize)
+{
int rc, i;
struct cpioFileMapping * map = NULL;
int mappedFiles = 0;
@@ -634,7 +354,8 @@ static int installArchive(FD_t fd, struct fileInfo * files,
/* 2 error */
static int installSources(Header h, const char * rootdir, FD_t fd,
const char ** specFilePtr, rpmCallbackFunction notify,
- void * notifyData) {
+ void * notifyData)
+{
char * specFile;
int specFileIndex = -1;
const char * realSourceDir = NULL;
@@ -811,53 +532,8 @@ exit:
return rc;
}
-static int markReplacedFiles(rpmdb db, struct sharedFileInfo * replList) {
- struct sharedFileInfo * fileInfo;
- Header secHeader = NULL, sh;
- char * secStates;
- int type, count;
-
- int secOffset = 0;
-
- for (fileInfo = replList; fileInfo->otherPkg; fileInfo++) {
- if (secOffset != fileInfo->otherPkg) {
- if (secHeader != NULL) {
- /* ignore errors here - just do the best we can */
-
- rpmdbUpdateRecord(db, secOffset, secHeader);
- headerFree(secHeader);
- }
-
- secOffset = fileInfo->otherPkg;
- sh = rpmdbGetRecord(db, secOffset);
- if (sh == NULL) {
- secOffset = 0;
- } else {
- secHeader = headerCopy(sh); /* so we can modify it */
- headerFree(sh);
- }
-
- headerGetEntry(secHeader, RPMTAG_FILESTATES, &type,
- (void **) &secStates, &count);
- }
-
- /* by now, secHeader is the right header to modify, secStates is
- the right states list to modify */
-
- secStates[fileInfo->otherFileNum] = RPMFILE_STATE_REPLACED;
- }
-
- if (secHeader != NULL) {
- /* ignore errors here - just do the best we can */
-
- rpmdbUpdateRecord(db, secOffset, secHeader);
- headerFree(secHeader);
- }
-
- return 0;
-}
-
-int rpmVersionCompare(Header first, Header second) {
+int rpmVersionCompare(Header first, Header second)
+{
char * one, * two;
int_32 * epochOne, * epochTwo;
int rc;
@@ -892,7 +568,8 @@ int rpmVersionCompare(Header first, Header second) {
return rpmvercmp(one, two);
}
-const char * fileActionString(enum fileActions a) {
+const char * fileActionString(enum fileActions a)
+{
switch (a) {
case FA_UNKNOWN: return "unknown";
case FA_CREATE: return "create";
@@ -906,3 +583,324 @@ const char * fileActionString(enum fileActions a) {
return "???";
}
+
+/* 0 success */
+/* 1 bad magic */
+/* 2 error */
+int rpmInstallSourcePackage(const char * rootdir, FD_t fd,
+ const char ** specFile, rpmCallbackFunction notify,
+ void * notifyData, char ** cookie)
+{
+ int rc, isSource;
+ Header h;
+ int major, minor;
+
+ rc = rpmReadPackageHeader(fd, &h, &isSource, &major, &minor);
+ if (rc) return rc;
+
+ if (!isSource) {
+ rpmError(RPMERR_NOTSRPM, _("source package expected, binary found"));
+ return 2;
+ }
+
+#if defined(ENABLE_V1_PACKAGES)
+ if (major == 1) {
+ notify = NULL;
+ h = NULL;
+ }
+#endif /* ENABLE_V1_PACKAGES */
+
+ if (cookie) {
+ *cookie = NULL;
+ if (h && headerGetEntry(h, RPMTAG_COOKIE, NULL, (void **) cookie,
+ NULL)) {
+ *cookie = strdup(*cookie);
+ }
+ }
+
+ rpmInstallLoadMacros(h);
+
+ rc = installSources(h, rootdir, fd, specFile, notify, notifyData);
+ if (h != NULL) headerFree(h);
+
+ return rc;
+}
+
+/* 0 success */
+/* 1 bad magic */
+/* 2 error */
+int installBinaryPackage(const char * rootdir, rpmdb db, FD_t fd, Header h,
+ int flags, rpmCallbackFunction notify,
+ void * notifyData, const void * pkgKey,
+ enum fileActions * actions,
+ struct sharedFileInfo * sharedList, FD_t scriptFd)
+{
+ int rc;
+ char * name, * version, * release;
+ int fileCount, type, count;
+ struct fileInfo * files;
+ int_32 installTime;
+ char * fileStates;
+ int i;
+ int installFile = 0;
+ int otherOffset = 0;
+ char * ext = NULL, * newpath;
+ char * defaultPrefix;
+ dbiIndexSet matches;
+ int scriptArg;
+ int stripSize = 1; /* strip at least first / for cpio */
+ uint_32 * archiveSizePtr;
+ struct fileMemory fileMem;
+ int freeFileMem = 0;
+ char * currDir = NULL, * tmpptr;
+
+ if (flags & RPMTRANS_FLAG_JUSTDB)
+ flags |= RPMTRANS_FLAG_NOSCRIPTS;
+
+ headerGetEntry(h, RPMTAG_NAME, &type, (void **) &name, &fileCount);
+ headerGetEntry(h, RPMTAG_VERSION, &type, (void **) &version, &fileCount);
+ headerGetEntry(h, RPMTAG_RELEASE, &type, (void **) &release, &fileCount);
+
+ rpmMessage(RPMMESS_DEBUG, _("package: %s-%s-%s files test = %d\n"),
+ name, version, release, flags & RPMTRANS_FLAG_TEST);
+
+ rc = rpmdbFindPackage(db, name, &matches);
+ if (rc == -1) return 2;
+ if (rc) {
+ scriptArg = 1;
+ } else {
+ scriptArg = dbiIndexSetCount(matches) + 1;
+ dbiFreeIndexRecord(matches);
+ }
+
+ if (!rpmdbFindByHeader(db, h, &matches)) {
+ otherOffset = matches.recs[0].recOffset;
+ dbiFreeIndexRecord(matches);
+ }
+
+ if (rootdir) {
+ /* this loads all of the name services libraries, in case we
+ don't have access to them in the chroot() */
+ (void)getpwnam("root");
+ endpwent();
+
+ tmpptr = currentDirectory();
+ currDir = alloca(strlen(tmpptr) + 1);
+ strcpy(currDir, tmpptr);
+ free(tmpptr);
+
+ chdir("/");
+ chroot(rootdir);
+ }
+
+ if (!(flags & RPMTRANS_FLAG_JUSTDB) && headerIsEntry(h, RPMTAG_FILENAMES)) {
+ /* old format relocateable packages need the entire default
+ prefix stripped to form the cpio list, while all other packages
+ need the leading / stripped */
+ if (headerGetEntry(h, RPMTAG_DEFAULTPREFIX, NULL, (void **)
+ &defaultPrefix, NULL)) {
+ stripSize = strlen(defaultPrefix) + 1;
+ } else {
+ stripSize = 1;
+ }
+
+ if (assembleFileList(h, &fileMem, &fileCount, &files, stripSize,
+ actions)) {
+ if (rootdir) {
+ chroot(".");
+ chdir(currDir);
+ }
+ return 2;
+ }
+
+ freeFileMem = 1;
+ } else {
+ files = NULL;
+ }
+
+ if (flags & RPMTRANS_FLAG_TEST) {
+ if (rootdir) {
+ chroot(".");
+ chdir(currDir);
+ }
+
+ rpmMessage(RPMMESS_DEBUG, _("stopping install as we're running --test\n"));
+ if (freeFileMem) freeFileMemory(fileMem);
+ return 0;
+ }
+
+ rpmMessage(RPMMESS_DEBUG, _("running preinstall script (if any)\n"));
+ if (runInstScript("/", h, RPMTAG_PREIN, RPMTAG_PREINPROG, scriptArg,
+ flags & RPMTRANS_FLAG_NOSCRIPTS, scriptFd)) {
+ if (freeFileMem) freeFileMemory(fileMem);
+
+ if (rootdir) {
+ chroot(".");
+ chdir(currDir);
+ }
+
+ return 2;
+ }
+
+ if (files) {
+ setFileOwners(h, files, fileCount);
+
+ for (i = 0; i < fileCount; i++) {
+ switch (files[i].action) {
+ case FA_BACKUP:
+ ext = ".rpmorig";
+ installFile = 1;
+ break;
+
+ case FA_ALTNAME:
+ ext = NULL;
+ installFile = 1;
+
+ newpath = alloca(strlen(files[i].relativePath) + 20);
+ strcpy(newpath, files[i].relativePath);
+ strcat(newpath, ".rpmnew");
+ rpmError(RPMMESS_ALTNAME, _("warning: %s created as %s"),
+ files[i].relativePath, newpath);
+ files[i].relativePath = newpath;
+
+ break;
+
+ case FA_SAVE:
+ ext = ".rpmsave";
+ installFile = 1;
+ break;
+
+ case FA_CREATE:
+ installFile = 1;
+ ext = NULL;
+ break;
+
+ case FA_SKIP:
+ installFile = 0;
+ ext = NULL;
+ break;
+
+ case FA_SKIPNSTATE:
+ installFile = 0;
+ ext = NULL;
+ files[i].state = RPMFILE_STATE_NOTINSTALLED;
+ break;
+
+ case FA_UNKNOWN:
+ case FA_REMOVE:
+ break;
+ }
+
+ if (ext) {
+ newpath = alloca(strlen(files[i].relativePath) + 20);
+ strcpy(newpath, files[i].relativePath);
+ strcat(newpath, ext);
+ rpmError(RPMMESS_BACKUP, _("warning: %s saved as %s"),
+ files[i].relativePath, newpath);
+
+ if (rename(files[i].relativePath, newpath)) {
+ rpmError(RPMERR_RENAME, _("rename of %s to %s failed: %s"),
+ files[i].relativePath, newpath, strerror(errno));
+ if (freeFileMem) freeFileMemory(fileMem);
+
+ if (rootdir) {
+ chroot(".");
+ chdir(currDir);
+ }
+
+ return 2;
+ }
+ }
+
+ if (!installFile) {
+ files[i].install = 0;
+ }
+ }
+
+ if (!headerGetEntry(h, RPMTAG_ARCHIVESIZE, &type,
+ (void **) &archiveSizePtr, &count))
+ archiveSizePtr = NULL;
+
+ if (notify) {
+ notify(h, RPMCALLBACK_INST_START, 0, 0, pkgKey, notifyData);
+ }
+
+ /* the file pointer for fd is pointing at the cpio archive */
+ if (installArchive(fd, files, fileCount, notify, notifyData, pkgKey, h,
+ NULL, archiveSizePtr ? *archiveSizePtr : 0)) {
+ headerFree(h);
+ if (freeFileMem) freeFileMemory(fileMem);
+
+ if (rootdir) {
+ chroot(".");
+ chdir(currDir);
+ }
+
+ return 2;
+ }
+
+ fileStates = malloc(sizeof(*fileStates) * fileCount);
+ for (i = 0; i < fileCount; i++)
+ fileStates[i] = files[i].state;
+
+ headerAddEntry(h, RPMTAG_FILESTATES, RPM_CHAR_TYPE, fileStates,
+ fileCount);
+
+ free(fileStates);
+ if (freeFileMem) freeFileMemory(fileMem);
+ } else if (flags & RPMTRANS_FLAG_JUSTDB) {
+ if (headerGetEntry(h, RPMTAG_FILENAMES, NULL, NULL, &fileCount)) {
+ fileStates = malloc(sizeof(*fileStates) * fileCount);
+ memset(fileStates, RPMFILE_STATE_NORMAL, fileCount);
+ headerAddEntry(h, RPMTAG_FILESTATES, RPM_CHAR_TYPE, fileStates,
+ fileCount);
+ free(fileStates);
+ }
+ }
+
+ installTime = time(NULL);
+ headerAddEntry(h, RPMTAG_INSTALLTIME, RPM_INT32_TYPE, &installTime, 1);
+
+ if (rootdir) {
+ chroot(".");
+ chdir(currDir);
+ }
+
+ trimChangelog(h);
+
+ /* if this package has already been installed, remove it from the database
+ before adding the new one */
+ if (otherOffset) {
+ rpmdbRemove(db, otherOffset, 1);
+ }
+
+ if (rpmdbAdd(db, h)) {
+ headerFree(h);
+ return 2;
+ }
+
+ rpmMessage(RPMMESS_DEBUG, _("running postinstall script (if any)\n"));
+
+ if (runInstScript(rootdir, h, RPMTAG_POSTIN, RPMTAG_POSTINPROG, scriptArg,
+ flags & RPMTRANS_FLAG_NOSCRIPTS, scriptFd)) {
+ return 2;
+ }
+
+ if (!(flags & RPMTRANS_FLAG_NOTRIGGERS)) {
+ /* Run triggers this package sets off */
+ if (runTriggers(rootdir, db, RPMSENSE_TRIGGERIN, h, 0, scriptFd)) {
+ return 2;
+ }
+
+ /* Run triggers in this package which are set off by other things in
+ the database. */
+ if (runImmedTriggers(rootdir, db, RPMSENSE_TRIGGERIN, h, 0, scriptFd)) {
+ return 2;
+ }
+ }
+
+ if (sharedList)
+ markReplacedFiles(db, sharedList);
+
+ return 0;
+}