1997-01-18 00:20:18 +08:00
|
|
|
#include "config.h"
|
|
|
|
|
1996-01-06 02:12:55 +08:00
|
|
|
#include <fcntl.h>
|
1996-01-23 05:12:55 +08:00
|
|
|
#include <stdio.h>
|
1996-06-11 01:41:24 +08:00
|
|
|
#include <stdlib.h>
|
1996-01-23 05:12:55 +08:00
|
|
|
#include <string.h>
|
1996-01-09 03:21:55 +08:00
|
|
|
#include <unistd.h>
|
1996-01-06 02:12:55 +08:00
|
|
|
|
1997-01-18 00:20:18 +08:00
|
|
|
#if HAVE_ALLOCA_H
|
1996-12-12 11:32:22 +08:00
|
|
|
# include <alloca.h>
|
|
|
|
#endif
|
|
|
|
|
1997-05-01 05:30:55 +08:00
|
|
|
#include "miscfn.h"
|
1996-01-06 02:12:55 +08:00
|
|
|
#include "install.h"
|
1997-04-29 10:45:19 +08:00
|
|
|
#include "intl.h"
|
1996-01-06 02:12:55 +08:00
|
|
|
#include "lib/rpmlib.h"
|
1996-01-09 03:21:55 +08:00
|
|
|
#include "messages.h"
|
1996-02-15 04:56:22 +08:00
|
|
|
#include "query.h"
|
1996-10-15 11:14:35 +08:00
|
|
|
#include "url.h"
|
1996-01-06 02:12:55 +08:00
|
|
|
|
1996-01-23 05:12:55 +08:00
|
|
|
static int hashesPrinted = 0;
|
|
|
|
|
|
|
|
static void printHash(const unsigned long amount, const unsigned long total);
|
|
|
|
static void printPercent(const unsigned long amount, const unsigned long total);
|
1996-07-11 00:28:50 +08:00
|
|
|
static void printDepProblems(FILE * f, struct rpmDependencyConflict * conflicts,
|
|
|
|
int numConflicts);
|
1996-01-23 05:12:55 +08:00
|
|
|
|
|
|
|
static void printHash(const unsigned long amount, const unsigned long total) {
|
|
|
|
int hashesNeeded;
|
|
|
|
|
|
|
|
if (hashesPrinted != 50) {
|
1996-03-13 11:51:56 +08:00
|
|
|
hashesNeeded = 50 * (total ? (((float) amount) / total) : 1);
|
1996-01-23 05:12:55 +08:00
|
|
|
while (hashesNeeded > hashesPrinted) {
|
|
|
|
printf("#");
|
|
|
|
hashesPrinted++;
|
|
|
|
}
|
|
|
|
fflush(stdout);
|
|
|
|
hashesPrinted = hashesNeeded;
|
|
|
|
|
|
|
|
if (hashesPrinted == 50)
|
|
|
|
printf("\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void printPercent(const unsigned long amount, const unsigned long total)
|
|
|
|
{
|
1996-03-13 11:51:56 +08:00
|
|
|
printf("%%%% %f\n", (total
|
|
|
|
? ((float) ((((float) amount) / total) * 100))
|
|
|
|
: 100.0));
|
1996-02-15 07:21:02 +08:00
|
|
|
fflush(stdout);
|
1996-01-23 05:12:55 +08:00
|
|
|
}
|
|
|
|
|
1996-07-10 10:35:15 +08:00
|
|
|
static int installPackages(char * rootdir, char ** packages, char * location,
|
1996-06-11 01:41:24 +08:00
|
|
|
int numPackages, int installFlags,
|
|
|
|
int interfaceFlags, rpmdb db) {
|
|
|
|
int i, fd;
|
|
|
|
int numFailed = 0;
|
|
|
|
char ** filename;
|
|
|
|
char * printFormat = NULL;
|
1996-01-23 05:12:55 +08:00
|
|
|
char * chptr;
|
1996-06-11 01:41:24 +08:00
|
|
|
int rc;
|
1996-11-19 02:02:36 +08:00
|
|
|
rpmNotifyFunction fn;
|
1996-10-21 10:14:02 +08:00
|
|
|
char * netsharedPath = NULL;
|
1996-01-23 05:12:55 +08:00
|
|
|
|
1996-11-19 02:02:36 +08:00
|
|
|
if (interfaceFlags & INSTALL_PERCENT)
|
1996-01-23 05:12:55 +08:00
|
|
|
fn = printPercent;
|
1996-11-19 02:02:36 +08:00
|
|
|
else if (interfaceFlags & INSTALL_HASH)
|
1996-01-23 05:12:55 +08:00
|
|
|
fn = printHash;
|
|
|
|
else
|
|
|
|
fn = NULL;
|
1996-06-11 01:41:24 +08:00
|
|
|
|
1996-11-19 02:02:36 +08:00
|
|
|
netsharedPath = rpmGetVar(RPMVAR_NETSHAREDPATH);
|
1996-10-21 10:14:02 +08:00
|
|
|
|
1996-06-11 01:41:24 +08:00
|
|
|
for (i = 0, filename = packages; i < numPackages; i++, filename++) {
|
|
|
|
if (!*filename) continue;
|
|
|
|
|
1996-07-20 06:32:36 +08:00
|
|
|
hashesPrinted = 0;
|
|
|
|
|
1996-06-11 01:41:24 +08:00
|
|
|
fd = open(*filename, O_RDONLY);
|
|
|
|
if (fd < 0) {
|
1997-04-29 10:45:19 +08:00
|
|
|
fprintf(stderr, _("error: cannot open file %s\n"), *filename);
|
1996-06-11 01:41:24 +08:00
|
|
|
numFailed++;
|
|
|
|
*filename = NULL;
|
1996-07-16 23:56:21 +08:00
|
|
|
continue;
|
|
|
|
}
|
1996-06-11 01:41:24 +08:00
|
|
|
|
1996-11-19 02:02:36 +08:00
|
|
|
if (interfaceFlags & INSTALL_PERCENT)
|
1996-06-11 01:41:24 +08:00
|
|
|
printFormat = "%%f %s:%s:%s\n";
|
1996-11-19 02:02:36 +08:00
|
|
|
else if (rpmIsVerbose() && (interfaceFlags & INSTALL_HASH)) {
|
1996-06-11 01:41:24 +08:00
|
|
|
chptr = strrchr(*filename, '/');
|
|
|
|
if (!chptr)
|
|
|
|
chptr = *filename;
|
|
|
|
else
|
|
|
|
chptr++;
|
|
|
|
|
|
|
|
printFormat = "%-28s";
|
1996-11-19 02:02:36 +08:00
|
|
|
} else if (rpmIsVerbose())
|
1997-04-29 10:45:19 +08:00
|
|
|
printf(_("Installing %s\n"), *filename);
|
1996-06-11 01:41:24 +08:00
|
|
|
|
|
|
|
if (db) {
|
1996-07-10 10:35:15 +08:00
|
|
|
rc = rpmInstallPackage(rootdir, db, fd, location, installFlags, fn,
|
1996-10-21 10:14:02 +08:00
|
|
|
printFormat, netsharedPath);
|
1996-06-11 01:41:24 +08:00
|
|
|
} else {
|
1996-11-19 02:02:36 +08:00
|
|
|
if (installFlags &= RPMINSTALL_TEST) {
|
|
|
|
rpmMessage(RPMMESS_DEBUG, "stopping source install as we're "
|
1996-06-11 01:41:24 +08:00
|
|
|
"just testing\n");
|
|
|
|
rc = 0;
|
1996-07-16 23:56:21 +08:00
|
|
|
} else {
|
1996-08-29 12:14:54 +08:00
|
|
|
rc = rpmInstallSourcePackage(rootdir, fd, NULL, fn,
|
1997-10-29 23:55:09 +08:00
|
|
|
printFormat, NULL);
|
1996-07-16 23:56:21 +08:00
|
|
|
}
|
1996-06-11 01:41:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (rc == 1) {
|
1997-04-29 10:45:19 +08:00
|
|
|
fprintf(stderr,
|
|
|
|
_("error: %s does not appear to be a RPM package\n"),
|
|
|
|
*filename);
|
1996-06-11 01:41:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (rc) {
|
1997-04-29 10:45:19 +08:00
|
|
|
fprintf(stderr, _("error: %s cannot be installed\n"), *filename);
|
1996-06-11 01:41:24 +08:00
|
|
|
numFailed++;
|
|
|
|
}
|
|
|
|
|
|
|
|
close(fd);
|
1996-01-09 03:21:55 +08:00
|
|
|
}
|
|
|
|
|
1996-06-11 01:41:24 +08:00
|
|
|
return numFailed;
|
|
|
|
}
|
|
|
|
|
1996-07-10 10:35:15 +08:00
|
|
|
int doInstall(char * rootdir, char ** argv, char * location, int installFlags,
|
1996-06-11 01:41:24 +08:00
|
|
|
int interfaceFlags) {
|
|
|
|
rpmdb db;
|
|
|
|
int fd, i;
|
|
|
|
int mode, rc;
|
|
|
|
char ** packages, ** tmpPackages;
|
|
|
|
char ** filename;
|
|
|
|
int numPackages;
|
|
|
|
int numTmpPackages = 0, numBinaryPackages = 0, numSourcePackages = 0;
|
|
|
|
int numFailed = 0;
|
|
|
|
Header * binaryHeaders;
|
|
|
|
int isSource;
|
|
|
|
int tmpnum = 0;
|
|
|
|
rpmDependencies rpmdep;
|
|
|
|
struct rpmDependencyConflict * conflicts;
|
|
|
|
int numConflicts;
|
|
|
|
int stopInstall = 0;
|
|
|
|
|
1996-11-19 02:02:36 +08:00
|
|
|
if (installFlags & RPMINSTALL_TEST)
|
1996-06-11 01:41:24 +08:00
|
|
|
mode = O_RDONLY;
|
|
|
|
else
|
1996-07-03 23:33:18 +08:00
|
|
|
mode = O_RDWR | O_CREAT;
|
1996-02-28 01:37:06 +08:00
|
|
|
|
1996-11-19 02:02:36 +08:00
|
|
|
rpmMessage(RPMMESS_DEBUG, "counting packages to install\n");
|
1996-06-11 01:41:24 +08:00
|
|
|
for (filename = argv, numPackages = 0; *filename; filename++, numPackages++)
|
|
|
|
;
|
|
|
|
|
1996-11-19 02:02:36 +08:00
|
|
|
rpmMessage(RPMMESS_DEBUG, "found %d packages\n", numPackages);
|
1996-06-11 01:41:24 +08:00
|
|
|
packages = alloca((numPackages + 1) * sizeof(char *));
|
|
|
|
packages[numPackages] = NULL;
|
|
|
|
tmpPackages = alloca((numPackages + 1) * sizeof(char *));
|
|
|
|
binaryHeaders = alloca((numPackages + 1) * sizeof(Header));
|
|
|
|
|
1996-11-19 02:02:36 +08:00
|
|
|
rpmMessage(RPMMESS_DEBUG, "looking for packages to download\n");
|
1996-06-11 01:41:24 +08:00
|
|
|
for (filename = argv, i = 0; *filename; filename++) {
|
1996-10-15 11:14:35 +08:00
|
|
|
if (urlIsURL(*filename)) {
|
1996-11-19 02:02:36 +08:00
|
|
|
if (rpmIsVerbose()) {
|
1997-04-29 10:45:19 +08:00
|
|
|
printf(_("Retrieving %s\n"), *filename);
|
1996-06-11 01:41:24 +08:00
|
|
|
}
|
1996-07-10 10:35:15 +08:00
|
|
|
packages[i] = alloca(strlen(*filename) + 30 + strlen(rootdir));
|
|
|
|
sprintf(packages[i], "%s/var/tmp/rpm-ftp-%d-%d.tmp", rootdir,
|
1996-09-26 03:11:30 +08:00
|
|
|
tmpnum++, (int) getpid());
|
1997-07-02 00:24:08 +08:00
|
|
|
rpmMessage(RPMMESS_DEBUG,
|
|
|
|
"getting %s as %s\n", *filename, packages[i]);
|
1996-10-15 11:14:35 +08:00
|
|
|
fd = urlGetFile(*filename, packages[i]);
|
1996-06-11 01:41:24 +08:00
|
|
|
if (fd < 0) {
|
1997-04-29 10:45:19 +08:00
|
|
|
fprintf(stderr,
|
|
|
|
_("error: skipping %s - transfer failed - %s\n"),
|
1996-06-11 01:41:24 +08:00
|
|
|
*filename, ftpStrerror(fd));
|
|
|
|
numFailed++;
|
|
|
|
} else {
|
|
|
|
tmpPackages[numTmpPackages++] = packages[i];
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
packages[i++] = *filename;
|
1996-02-28 01:37:06 +08:00
|
|
|
}
|
1996-06-11 01:41:24 +08:00
|
|
|
}
|
|
|
|
|
1996-11-19 02:02:36 +08:00
|
|
|
rpmMessage(RPMMESS_DEBUG, "retrieved %d packages\n", numTmpPackages);
|
1996-06-11 01:41:24 +08:00
|
|
|
|
1996-11-19 02:02:36 +08:00
|
|
|
rpmMessage(RPMMESS_DEBUG, "finding source and binary packages\n");
|
1996-06-11 01:41:24 +08:00
|
|
|
for (filename = packages; *filename; filename++) {
|
|
|
|
fd = open(*filename, O_RDONLY);
|
1996-02-28 01:37:06 +08:00
|
|
|
if (fd < 0) {
|
1997-04-29 10:45:19 +08:00
|
|
|
fprintf(stderr, _("error: cannot open file %s\n"), *filename);
|
1996-06-11 01:41:24 +08:00
|
|
|
numFailed++;
|
|
|
|
*filename = NULL;
|
1996-07-16 23:56:21 +08:00
|
|
|
continue;
|
1996-02-28 01:37:06 +08:00
|
|
|
}
|
1996-06-11 01:41:24 +08:00
|
|
|
|
1997-07-02 00:24:08 +08:00
|
|
|
rc = rpmReadPackageHeader(fd, &binaryHeaders[numBinaryPackages],
|
|
|
|
&isSource, NULL, NULL);
|
1996-06-11 01:41:24 +08:00
|
|
|
|
|
|
|
close(fd);
|
|
|
|
|
|
|
|
if (rc == 1) {
|
1997-04-29 10:45:19 +08:00
|
|
|
fprintf(stderr,
|
|
|
|
_("error: %s does not appear to be a RPM package\n"),
|
1996-06-11 01:41:24 +08:00
|
|
|
*filename);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (rc) {
|
1997-04-29 10:45:19 +08:00
|
|
|
fprintf(stderr, _("error: %s cannot be installed\n"), *filename);
|
1996-06-11 01:41:24 +08:00
|
|
|
numFailed++;
|
|
|
|
*filename = NULL;
|
|
|
|
} else if (isSource) {
|
1996-07-18 04:00:49 +08:00
|
|
|
/* the header will be NULL if this is a v1 source package */
|
|
|
|
if (binaryHeaders[numBinaryPackages])
|
1996-11-19 02:02:36 +08:00
|
|
|
headerFree(binaryHeaders[numBinaryPackages]);
|
1996-07-18 04:00:49 +08:00
|
|
|
|
1996-06-11 01:41:24 +08:00
|
|
|
numSourcePackages++;
|
|
|
|
} else {
|
|
|
|
numBinaryPackages++;
|
1996-02-28 01:37:06 +08:00
|
|
|
}
|
1996-01-09 03:21:55 +08:00
|
|
|
}
|
|
|
|
|
1996-11-19 02:02:36 +08:00
|
|
|
rpmMessage(RPMMESS_DEBUG, "found %d source and %d binary packages\n",
|
1996-06-11 01:41:24 +08:00
|
|
|
numSourcePackages, numBinaryPackages);
|
1996-01-23 05:12:55 +08:00
|
|
|
|
1996-06-11 01:41:24 +08:00
|
|
|
if (numBinaryPackages) {
|
1996-11-19 02:02:36 +08:00
|
|
|
rpmMessage(RPMMESS_DEBUG, "opening database mode: 0%o\n", mode);
|
1996-07-10 10:35:15 +08:00
|
|
|
if (rpmdbOpen(rootdir, &db, mode, 0644)) {
|
1998-01-06 10:45:02 +08:00
|
|
|
fprintf(stderr, _("error: cannot open %s%s/packages.rpm\n"),
|
1998-01-06 01:22:04 +08:00
|
|
|
rootdir, rpmGetVar(RPMVAR_DBPATH));
|
1996-06-11 01:41:24 +08:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
1997-07-02 00:24:08 +08:00
|
|
|
rpmdep = rpmdepDependencies(db);
|
|
|
|
for (i = 0; i < numBinaryPackages; i++)
|
|
|
|
if (installFlags & RPMINSTALL_UPGRADE)
|
|
|
|
rpmdepUpgradePackage(rpmdep, binaryHeaders[i],
|
|
|
|
packages[i]);
|
|
|
|
else
|
|
|
|
rpmdepAddPackage(rpmdep, binaryHeaders[i],
|
|
|
|
packages[i]);
|
1996-06-11 01:41:24 +08:00
|
|
|
|
1997-07-02 00:24:08 +08:00
|
|
|
if (!(interfaceFlags & INSTALL_NODEPS)) {
|
1996-06-11 01:41:24 +08:00
|
|
|
if (rpmdepCheck(rpmdep, &conflicts, &numConflicts)) {
|
|
|
|
numFailed = numPackages;
|
|
|
|
stopInstall = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!stopInstall && conflicts) {
|
1997-04-29 10:45:19 +08:00
|
|
|
fprintf(stderr, _("failed dependencies:\n"));
|
1996-07-11 00:28:50 +08:00
|
|
|
printDepProblems(stderr, conflicts, numConflicts);
|
1996-08-07 23:46:22 +08:00
|
|
|
rpmdepFreeConflicts(conflicts, numConflicts);
|
1996-06-11 01:41:24 +08:00
|
|
|
numFailed = numPackages;
|
|
|
|
stopInstall = 1;
|
|
|
|
}
|
|
|
|
}
|
1997-07-02 00:24:08 +08:00
|
|
|
|
|
|
|
if (!(interfaceFlags & INSTALL_NOORDER)) {
|
|
|
|
if (rpmdepOrder(rpmdep, (void ***) &packages)) {
|
|
|
|
numFailed = numPackages;
|
|
|
|
stopInstall = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
rpmdepDone(rpmdep);
|
1996-04-06 01:35:45 +08:00
|
|
|
}
|
1996-06-11 01:41:24 +08:00
|
|
|
else
|
|
|
|
db = NULL;
|
|
|
|
|
|
|
|
if (!stopInstall) {
|
1996-11-19 02:02:36 +08:00
|
|
|
rpmMessage(RPMMESS_DEBUG, "installing binary packages\n");
|
1996-07-10 10:35:15 +08:00
|
|
|
numFailed += installPackages(rootdir, packages, location, numPackages,
|
1996-06-11 01:41:24 +08:00
|
|
|
installFlags, interfaceFlags, db);
|
1996-01-09 03:21:55 +08:00
|
|
|
}
|
|
|
|
|
1996-06-11 01:41:24 +08:00
|
|
|
for (i = 0; i < numTmpPackages; i++)
|
|
|
|
unlink(tmpPackages[i]);
|
1996-04-03 11:46:41 +08:00
|
|
|
|
1996-10-21 09:22:12 +08:00
|
|
|
for (i = 0; i < numBinaryPackages; i++)
|
1996-11-19 02:02:36 +08:00
|
|
|
headerFree(binaryHeaders[i]);
|
1996-10-21 09:22:12 +08:00
|
|
|
|
1996-06-11 01:41:24 +08:00
|
|
|
if (db) rpmdbClose(db);
|
|
|
|
|
|
|
|
return numFailed;
|
1996-01-06 02:12:55 +08:00
|
|
|
}
|
|
|
|
|
1996-07-10 10:35:15 +08:00
|
|
|
int doUninstall(char * rootdir, char ** argv, int uninstallFlags,
|
1996-06-11 01:41:24 +08:00
|
|
|
int interfaceFlags) {
|
1996-01-06 02:12:55 +08:00
|
|
|
rpmdb db;
|
1996-11-19 02:02:36 +08:00
|
|
|
dbiIndexSet matches;
|
1996-06-11 01:41:24 +08:00
|
|
|
int i, j;
|
1996-01-09 03:21:55 +08:00
|
|
|
int mode;
|
1996-02-15 04:56:22 +08:00
|
|
|
int rc;
|
|
|
|
int count;
|
1997-04-01 04:15:41 +08:00
|
|
|
int numPackages, packageOffsetsAlloced;
|
1996-06-11 01:41:24 +08:00
|
|
|
int * packageOffsets;
|
|
|
|
char ** arg;
|
|
|
|
int numFailed = 0;
|
|
|
|
rpmDependencies rpmdep;
|
|
|
|
struct rpmDependencyConflict * conflicts;
|
|
|
|
int numConflicts;
|
|
|
|
int stopUninstall = 0;
|
|
|
|
|
1996-11-19 02:02:36 +08:00
|
|
|
rpmMessage(RPMMESS_DEBUG, "counting packages to uninstall\n");
|
1996-06-11 01:41:24 +08:00
|
|
|
for (arg = argv, numPackages = 0; *arg; arg++, numPackages++)
|
|
|
|
;
|
|
|
|
|
1997-04-01 04:15:41 +08:00
|
|
|
packageOffsetsAlloced = numPackages;
|
|
|
|
packageOffsets = malloc(sizeof(int *) * packageOffsetsAlloced);
|
1996-06-11 01:41:24 +08:00
|
|
|
|
1996-11-19 02:02:36 +08:00
|
|
|
if (uninstallFlags & RPMUNINSTALL_TEST)
|
1996-01-09 03:21:55 +08:00
|
|
|
mode = O_RDONLY;
|
|
|
|
else
|
|
|
|
mode = O_RDWR | O_EXCL;
|
|
|
|
|
1996-07-10 10:35:15 +08:00
|
|
|
if (rpmdbOpen(rootdir, &db, mode, 0644)) {
|
1998-01-06 01:22:04 +08:00
|
|
|
fprintf(stderr, _("error: cannot open %s%s/packages.rpm\n"),
|
|
|
|
rootdir, rpmGetVar(RPMVAR_DBPATH));
|
1996-01-06 02:12:55 +08:00
|
|
|
exit(1);
|
|
|
|
}
|
1996-06-11 01:41:24 +08:00
|
|
|
|
|
|
|
j = 0;
|
1997-04-01 04:15:41 +08:00
|
|
|
numPackages = 0;
|
|
|
|
for (arg = argv; *arg; arg++) {
|
1997-05-31 05:14:34 +08:00
|
|
|
rc = rpmdbFindByLabel(db, *arg, &matches);
|
1996-06-11 01:41:24 +08:00
|
|
|
if (rc == 1) {
|
1997-04-29 10:45:19 +08:00
|
|
|
fprintf(stderr, _("package %s is not installed\n"), *arg);
|
1996-06-11 01:41:24 +08:00
|
|
|
numFailed++;
|
|
|
|
} else if (rc == 2) {
|
1997-04-29 10:45:19 +08:00
|
|
|
fprintf(stderr, _("error searching for package %s\n"), *arg);
|
1996-06-11 01:41:24 +08:00
|
|
|
numFailed++;
|
|
|
|
} else {
|
|
|
|
count = 0;
|
|
|
|
for (i = 0; i < matches.count; i++)
|
|
|
|
if (matches.recs[i].recOffset) count++;
|
|
|
|
|
1997-04-01 04:15:41 +08:00
|
|
|
if (count > 1 && !(interfaceFlags & UNINSTALL_ALLMATCHES)) {
|
1997-04-29 10:45:19 +08:00
|
|
|
fprintf(stderr, _("\"%s\" specifies multiple packages\n"),
|
|
|
|
*arg);
|
1996-06-11 01:41:24 +08:00
|
|
|
numFailed++;
|
|
|
|
}
|
|
|
|
else {
|
1997-04-09 23:53:22 +08:00
|
|
|
numPackages += count;
|
1997-04-01 04:15:41 +08:00
|
|
|
if (numPackages > packageOffsetsAlloced) {
|
|
|
|
packageOffsetsAlloced = numPackages + 5;
|
|
|
|
packageOffsets = realloc(packageOffsets,
|
|
|
|
sizeof(int *) * packageOffsetsAlloced);
|
|
|
|
}
|
1996-06-11 01:41:24 +08:00
|
|
|
for (i = 0; i < matches.count; i++) {
|
|
|
|
if (matches.recs[i].recOffset) {
|
|
|
|
packageOffsets[j++] = matches.recs[i].recOffset;
|
|
|
|
}
|
1996-02-15 04:56:22 +08:00
|
|
|
}
|
1996-01-06 08:05:14 +08:00
|
|
|
}
|
1996-06-11 01:41:24 +08:00
|
|
|
|
1996-11-19 02:02:36 +08:00
|
|
|
dbiFreeIndexRecord(matches);
|
1996-06-11 01:41:24 +08:00
|
|
|
}
|
|
|
|
}
|
1997-04-01 04:15:41 +08:00
|
|
|
|
|
|
|
rpmMessage(RPMMESS_DEBUG, "found %d packages to uninstall\n", numPackages);
|
1996-06-11 01:41:24 +08:00
|
|
|
|
1996-11-19 02:02:36 +08:00
|
|
|
if (!(interfaceFlags & UNINSTALL_NODEPS)) {
|
1996-06-11 01:41:24 +08:00
|
|
|
rpmdep = rpmdepDependencies(db);
|
|
|
|
for (i = 0; i < numPackages; i++)
|
|
|
|
rpmdepRemovePackage(rpmdep, packageOffsets[i]);
|
|
|
|
|
|
|
|
if (rpmdepCheck(rpmdep, &conflicts, &numConflicts)) {
|
|
|
|
numFailed = numPackages;
|
|
|
|
stopUninstall = 1;
|
|
|
|
}
|
|
|
|
|
1996-10-21 09:22:12 +08:00
|
|
|
rpmdepDone(rpmdep);
|
|
|
|
|
1996-06-11 01:41:24 +08:00
|
|
|
if (!stopUninstall && conflicts) {
|
1997-04-29 10:45:19 +08:00
|
|
|
fprintf(stderr, _("removing these packages would break "
|
|
|
|
"dependencies:\n"));
|
1996-07-11 00:28:50 +08:00
|
|
|
printDepProblems(stderr, conflicts, numConflicts);
|
1996-08-07 23:46:22 +08:00
|
|
|
rpmdepFreeConflicts(conflicts, numConflicts);
|
1996-06-11 01:41:24 +08:00
|
|
|
numFailed += numPackages;
|
|
|
|
stopUninstall = 1;
|
1996-01-06 02:12:55 +08:00
|
|
|
}
|
1996-06-11 01:41:24 +08:00
|
|
|
}
|
1996-01-06 02:12:55 +08:00
|
|
|
|
1996-06-11 01:41:24 +08:00
|
|
|
if (!stopUninstall) {
|
|
|
|
for (i = 0; i < numPackages; i++) {
|
1996-11-19 02:02:36 +08:00
|
|
|
rpmMessage(RPMMESS_DEBUG, "uninstalling record number %d\n",
|
1996-06-11 01:41:24 +08:00
|
|
|
packageOffsets[i]);
|
1997-03-20 23:18:45 +08:00
|
|
|
if (rpmRemovePackage(rootdir, db, packageOffsets[i],
|
|
|
|
uninstallFlags))
|
|
|
|
numFailed++;
|
1996-06-11 01:41:24 +08:00
|
|
|
}
|
1996-01-06 02:12:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
rpmdbClose(db);
|
1996-06-11 01:41:24 +08:00
|
|
|
|
1997-04-01 04:15:41 +08:00
|
|
|
free(packageOffsets);
|
|
|
|
|
1996-06-11 01:41:24 +08:00
|
|
|
return numFailed;
|
1996-01-06 02:12:55 +08:00
|
|
|
}
|
1996-02-15 04:09:14 +08:00
|
|
|
|
1997-10-29 23:55:09 +08:00
|
|
|
int doSourceInstall(char * rootdir, char * arg, char ** specFile,
|
|
|
|
char ** cookie) {
|
1996-02-15 04:09:14 +08:00
|
|
|
int fd;
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
fd = open(arg, O_RDONLY);
|
|
|
|
if (fd < 0) {
|
1997-04-29 10:45:19 +08:00
|
|
|
fprintf(stderr, _("error: cannot open %s\n"), arg);
|
1996-02-15 04:09:14 +08:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
1996-11-19 02:02:36 +08:00
|
|
|
if (rpmIsVerbose())
|
1996-02-15 04:09:14 +08:00
|
|
|
printf("Installing %s\n", arg);
|
|
|
|
|
1997-10-29 23:55:09 +08:00
|
|
|
rc = rpmInstallSourcePackage(rootdir, fd, specFile, NULL, NULL, cookie);
|
1996-02-15 04:09:14 +08:00
|
|
|
if (rc == 1) {
|
1997-04-29 10:45:19 +08:00
|
|
|
fprintf(stderr, _("error: %s cannot be installed\n"), arg);
|
1997-10-29 23:55:09 +08:00
|
|
|
if (specFile) free(*specFile);
|
|
|
|
if (cookie) free(*cookie);
|
1996-02-15 04:09:14 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
close(fd);
|
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
1996-02-28 01:37:06 +08:00
|
|
|
|
1996-07-21 07:20:56 +08:00
|
|
|
void printDepFlags(FILE * f, char * version, int flags) {
|
|
|
|
if (flags)
|
|
|
|
fprintf(f, " ");
|
|
|
|
|
1996-11-19 02:02:36 +08:00
|
|
|
if (flags & RPMSENSE_LESS)
|
1996-07-11 00:28:50 +08:00
|
|
|
fprintf(f, "<");
|
1996-11-19 02:02:36 +08:00
|
|
|
if (flags & RPMSENSE_GREATER)
|
1996-07-11 00:28:50 +08:00
|
|
|
fprintf(f, ">");
|
1996-11-19 02:02:36 +08:00
|
|
|
if (flags & RPMSENSE_EQUAL)
|
1996-07-11 00:28:50 +08:00
|
|
|
fprintf(f, "=");
|
1996-11-19 02:02:36 +08:00
|
|
|
if (flags & RPMSENSE_SERIAL)
|
1996-07-11 00:28:50 +08:00
|
|
|
fprintf(f, "S");
|
|
|
|
|
|
|
|
if (flags)
|
|
|
|
fprintf(f, " %s", version);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void printDepProblems(FILE * f, struct rpmDependencyConflict * conflicts,
|
|
|
|
int numConflicts) {
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < numConflicts; i++) {
|
1996-07-12 10:32:31 +08:00
|
|
|
fprintf(f, "\t%s", conflicts[i].needsName);
|
1996-07-18 04:00:49 +08:00
|
|
|
if (conflicts[i].needsFlags) {
|
|
|
|
printDepFlags(stderr, conflicts[i].needsVersion,
|
|
|
|
conflicts[i].needsFlags);
|
|
|
|
}
|
1996-10-21 03:29:34 +08:00
|
|
|
|
|
|
|
if (conflicts[i].sense == RPMDEP_SENSE_REQUIRES)
|
1997-04-29 10:45:19 +08:00
|
|
|
fprintf(f, _(" is needed by %s-%s-%s\n"), conflicts[i].byName,
|
1996-10-21 03:29:34 +08:00
|
|
|
conflicts[i].byVersion, conflicts[i].byRelease);
|
|
|
|
else
|
1997-04-29 10:45:19 +08:00
|
|
|
fprintf(f, _(" conflicts with %s-%s-%s\n"), conflicts[i].byName,
|
1996-10-21 03:29:34 +08:00
|
|
|
conflicts[i].byVersion, conflicts[i].byRelease);
|
1996-07-11 00:28:50 +08:00
|
|
|
}
|
|
|
|
}
|