1997-01-18 00:20:18 +08:00
|
|
|
#include "config.h"
|
1997-05-20 23:57:39 +08:00
|
|
|
#include "miscfn.h"
|
1997-01-18 00:20:18 +08:00
|
|
|
|
|
|
|
#if HAVE_ALLOCA_H
|
1996-09-26 03:15:49 +08:00
|
|
|
# include <alloca.h>
|
|
|
|
#endif
|
|
|
|
|
1996-01-09 04:21:22 +08:00
|
|
|
#include <errno.h>
|
1996-01-09 03:19:53 +08:00
|
|
|
#include <fcntl.h>
|
1996-01-06 02:12:55 +08:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
1997-05-21 01:43:34 +08:00
|
|
|
#include <sys/time.h>
|
1997-05-16 23:32:57 +08:00
|
|
|
#include <sys/resource.h>
|
1996-01-09 04:21:22 +08:00
|
|
|
#include <sys/stat.h>
|
1996-01-09 03:19:53 +08:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/wait.h>
|
|
|
|
#include <unistd.h>
|
1996-01-06 02:12:55 +08:00
|
|
|
|
1996-01-09 03:19:53 +08:00
|
|
|
#include "install.h"
|
1997-05-01 23:15:11 +08:00
|
|
|
#include "intl.h"
|
1996-01-09 03:19:53 +08:00
|
|
|
#include "messages.h"
|
1996-01-09 04:21:22 +08:00
|
|
|
#include "md5.h"
|
1996-01-09 03:19:53 +08:00
|
|
|
#include "misc.h"
|
1996-09-17 06:28:56 +08:00
|
|
|
#include "rpmdb.h"
|
1996-01-06 02:12:55 +08:00
|
|
|
#include "rpmlib.h"
|
|
|
|
|
1996-05-23 03:30:04 +08:00
|
|
|
static char * SCRIPT_PATH = "PATH=/sbin:/bin:/usr/sbin:/usr/bin:"
|
|
|
|
"/usr/X11R6/bin\nexport PATH\n";
|
1996-03-01 09:59:03 +08:00
|
|
|
|
1996-01-09 03:19:53 +08:00
|
|
|
enum fileActions { REMOVE, BACKUP, KEEP };
|
|
|
|
|
|
|
|
static int sharedFileCmp(const void * one, const void * two);
|
|
|
|
static int handleSharedFiles(rpmdb db, int offset, char ** fileList,
|
|
|
|
char ** fileMd5List, int fileCount,
|
|
|
|
enum fileActions * fileActions);
|
|
|
|
static int removeFile(char * file, char state, unsigned int flags, char * md5,
|
1996-01-09 04:21:22 +08:00
|
|
|
short mode, enum fileActions action, char * rmmess,
|
1996-09-01 02:36:28 +08:00
|
|
|
int brokenMd5, int test);
|
1996-01-09 03:19:53 +08:00
|
|
|
|
|
|
|
static int sharedFileCmp(const void * one, const void * two) {
|
1996-02-20 08:12:50 +08:00
|
|
|
if (((struct sharedFile *) one)->secRecOffset <
|
|
|
|
((struct sharedFile *) two)->secRecOffset)
|
1996-01-09 03:19:53 +08:00
|
|
|
return -1;
|
1996-02-20 08:12:50 +08:00
|
|
|
else if (((struct sharedFile *) one)->secRecOffset ==
|
|
|
|
((struct sharedFile *) two)->secRecOffset)
|
1996-01-09 03:19:53 +08:00
|
|
|
return 0;
|
|
|
|
else
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int findSharedFiles(rpmdb db, int offset, char ** fileList, int fileCount,
|
|
|
|
struct sharedFile ** listPtr, int * listCountPtr) {
|
|
|
|
int i, j;
|
|
|
|
struct sharedFile * list = NULL;
|
|
|
|
int itemsUsed = 0;
|
|
|
|
int itemsAllocated = 0;
|
1996-11-19 02:02:36 +08:00
|
|
|
dbiIndexSet matches;
|
1996-01-09 03:19:53 +08:00
|
|
|
|
|
|
|
itemsAllocated = 5;
|
|
|
|
list = malloc(sizeof(struct sharedFile) * itemsAllocated);
|
|
|
|
|
|
|
|
for (i = 0; i < fileCount; i++) {
|
|
|
|
if (!rpmdbFindByFile(db, fileList[i], &matches)) {
|
|
|
|
for (j = 0; j < matches.count; j++) {
|
|
|
|
if (matches.recs[j].recOffset != offset) {
|
|
|
|
if (itemsUsed == itemsAllocated) {
|
|
|
|
itemsAllocated += 10;
|
|
|
|
list = realloc(list, sizeof(struct sharedFile) *
|
|
|
|
itemsAllocated);
|
|
|
|
}
|
|
|
|
list[itemsUsed].mainFileNumber = i;
|
|
|
|
list[itemsUsed].secRecOffset = matches.recs[j].recOffset;
|
|
|
|
list[itemsUsed].secFileNumber = matches.recs[j].fileNumber;
|
|
|
|
itemsUsed++;
|
|
|
|
}
|
|
|
|
}
|
1996-10-21 09:24:25 +08:00
|
|
|
|
1996-11-19 02:02:36 +08:00
|
|
|
dbiFreeIndexRecord(matches);
|
1996-01-09 03:19:53 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1996-10-21 09:24:25 +08:00
|
|
|
if (itemsUsed) {
|
|
|
|
qsort(list, itemsUsed, sizeof(struct sharedFile), sharedFileCmp);
|
|
|
|
*listPtr = list;
|
|
|
|
*listCountPtr = itemsUsed;
|
|
|
|
} else {
|
|
|
|
free(list);
|
|
|
|
*listPtr = NULL;
|
|
|
|
*listCountPtr = 0;
|
|
|
|
}
|
1996-01-09 03:19:53 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int handleSharedFiles(rpmdb db, int offset, char ** fileList,
|
|
|
|
char ** fileMd5List, int fileCount,
|
|
|
|
enum fileActions * fileActions) {
|
1996-02-20 08:12:50 +08:00
|
|
|
Header sech = NULL;
|
1996-01-09 03:19:53 +08:00
|
|
|
int secOffset = 0;
|
|
|
|
struct sharedFile * sharedList;
|
|
|
|
int sharedCount;
|
|
|
|
char * name, * version, * release;
|
|
|
|
int secFileCount;
|
|
|
|
char ** secFileMd5List, ** secFileList;
|
|
|
|
char * secFileStatesList;
|
|
|
|
int type;
|
|
|
|
int i;
|
|
|
|
int rc = 0;
|
|
|
|
|
|
|
|
if (findSharedFiles(db, offset, fileList, fileCount, &sharedList,
|
|
|
|
&sharedCount)) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!sharedCount) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < sharedCount; i++) {
|
|
|
|
if (secOffset != sharedList[i].secRecOffset) {
|
|
|
|
if (secOffset) {
|
1996-11-19 02:02:36 +08:00
|
|
|
headerFree(sech);
|
1996-01-09 03:19:53 +08:00
|
|
|
free(secFileMd5List);
|
|
|
|
free(secFileList);
|
|
|
|
}
|
|
|
|
|
|
|
|
secOffset = sharedList[i].secRecOffset;
|
|
|
|
sech = rpmdbGetRecord(db, secOffset);
|
|
|
|
if (!sech) {
|
1997-05-01 23:15:11 +08:00
|
|
|
rpmError(RPMERR_DBCORRUPT,
|
|
|
|
_("cannot read header at %d for uninstall"), offset);
|
1996-01-09 03:19:53 +08:00
|
|
|
rc = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
1996-11-19 02:02:36 +08:00
|
|
|
headerGetEntry(sech, RPMTAG_NAME, &type, (void **) &name,
|
1996-01-09 03:19:53 +08:00
|
|
|
&secFileCount);
|
1996-11-19 02:02:36 +08:00
|
|
|
headerGetEntry(sech, RPMTAG_VERSION, &type, (void **) &version,
|
1996-01-09 03:19:53 +08:00
|
|
|
&secFileCount);
|
1996-11-19 02:02:36 +08:00
|
|
|
headerGetEntry(sech, RPMTAG_RELEASE, &type, (void **) &release,
|
1996-01-09 03:19:53 +08:00
|
|
|
&secFileCount);
|
|
|
|
|
1997-05-01 23:15:11 +08:00
|
|
|
rpmMessage(RPMMESS_DEBUG,
|
|
|
|
_("package %s-%s-%s contain shared files\n"),
|
|
|
|
name, version, release);
|
1996-01-09 03:19:53 +08:00
|
|
|
|
1996-11-19 02:02:36 +08:00
|
|
|
if (!headerGetEntry(sech, RPMTAG_FILENAMES, &type,
|
1996-01-09 03:19:53 +08:00
|
|
|
(void **) &secFileList, &secFileCount)) {
|
1996-11-19 02:02:36 +08:00
|
|
|
rpmError(RPMERR_DBCORRUPT, "package %s contains no files",
|
1996-01-09 03:19:53 +08:00
|
|
|
name);
|
1996-11-19 02:02:36 +08:00
|
|
|
headerFree(sech);
|
1996-01-09 03:19:53 +08:00
|
|
|
rc = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
1996-11-19 02:02:36 +08:00
|
|
|
headerGetEntry(sech, RPMTAG_FILESTATES, &type,
|
1996-01-09 03:19:53 +08:00
|
|
|
(void **) &secFileStatesList, &secFileCount);
|
1996-11-19 02:02:36 +08:00
|
|
|
headerGetEntry(sech, RPMTAG_FILEMD5S, &type,
|
1996-01-09 03:19:53 +08:00
|
|
|
(void **) &secFileMd5List, &secFileCount);
|
|
|
|
}
|
|
|
|
|
1996-11-19 02:02:36 +08:00
|
|
|
rpmMessage(RPMMESS_DEBUG, "file %s is shared\n",
|
1996-01-09 03:19:53 +08:00
|
|
|
fileList[sharedList[i].mainFileNumber]);
|
|
|
|
|
|
|
|
switch (secFileStatesList[sharedList[i].secFileNumber]) {
|
|
|
|
case RPMFILE_STATE_REPLACED:
|
1996-11-19 02:02:36 +08:00
|
|
|
rpmMessage(RPMMESS_DEBUG, " file has already been replaced\n");
|
1996-01-09 03:19:53 +08:00
|
|
|
break;
|
1996-03-30 04:51:20 +08:00
|
|
|
|
|
|
|
case RPMFILE_STATE_NOTINSTALLED:
|
1996-11-19 02:02:36 +08:00
|
|
|
rpmMessage(RPMMESS_DEBUG, " file was never installed\n");
|
1996-03-30 04:51:20 +08:00
|
|
|
break;
|
1996-01-09 03:19:53 +08:00
|
|
|
|
1996-10-21 10:19:37 +08:00
|
|
|
case RPMFILE_STATE_NETSHARED:
|
1996-11-19 02:02:36 +08:00
|
|
|
rpmMessage(RPMMESS_DEBUG, " file is netshared (so don't touch it)\n");
|
1996-10-21 10:19:37 +08:00
|
|
|
fileActions[sharedList[i].mainFileNumber] = KEEP;
|
|
|
|
break;
|
|
|
|
|
1996-01-09 03:19:53 +08:00
|
|
|
case RPMFILE_STATE_NORMAL:
|
|
|
|
if (!strcmp(fileMd5List[sharedList[i].mainFileNumber],
|
|
|
|
secFileMd5List[sharedList[i].secFileNumber])) {
|
1996-11-19 02:02:36 +08:00
|
|
|
rpmMessage(RPMMESS_DEBUG, " file is truely shared - saving\n");
|
1996-01-09 03:19:53 +08:00
|
|
|
}
|
|
|
|
fileActions[sharedList[i].mainFileNumber] = KEEP;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1996-01-23 05:13:55 +08:00
|
|
|
if (secOffset) {
|
1996-11-19 02:02:36 +08:00
|
|
|
headerFree(sech);
|
1996-01-23 05:13:55 +08:00
|
|
|
free(secFileMd5List);
|
|
|
|
free(secFileList);
|
|
|
|
}
|
1996-01-09 03:19:53 +08:00
|
|
|
free(sharedList);
|
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
1996-06-28 22:37:45 +08:00
|
|
|
int rpmRemovePackage(char * prefix, rpmdb db, unsigned int offset, int flags) {
|
1996-01-06 02:12:55 +08:00
|
|
|
Header h;
|
|
|
|
int i;
|
1996-01-09 03:19:53 +08:00
|
|
|
int fileCount;
|
1996-07-17 04:22:09 +08:00
|
|
|
char * rmmess, * name, * version, * release;
|
1996-01-06 02:12:55 +08:00
|
|
|
char * fnbuffer = NULL;
|
1996-11-19 02:02:36 +08:00
|
|
|
dbiIndexSet matches;
|
1996-01-06 02:12:55 +08:00
|
|
|
int fnbuffersize = 0;
|
|
|
|
int prefixLength = strlen(prefix);
|
1996-01-09 03:19:53 +08:00
|
|
|
char ** fileList, ** fileMd5List;
|
1996-06-28 22:37:45 +08:00
|
|
|
int type, count;
|
1996-01-09 03:19:53 +08:00
|
|
|
uint_32 * fileFlagsList;
|
1996-01-09 04:21:22 +08:00
|
|
|
int_16 * fileModesList;
|
1996-01-06 02:12:55 +08:00
|
|
|
char * fileStatesList;
|
1996-01-09 03:19:53 +08:00
|
|
|
enum { REMOVE, BACKUP, KEEP } * fileActions;
|
1996-06-28 22:37:45 +08:00
|
|
|
int scriptArg;
|
1996-01-06 02:12:55 +08:00
|
|
|
|
|
|
|
h = rpmdbGetRecord(db, offset);
|
|
|
|
if (!h) {
|
1996-11-19 02:02:36 +08:00
|
|
|
rpmError(RPMERR_DBCORRUPT, "cannot read header at %d for uninstall",
|
1996-01-06 02:12:55 +08:00
|
|
|
offset);
|
1996-01-09 03:19:53 +08:00
|
|
|
return 1;
|
1996-01-06 02:12:55 +08:00
|
|
|
}
|
|
|
|
|
1996-11-19 02:02:36 +08:00
|
|
|
headerGetEntry(h, RPMTAG_NAME, &type, (void **) &name, &count);
|
|
|
|
headerGetEntry(h, RPMTAG_VERSION, &type, (void **) &version, &count);
|
|
|
|
headerGetEntry(h, RPMTAG_RELEASE, &type, (void **) &release, &count);
|
1996-06-28 22:37:45 +08:00
|
|
|
/* when we run scripts, we pass an argument which is the number of
|
|
|
|
versions of this package that will be installed when we are finished */
|
|
|
|
if (rpmdbFindPackage(db, name, &matches)) {
|
1996-11-19 02:02:36 +08:00
|
|
|
rpmError(RPMERR_DBCORRUPT, "cannot read packages named %s for uninstall",
|
1996-06-28 22:37:45 +08:00
|
|
|
name);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
scriptArg = matches.count - 1;
|
1996-11-19 02:02:36 +08:00
|
|
|
dbiFreeIndexRecord(matches);
|
1996-01-06 02:12:55 +08:00
|
|
|
|
1996-11-19 02:02:36 +08:00
|
|
|
if (flags & RPMUNINSTALL_TEST) {
|
1996-01-06 02:12:55 +08:00
|
|
|
rmmess = "would remove";
|
|
|
|
} else {
|
|
|
|
rmmess = "removing";
|
|
|
|
}
|
1996-01-09 03:19:53 +08:00
|
|
|
|
1996-11-19 02:02:36 +08:00
|
|
|
rpmMessage(RPMMESS_DEBUG, "running preuninstall script (if any)\n");
|
1996-11-01 05:07:30 +08:00
|
|
|
|
|
|
|
if (runScript(prefix, h, RPMTAG_PREUN, scriptArg,
|
1996-11-19 02:02:36 +08:00
|
|
|
flags & RPMUNINSTALL_NOSCRIPTS)) {
|
|
|
|
headerFree(h);
|
1996-11-01 05:07:30 +08:00
|
|
|
return 1;
|
|
|
|
}
|
1996-01-06 02:12:55 +08:00
|
|
|
|
1996-11-19 02:02:36 +08:00
|
|
|
rpmMessage(RPMMESS_DEBUG, "%s files test = %d\n", rmmess, flags & RPMUNINSTALL_TEST);
|
|
|
|
if (headerGetEntry(h, RPMTAG_FILENAMES, &type, (void **) &fileList,
|
1996-01-09 03:19:53 +08:00
|
|
|
&fileCount)) {
|
1996-01-06 02:12:55 +08:00
|
|
|
if (prefix[0]) {
|
|
|
|
fnbuffersize = 1024;
|
|
|
|
fnbuffer = alloca(fnbuffersize);
|
|
|
|
}
|
|
|
|
|
1996-11-19 02:02:36 +08:00
|
|
|
headerGetEntry(h, RPMTAG_FILESTATES, &type, (void **) &fileStatesList,
|
1996-01-09 03:19:53 +08:00
|
|
|
&fileCount);
|
1996-11-19 02:02:36 +08:00
|
|
|
headerGetEntry(h, RPMTAG_FILEMD5S, &type, (void **) &fileMd5List,
|
1996-01-09 03:19:53 +08:00
|
|
|
&fileCount);
|
1996-11-19 02:02:36 +08:00
|
|
|
headerGetEntry(h, RPMTAG_FILEFLAGS, &type, (void **) &fileFlagsList,
|
1996-01-09 03:19:53 +08:00
|
|
|
&fileCount);
|
1996-11-19 02:02:36 +08:00
|
|
|
headerGetEntry(h, RPMTAG_FILEMODES, &type, (void **) &fileModesList,
|
1996-01-09 04:21:22 +08:00
|
|
|
&fileCount);
|
1996-01-09 03:19:53 +08:00
|
|
|
|
1996-03-30 04:51:20 +08:00
|
|
|
fileActions = alloca(sizeof(*fileActions) * fileCount);
|
|
|
|
for (i = 0; i < fileCount; i++)
|
1996-10-21 10:19:37 +08:00
|
|
|
if (fileStatesList[i] == RPMFILE_STATE_NOTINSTALLED ||
|
|
|
|
fileStatesList[i] == RPMFILE_STATE_NETSHARED)
|
1996-03-30 04:51:20 +08:00
|
|
|
fileActions[i] = KEEP;
|
|
|
|
else
|
|
|
|
fileActions[i] = REMOVE;
|
|
|
|
|
1996-01-09 03:19:53 +08:00
|
|
|
handleSharedFiles(db, offset, fileList, fileMd5List, fileCount, fileActions);
|
|
|
|
|
1996-01-30 03:37:28 +08:00
|
|
|
/* go through the filelist backwards to help insure that rmdir()
|
|
|
|
will work */
|
|
|
|
for (i = fileCount - 1; i >= 0; i--) {
|
1996-01-09 05:28:20 +08:00
|
|
|
if (strcmp(prefix, "/")) {
|
1996-01-06 02:12:55 +08:00
|
|
|
if ((strlen(fileList[i]) + prefixLength + 1) > fnbuffersize) {
|
|
|
|
fnbuffersize = (strlen(fileList[i]) + prefixLength) * 2;
|
|
|
|
fnbuffer = alloca(fnbuffersize);
|
|
|
|
}
|
1996-01-09 05:28:20 +08:00
|
|
|
strcpy(fnbuffer, prefix);
|
1996-01-06 02:12:55 +08:00
|
|
|
strcat(fnbuffer, "/");
|
1996-01-09 05:28:20 +08:00
|
|
|
strcat(fnbuffer, fileList[i]);
|
1996-01-06 02:12:55 +08:00
|
|
|
} else {
|
|
|
|
fnbuffer = fileList[i];
|
|
|
|
}
|
|
|
|
|
1996-01-09 03:19:53 +08:00
|
|
|
removeFile(fnbuffer, fileStatesList[i], fileFlagsList[i],
|
1996-01-09 04:21:22 +08:00
|
|
|
fileMd5List[i], fileModesList[i], fileActions[i],
|
1996-11-19 02:02:36 +08:00
|
|
|
rmmess, !headerIsEntry(h, RPMTAG_RPMVERSION),
|
|
|
|
flags & RPMUNINSTALL_TEST);
|
1996-01-06 02:12:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
free(fileList);
|
1996-01-09 03:19:53 +08:00
|
|
|
free(fileMd5List);
|
1996-01-06 02:12:55 +08:00
|
|
|
}
|
|
|
|
|
1996-11-19 02:02:36 +08:00
|
|
|
rpmMessage(RPMMESS_DEBUG, "running postuninstall script (if any)\n");
|
|
|
|
runScript(prefix, h, RPMTAG_POSTUN, scriptArg, flags & RPMUNINSTALL_NOSCRIPTS);
|
1996-01-09 03:19:53 +08:00
|
|
|
|
1996-11-19 02:02:36 +08:00
|
|
|
headerFree(h);
|
1996-01-09 03:19:53 +08:00
|
|
|
|
1996-11-19 02:02:36 +08:00
|
|
|
rpmMessage(RPMMESS_DEBUG, "%s database entry\n", rmmess);
|
|
|
|
if (!(flags & RPMUNINSTALL_TEST))
|
1996-01-06 02:12:55 +08:00
|
|
|
rpmdbRemove(db, offset, 0);
|
|
|
|
|
1996-01-09 03:19:53 +08:00
|
|
|
return 0;
|
1996-01-06 02:12:55 +08:00
|
|
|
}
|
|
|
|
|
1996-06-28 22:37:45 +08:00
|
|
|
int runScript(char * prefix, Header h, int tag, int arg, int norunScripts) {
|
1996-01-09 03:19:53 +08:00
|
|
|
int count, type;
|
|
|
|
char * script;
|
|
|
|
char * fn;
|
|
|
|
int fd;
|
1996-11-19 02:02:36 +08:00
|
|
|
int isdebug = rpmIsDebug();
|
1996-01-09 03:19:53 +08:00
|
|
|
int child;
|
|
|
|
int status;
|
1996-06-28 22:37:45 +08:00
|
|
|
char upgradeArg[20];
|
1996-07-10 22:11:04 +08:00
|
|
|
char * installPrefix = NULL;
|
|
|
|
char * installPrefixEnv = NULL;
|
1996-05-23 03:30:04 +08:00
|
|
|
|
1996-06-28 22:37:45 +08:00
|
|
|
sprintf(upgradeArg, "%d", arg);
|
1996-01-09 03:19:53 +08:00
|
|
|
|
1996-05-07 09:49:06 +08:00
|
|
|
if (norunScripts) return 0;
|
1996-07-10 22:11:04 +08:00
|
|
|
|
1996-11-19 02:02:36 +08:00
|
|
|
if (headerGetEntry(h, tag, &type, (void **) &script, &count)) {
|
|
|
|
if (headerGetEntry(h, RPMTAG_INSTALLPREFIX, &type, (void **) &installPrefix,
|
1996-07-10 22:11:04 +08:00
|
|
|
&count)) {
|
|
|
|
installPrefixEnv = alloca(strlen(installPrefix) + 30);
|
|
|
|
strcpy(installPrefixEnv, "RPM_INSTALL_PREFIX=");
|
|
|
|
strcat(installPrefixEnv, installPrefix);
|
|
|
|
}
|
|
|
|
|
1996-01-09 03:19:53 +08:00
|
|
|
fn = tmpnam(NULL);
|
1996-11-19 02:02:36 +08:00
|
|
|
rpmMessage(RPMMESS_DEBUG, "script found - running from file %s\n", fn);
|
1996-01-09 03:19:53 +08:00
|
|
|
fd = open(fn, O_CREAT | O_RDWR);
|
1997-02-12 13:05:58 +08:00
|
|
|
if (!isdebug) unlink(fn);
|
1996-01-09 03:19:53 +08:00
|
|
|
if (fd < 0) {
|
1997-05-01 23:15:11 +08:00
|
|
|
rpmError(RPMERR_SCRIPT,
|
|
|
|
_("error creating file for (un)install script"));
|
1996-01-09 03:19:53 +08:00
|
|
|
return 1;
|
|
|
|
}
|
1996-03-01 09:59:03 +08:00
|
|
|
write(fd, SCRIPT_PATH, strlen(SCRIPT_PATH));
|
1996-01-09 03:19:53 +08:00
|
|
|
write(fd, script, strlen(script));
|
|
|
|
|
|
|
|
/* run the script via /bin/sh - just feed the commands to the
|
|
|
|
shell as stdin */
|
1996-07-10 22:11:04 +08:00
|
|
|
if (!(child = fork())) {
|
|
|
|
if (installPrefixEnv) {
|
1996-12-24 22:02:21 +08:00
|
|
|
doputenv(installPrefixEnv);
|
1996-07-10 22:11:04 +08:00
|
|
|
}
|
|
|
|
|
1996-01-09 03:19:53 +08:00
|
|
|
lseek(fd, 0, SEEK_SET);
|
|
|
|
close(0);
|
|
|
|
dup2(fd, 0);
|
|
|
|
close(fd);
|
|
|
|
|
|
|
|
if (strcmp(prefix, "/")) {
|
1996-11-19 02:02:36 +08:00
|
|
|
rpmMessage(RPMMESS_DEBUG, "performing chroot(%s)\n", prefix);
|
1996-01-09 03:19:53 +08:00
|
|
|
chroot(prefix);
|
1996-01-09 05:28:20 +08:00
|
|
|
chdir("/");
|
1996-01-09 03:19:53 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (isdebug)
|
1997-02-12 13:05:58 +08:00
|
|
|
execl("/bin/sh", "/bin/sh", "-xs", upgradeArg, NULL);
|
1996-01-09 03:19:53 +08:00
|
|
|
else
|
1996-05-23 03:30:04 +08:00
|
|
|
execl("/bin/sh", "/bin/sh", "-s", upgradeArg, NULL);
|
1996-12-12 11:35:01 +08:00
|
|
|
_exit(-1);
|
1996-01-09 03:19:53 +08:00
|
|
|
}
|
|
|
|
close(fd);
|
|
|
|
waitpid(child, &status, 0);
|
|
|
|
|
|
|
|
if (!WIFEXITED(status) || WEXITSTATUS(status)) {
|
1997-05-01 23:15:11 +08:00
|
|
|
rpmError(RPMERR_SCRIPT, _("execution of script failed"));
|
1996-01-09 03:19:53 +08:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int removeFile(char * file, char state, unsigned int flags, char * md5,
|
1996-01-09 04:21:22 +08:00
|
|
|
short mode, enum fileActions action, char * rmmess,
|
1996-09-01 02:36:28 +08:00
|
|
|
int brokenMd5, int test) {
|
1996-01-09 04:21:22 +08:00
|
|
|
char currentMd5[40];
|
|
|
|
int rc = 0;
|
|
|
|
char * newfile;
|
1996-01-09 03:19:53 +08:00
|
|
|
|
|
|
|
switch (state) {
|
|
|
|
case RPMFILE_STATE_REPLACED:
|
1996-11-19 02:02:36 +08:00
|
|
|
rpmMessage(RPMMESS_DEBUG, "%s has already been replaced\n", file);
|
1996-01-09 03:19:53 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case RPMFILE_STATE_NORMAL:
|
1996-01-09 04:21:22 +08:00
|
|
|
if ((action == REMOVE) && (flags & RPMFILE_CONFIG)) {
|
|
|
|
/* if it's a config file, we may not want to remove it */
|
1996-11-19 02:02:36 +08:00
|
|
|
rpmMessage(RPMMESS_DEBUG, "finding md5sum of %s\n", file);
|
1996-09-01 02:36:28 +08:00
|
|
|
if (brokenMd5)
|
|
|
|
rc = mdfileBroken(file, currentMd5);
|
|
|
|
else
|
|
|
|
rc = mdfile(file, currentMd5);
|
|
|
|
|
1996-01-09 04:21:22 +08:00
|
|
|
if (mdfile(file, currentMd5))
|
1997-05-01 23:15:11 +08:00
|
|
|
rpmMessage(RPMMESS_DEBUG,
|
|
|
|
" failed - assuming file removed\n");
|
1996-01-09 04:21:22 +08:00
|
|
|
else {
|
|
|
|
if (strcmp(currentMd5, md5)) {
|
1996-11-19 02:02:36 +08:00
|
|
|
rpmMessage(RPMMESS_DEBUG, " file changed - will save\n");
|
1996-01-09 04:21:22 +08:00
|
|
|
action = BACKUP;
|
|
|
|
} else {
|
1997-05-01 23:15:11 +08:00
|
|
|
rpmMessage(RPMMESS_DEBUG,
|
|
|
|
" file unchanged - will remove\n");
|
1996-01-09 04:21:22 +08:00
|
|
|
}
|
|
|
|
}
|
1996-01-09 03:19:53 +08:00
|
|
|
}
|
|
|
|
|
1996-01-09 04:21:22 +08:00
|
|
|
switch (action) {
|
|
|
|
|
|
|
|
case KEEP:
|
1996-11-19 02:02:36 +08:00
|
|
|
rpmMessage(RPMMESS_DEBUG, "keeping %s\n", file);
|
1996-02-16 05:08:09 +08:00
|
|
|
break;
|
1996-01-09 04:21:22 +08:00
|
|
|
|
|
|
|
case BACKUP:
|
1996-11-19 02:02:36 +08:00
|
|
|
rpmMessage(RPMMESS_DEBUG, "saving %s as %s.rpmsave\n", file, file);
|
1996-01-09 04:21:22 +08:00
|
|
|
if (!test) {
|
|
|
|
newfile = alloca(strlen(file) + 20);
|
|
|
|
strcpy(newfile, file);
|
|
|
|
strcat(newfile, ".rpmsave");
|
|
|
|
if (rename(file, newfile)) {
|
1997-05-01 23:15:11 +08:00
|
|
|
rpmError(RPMERR_RENAME, _("rename of %s to %s failed: %s"),
|
1996-01-09 04:21:22 +08:00
|
|
|
file, newfile, strerror(errno));
|
|
|
|
rc = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case REMOVE:
|
1996-11-19 02:02:36 +08:00
|
|
|
rpmMessage(RPMMESS_DEBUG, "%s - %s\n", file, rmmess);
|
1996-01-09 04:21:22 +08:00
|
|
|
if (S_ISDIR(mode)) {
|
|
|
|
if (!test) {
|
|
|
|
if (rmdir(file)) {
|
|
|
|
if (errno == ENOTEMPTY)
|
1997-05-01 23:15:11 +08:00
|
|
|
rpmError(RPMERR_RMDIR,
|
|
|
|
_("cannot remove %s - directory not empty"),
|
|
|
|
file);
|
1996-01-09 04:21:22 +08:00
|
|
|
else
|
1997-05-01 23:15:11 +08:00
|
|
|
rpmError(RPMERR_RMDIR, _("rmdir of %s failed: %s"),
|
1996-01-09 04:21:22 +08:00
|
|
|
file, strerror(errno));
|
|
|
|
rc = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (!test) {
|
|
|
|
if (unlink(file)) {
|
1997-05-01 23:15:11 +08:00
|
|
|
rpmError(RPMERR_UNLINK, _("removal of %s failed: %s"),
|
1996-01-09 04:21:22 +08:00
|
|
|
file, strerror(errno));
|
|
|
|
rc = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
1996-01-09 03:19:53 +08:00
|
|
|
}
|