1998-07-26 05:00:26 +08:00
|
|
|
#include "system.h"
|
1996-12-12 11:32:22 +08:00
|
|
|
|
1998-07-31 06:09:42 +08:00
|
|
|
#include "build/rpmbuild.h"
|
|
|
|
|
1996-01-06 02:12:55 +08:00
|
|
|
#include "install.h"
|
1996-10-15 11:14:35 +08:00
|
|
|
#include "url.h"
|
1998-12-15 05:34:11 +08:00
|
|
|
#include "ftp.h"
|
1996-01-06 02:12:55 +08:00
|
|
|
|
1996-01-23 05:12:55 +08:00
|
|
|
static void printHash(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);
|
1999-01-12 11:11:25 +08:00
|
|
|
static void * showProgress(const Header h, const rpmCallbackType what,
|
|
|
|
const unsigned long amount,
|
|
|
|
const unsigned long total,
|
|
|
|
const void * pkgKey, void * data);
|
1998-12-17 05:58:53 +08:00
|
|
|
|
|
|
|
static int hashesPrinted = 0;
|
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) {
|
1999-01-06 11:51:53 +08:00
|
|
|
printf("#");
|
|
|
|
fflush(stdout);
|
1996-01-23 05:12:55 +08:00
|
|
|
hashesPrinted++;
|
|
|
|
}
|
|
|
|
fflush(stdout);
|
|
|
|
hashesPrinted = hashesNeeded;
|
|
|
|
|
|
|
|
if (hashesPrinted == 50)
|
1998-09-28 06:03:52 +08:00
|
|
|
fprintf(stdout, "\n");
|
1996-01-23 05:12:55 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-01-12 11:11:25 +08:00
|
|
|
static void * showProgress(const Header h, const rpmCallbackType what,
|
|
|
|
const unsigned long amount,
|
|
|
|
const unsigned long total,
|
|
|
|
const void * pkgKey, void * data) {
|
1998-12-17 05:58:53 +08:00
|
|
|
char * s;
|
|
|
|
int flags = (int) data;
|
1999-01-12 11:11:25 +08:00
|
|
|
void * rc = NULL;
|
1996-06-11 01:41:24 +08:00
|
|
|
|
1998-12-17 05:58:53 +08:00
|
|
|
switch (what) {
|
1999-01-12 11:11:25 +08:00
|
|
|
case RPMCALLBACK_INST_START:
|
1996-07-20 06:32:36 +08:00
|
|
|
hashesPrinted = 0;
|
1998-12-17 05:58:53 +08:00
|
|
|
if (flags & INSTALL_LABEL) {
|
1999-01-12 11:11:25 +08:00
|
|
|
if (flags & INSTALL_HASH) {
|
|
|
|
s = headerSprintf(h, "%{NAME}",
|
|
|
|
rpmTagTable, rpmHeaderFormats, NULL);
|
1999-01-07 12:11:12 +08:00
|
|
|
printf("%-28s", s);
|
1999-01-12 11:11:25 +08:00
|
|
|
} else {
|
|
|
|
s = headerSprintf(h, "%{NAME}-%{VERSION}-%{RELEASE}",
|
|
|
|
rpmTagTable, rpmHeaderFormats, NULL);
|
1999-01-07 12:11:12 +08:00
|
|
|
printf("%s\n", s);
|
1999-01-12 11:11:25 +08:00
|
|
|
}
|
1999-01-06 11:51:53 +08:00
|
|
|
fflush(stdout);
|
1998-12-17 05:58:53 +08:00
|
|
|
free(s);
|
1996-06-11 01:41:24 +08:00
|
|
|
}
|
1998-12-17 05:58:53 +08:00
|
|
|
break;
|
|
|
|
|
1999-01-12 11:11:25 +08:00
|
|
|
case RPMCALLBACK_INST_PROGRESS:
|
1998-12-17 05:58:53 +08:00
|
|
|
if (flags & INSTALL_PERCENT) {
|
|
|
|
fprintf(stdout, "%%%% %f\n", (total
|
|
|
|
? ((float) ((((float) amount) / total) * 100))
|
|
|
|
: 100.0));
|
1999-01-06 11:51:53 +08:00
|
|
|
} else if (flags & INSTALL_HASH) {
|
1998-12-17 05:58:53 +08:00
|
|
|
printHash(amount, total);
|
1996-06-11 01:41:24 +08:00
|
|
|
}
|
1998-12-17 05:58:53 +08:00
|
|
|
break;
|
1999-01-12 11:11:25 +08:00
|
|
|
|
|
|
|
case RPMCALLBACK_INST_OPEN_FILE: /* shouldn't happen */
|
|
|
|
case RPMCALLBACK_INST_CLOSE_FILE: /* shouldn't happen */
|
|
|
|
abort();
|
1996-01-09 03:21:55 +08:00
|
|
|
}
|
1999-01-12 11:11:25 +08:00
|
|
|
|
|
|
|
return rc;
|
1998-12-17 05:58:53 +08:00
|
|
|
}
|
1996-06-11 01:41:24 +08:00
|
|
|
|
1999-01-07 01:33:50 +08:00
|
|
|
int doInstall(const char * rootdir, const char ** argv, int installFlags,
|
1998-12-17 05:58:53 +08:00
|
|
|
int interfaceFlags, int probFilter,
|
|
|
|
rpmRelocation * relocations) {
|
|
|
|
rpmdb db = NULL;
|
1998-11-19 05:41:05 +08:00
|
|
|
FD_t fd;
|
|
|
|
int i;
|
1998-12-17 05:58:53 +08:00
|
|
|
int mode, rc, major;
|
1999-01-07 12:05:23 +08:00
|
|
|
const char ** packages, ** tmpPackages;
|
1999-01-07 01:33:50 +08:00
|
|
|
const char ** filename;
|
1996-06-11 01:41:24 +08:00
|
|
|
int numPackages;
|
1999-01-07 12:05:23 +08:00
|
|
|
int numTmpPackages = 0, numBinaryPackages = 0, numSourcePackages = 0;
|
1996-06-11 01:41:24 +08:00
|
|
|
int numFailed = 0;
|
1998-12-17 05:58:53 +08:00
|
|
|
Header h;
|
1996-06-11 01:41:24 +08:00
|
|
|
int isSource;
|
1999-01-09 00:44:30 +08:00
|
|
|
rpmTransactionSet rpmdep = NULL;
|
1996-06-11 01:41:24 +08:00
|
|
|
struct rpmDependencyConflict * conflicts;
|
|
|
|
int numConflicts;
|
|
|
|
int stopInstall = 0;
|
1998-12-15 05:34:11 +08:00
|
|
|
size_t nb;
|
1999-01-12 11:11:25 +08:00
|
|
|
int notifyFlags = interfaceFlags | (rpmIsVerbose() ? INSTALL_LABEL : 0 );
|
1998-12-17 05:58:53 +08:00
|
|
|
int transFlags = 0;
|
|
|
|
rpmProblemSet probs, finalProbs;
|
1999-01-07 12:05:23 +08:00
|
|
|
int dbIsOpen = 0;
|
1999-01-08 11:12:51 +08:00
|
|
|
const char ** sourcePackages;
|
1996-06-11 01:41:24 +08:00
|
|
|
|
1999-01-07 12:05:23 +08:00
|
|
|
if (installFlags & RPMINSTALL_TEST)
|
1999-01-07 08:45:52 +08:00
|
|
|
mode = O_RDONLY;
|
1999-01-07 12:05:23 +08:00
|
|
|
else
|
|
|
|
mode = O_RDWR | O_CREAT;
|
|
|
|
|
|
|
|
if (installFlags & RPMINSTALL_TEST)
|
|
|
|
transFlags |= RPMTRANS_FLAG_TEST;
|
1998-12-17 05:58:53 +08:00
|
|
|
|
1998-09-28 06:03:52 +08:00
|
|
|
rpmMessage(RPMMESS_DEBUG, _("counting packages to install\n"));
|
1999-01-07 12:05:23 +08:00
|
|
|
for (filename = argv, numPackages = 0; *filename; filename++, numPackages++)
|
|
|
|
;
|
1996-06-11 01:41:24 +08:00
|
|
|
|
1998-09-28 06:03:52 +08:00
|
|
|
rpmMessage(RPMMESS_DEBUG, _("found %d packages\n"), numPackages);
|
1998-12-15 05:34:11 +08:00
|
|
|
|
|
|
|
nb = (numPackages + 1) * sizeof(char *);
|
|
|
|
packages = alloca(nb);
|
|
|
|
memset(packages, 0, nb);
|
1999-01-07 12:05:23 +08:00
|
|
|
tmpPackages = alloca(nb);
|
|
|
|
memset(tmpPackages, 0, nb);
|
1998-12-15 05:34:11 +08:00
|
|
|
nb = (numPackages + 1) * sizeof(Header);
|
|
|
|
|
1998-09-28 06:03:52 +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++) {
|
1998-12-01 08:10:18 +08:00
|
|
|
|
|
|
|
switch (urlIsURL(*filename)) {
|
|
|
|
case URL_IS_FTP:
|
1998-12-15 05:34:11 +08:00
|
|
|
case URL_IS_HTTP:
|
|
|
|
case URL_IS_PATH:
|
1998-12-01 08:10:18 +08:00
|
|
|
{ int myrc;
|
1999-01-06 07:13:56 +08:00
|
|
|
const char *tfn;
|
1999-01-14 03:28:12 +08:00
|
|
|
|
|
|
|
if (rpmIsVerbose())
|
1998-09-28 06:03:52 +08:00
|
|
|
fprintf(stdout, _("Retrieving %s\n"), *filename);
|
1998-12-15 05:34:11 +08:00
|
|
|
|
1999-01-14 03:28:12 +08:00
|
|
|
{ char tfnbuf[64];
|
|
|
|
strcpy(tfnbuf, "rpm-xfer.XXXXXX");
|
|
|
|
/* XXX watchout for rootdir = NULL */
|
|
|
|
tfn = rpmGetPath( (rootdir ? rootdir : ""),
|
|
|
|
"%{_tmppath}", mktemp(tfnbuf), NULL);
|
|
|
|
}
|
1998-12-15 05:34:11 +08:00
|
|
|
|
|
|
|
rpmMessage(RPMMESS_DEBUG, _(" ... as %s\n"), tfn);
|
|
|
|
myrc = urlGetFile(*filename, tfn);
|
1998-11-19 05:41:05 +08:00
|
|
|
if (myrc < 0) {
|
1998-12-15 05:34:11 +08:00
|
|
|
rpmMessage(RPMMESS_ERROR,
|
|
|
|
_("skipping %s - transfer failed - %s\n"),
|
1998-11-19 05:41:05 +08:00
|
|
|
*filename, ftpStrerror(myrc));
|
1996-06-11 01:41:24 +08:00
|
|
|
numFailed++;
|
1998-12-15 05:34:11 +08:00
|
|
|
packages[i] = NULL;
|
1999-01-06 07:13:56 +08:00
|
|
|
xfree(tfn);
|
1996-06-11 01:41:24 +08:00
|
|
|
} else {
|
1999-01-07 12:05:23 +08:00
|
|
|
tmpPackages[numTmpPackages++] = packages[i++] = tfn;
|
1996-06-11 01:41:24 +08:00
|
|
|
}
|
1998-12-01 08:10:18 +08:00
|
|
|
} break;
|
|
|
|
default:
|
1996-06-11 01:41:24 +08:00
|
|
|
packages[i++] = *filename;
|
1998-12-01 08:10:18 +08:00
|
|
|
break;
|
1996-02-28 01:37:06 +08:00
|
|
|
}
|
1996-06-11 01:41:24 +08:00
|
|
|
}
|
|
|
|
|
1999-01-07 12:05:23 +08:00
|
|
|
sourcePackages = alloca(sizeof(*sourcePackages) * i);
|
|
|
|
|
1998-09-28 06:03:52 +08:00
|
|
|
rpmMessage(RPMMESS_DEBUG, _("retrieved %d packages\n"), numTmpPackages);
|
1996-06-11 01:41:24 +08:00
|
|
|
|
1999-01-07 12:05:23 +08:00
|
|
|
/* Build up the transaction set. As a special case, v1 source packages
|
|
|
|
are installed right here, only because they don't have headers and
|
|
|
|
would create all sorts of confusion later. */
|
1998-12-17 05:58:53 +08:00
|
|
|
|
|
|
|
for (filename = packages; *filename; filename++) {
|
1998-11-19 05:41:05 +08:00
|
|
|
fd = fdOpen(*filename, O_RDONLY, 0);
|
|
|
|
if (fdFileno(fd) < 0) {
|
1998-12-15 05:34:11 +08:00
|
|
|
rpmMessage(RPMMESS_ERROR, _("cannot open file %s\n"), *filename);
|
1996-06-11 01:41:24 +08:00
|
|
|
numFailed++;
|
1998-12-15 05:34:11 +08:00
|
|
|
packages[i] = 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
|
|
|
|
1998-12-17 05:58:53 +08:00
|
|
|
rc = rpmReadPackageHeader(fd, &h, &isSource, &major, NULL);
|
1996-06-11 01:41:24 +08:00
|
|
|
|
1999-01-07 01:33:50 +08:00
|
|
|
switch (rc) {
|
|
|
|
case 1:
|
1999-01-07 12:05:23 +08:00
|
|
|
fdClose(fd);
|
1999-01-07 01:33:50 +08:00
|
|
|
rpmMessage(RPMMESS_ERROR,
|
|
|
|
_("%s does not appear to be a RPM package\n"),
|
|
|
|
*filename);
|
1999-01-07 12:05:23 +08:00
|
|
|
break;
|
1999-01-07 01:33:50 +08:00
|
|
|
default:
|
|
|
|
rpmMessage(RPMMESS_ERROR, _("%s cannot be installed\n"), *filename);
|
1996-06-11 01:41:24 +08:00
|
|
|
numFailed++;
|
1998-12-15 05:34:11 +08:00
|
|
|
packages[i] = NULL;
|
1999-01-07 01:33:50 +08:00
|
|
|
break;
|
|
|
|
case 0:
|
1999-01-07 12:05:23 +08:00
|
|
|
if (isSource && major == 1) {
|
|
|
|
printf("XXX FIXME I can't install v1 source packages!!!\n");
|
|
|
|
} else if (isSource) {
|
|
|
|
sourcePackages[numSourcePackages++] = *filename;
|
1999-01-07 08:45:52 +08:00
|
|
|
fdClose(fd);
|
1999-01-07 01:33:50 +08:00
|
|
|
} else {
|
1999-01-07 12:05:23 +08:00
|
|
|
if (!dbIsOpen) {
|
1999-01-07 08:45:52 +08:00
|
|
|
if (rpmdbOpen(rootdir, &db, mode, 0644)) {
|
|
|
|
const char *dn;
|
1999-01-07 12:05:23 +08:00
|
|
|
dn = rpmGetPath( (rootdir ? rootdir : ""),
|
|
|
|
"%{_dbpath}", NULL);
|
|
|
|
rpmMessage(RPMMESS_ERROR,
|
|
|
|
_("cannot open %s/packages.rpm\n"), dn);
|
1999-01-07 08:45:52 +08:00
|
|
|
xfree(dn);
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
rpmdep = rpmtransCreateSet(db, rootdir);
|
1999-01-07 12:05:23 +08:00
|
|
|
dbIsOpen = 1;
|
1999-01-07 08:45:52 +08:00
|
|
|
}
|
1999-01-07 12:05:23 +08:00
|
|
|
|
1999-01-07 01:33:50 +08:00
|
|
|
rpmtransAddPackage(rpmdep, h, fd,
|
1998-12-17 05:58:53 +08:00
|
|
|
packages[i],
|
|
|
|
(interfaceFlags & INSTALL_UPGRADE) != 0,
|
|
|
|
relocations);
|
1999-01-07 12:05:23 +08:00
|
|
|
numBinaryPackages++;
|
1999-01-07 01:33:50 +08:00
|
|
|
}
|
|
|
|
break;
|
1996-02-28 01:37:06 +08:00
|
|
|
}
|
1996-01-09 03:21:55 +08:00
|
|
|
}
|
|
|
|
|
1999-01-07 12:05:23 +08:00
|
|
|
rpmMessage(RPMMESS_DEBUG, _("found %d source and %d binary packages\n"),
|
|
|
|
numSourcePackages, numBinaryPackages);
|
|
|
|
|
|
|
|
if (numBinaryPackages && !(interfaceFlags & INSTALL_NODEPS)) {
|
1998-12-17 05:58:53 +08:00
|
|
|
if (rpmdepCheck(rpmdep, &conflicts, &numConflicts)) {
|
|
|
|
numFailed = numPackages;
|
|
|
|
stopInstall = 1;
|
1996-06-11 01:41:24 +08:00
|
|
|
}
|
|
|
|
|
1998-12-17 05:58:53 +08:00
|
|
|
if (!stopInstall && conflicts) {
|
|
|
|
rpmMessage(RPMMESS_ERROR, _("failed dependencies:\n"));
|
|
|
|
printDepProblems(stderr, conflicts, numConflicts);
|
|
|
|
rpmdepFreeConflicts(conflicts, numConflicts);
|
|
|
|
numFailed = numPackages;
|
|
|
|
stopInstall = 1;
|
1996-06-11 01:41:24 +08:00
|
|
|
}
|
1998-12-17 05:58:53 +08:00
|
|
|
}
|
1997-07-02 00:24:08 +08:00
|
|
|
|
1999-01-07 12:05:23 +08:00
|
|
|
if (numBinaryPackages && !(interfaceFlags & INSTALL_NOORDER)) {
|
1998-12-17 05:58:53 +08:00
|
|
|
if (rpmdepOrder(rpmdep, (void ***) &packages)) {
|
|
|
|
numFailed = numPackages;
|
|
|
|
stopInstall = 1;
|
1997-07-02 00:24:08 +08:00
|
|
|
}
|
1996-04-06 01:35:45 +08:00
|
|
|
}
|
1996-06-11 01:41:24 +08:00
|
|
|
|
1999-01-07 12:05:23 +08:00
|
|
|
if (numBinaryPackages && !stopInstall) {
|
1998-09-28 06:03:52 +08:00
|
|
|
rpmMessage(RPMMESS_DEBUG, _("installing binary packages\n"));
|
1998-12-17 05:58:53 +08:00
|
|
|
rc = rpmRunTransactions(rpmdep, showProgress, (void *) notifyFlags,
|
|
|
|
NULL, &probs, transFlags);
|
|
|
|
if (rc < 0) {
|
|
|
|
numFailed += numPackages;
|
|
|
|
} else if (rc) {
|
|
|
|
rpmProblemSetFilter(probs, probFilter);
|
|
|
|
|
|
|
|
rc = rpmRunTransactions(rpmdep, showProgress, (void *) notifyFlags,
|
|
|
|
probs, &finalProbs, transFlags);
|
|
|
|
rpmProblemSetFree(probs);
|
|
|
|
|
|
|
|
if (rc < 0) {
|
1999-01-07 12:05:23 +08:00
|
|
|
numFailed += numBinaryPackages;
|
1998-12-17 05:58:53 +08:00
|
|
|
} else if (rc) {
|
|
|
|
numFailed += rc;
|
|
|
|
for (i = 0; i < finalProbs->numProblems; i++)
|
|
|
|
if (!finalProbs->probs[i].ignoreProblem)
|
1999-01-07 01:33:50 +08:00
|
|
|
rpmMessage(RPMMESS_ERROR, "%s\n",
|
1998-12-17 05:58:53 +08:00
|
|
|
rpmProblemString(finalProbs->probs[i]));
|
|
|
|
|
|
|
|
rpmProblemSetFree(finalProbs);
|
|
|
|
}
|
|
|
|
}
|
1996-01-09 03:21:55 +08:00
|
|
|
}
|
|
|
|
|
1999-01-07 12:05:23 +08:00
|
|
|
if (numBinaryPackages) rpmtransFree(rpmdep);
|
1998-12-17 05:58:53 +08:00
|
|
|
|
1999-01-12 11:11:25 +08:00
|
|
|
|
1999-01-09 00:44:30 +08:00
|
|
|
if (numSourcePackages && !stopInstall) {
|
1999-01-07 12:05:23 +08:00
|
|
|
for (i = 0; i < numSourcePackages; i++) {
|
|
|
|
fd = fdOpen(sourcePackages[i], O_RDONLY, 0);
|
|
|
|
if (fdFileno(fd) < 0) {
|
|
|
|
rpmMessage(RPMMESS_ERROR, _("cannot open file %s\n"),
|
|
|
|
sourcePackages[i]);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
numFailed += rpmInstallSourcePackage(rootdir, fd, NULL,
|
1999-01-08 11:12:51 +08:00
|
|
|
showProgress, (void *) notifyFlags, NULL);
|
1999-01-07 12:05:23 +08:00
|
|
|
|
|
|
|
fdClose(fd);
|
|
|
|
}
|
|
|
|
}
|
1999-01-07 08:45:52 +08:00
|
|
|
|
|
|
|
for (i = 0; i < numTmpPackages; i++) {
|
1999-01-07 12:05:23 +08:00
|
|
|
unlink(tmpPackages[i]);
|
|
|
|
xfree(tmpPackages[i]);
|
1999-01-07 08:45:52 +08:00
|
|
|
}
|
1996-06-11 01:41:24 +08:00
|
|
|
|
1999-01-07 12:05:23 +08:00
|
|
|
/* FIXME how do we close our various fd's? */
|
|
|
|
|
1999-01-09 00:44:30 +08:00
|
|
|
if (dbIsOpen) rpmdbClose(db);
|
1999-01-07 12:05:23 +08:00
|
|
|
|
1996-06-11 01:41:24 +08:00
|
|
|
return numFailed;
|
1996-01-06 02:12:55 +08:00
|
|
|
}
|
|
|
|
|
1999-01-07 01:33:50 +08:00
|
|
|
int doUninstall(const char * rootdir, const 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;
|
1999-01-07 01:33:50 +08:00
|
|
|
const char ** arg;
|
1996-06-11 01:41:24 +08:00
|
|
|
int numFailed = 0;
|
1998-12-17 05:58:53 +08:00
|
|
|
rpmTransactionSet rpmdep;
|
1996-06-11 01:41:24 +08:00
|
|
|
struct rpmDependencyConflict * conflicts;
|
|
|
|
int numConflicts;
|
|
|
|
int stopUninstall = 0;
|
1998-12-17 05:58:53 +08:00
|
|
|
int transFlags = 0;
|
|
|
|
int numPackages = 0;
|
|
|
|
rpmProblemSet probs;
|
1996-06-11 01:41:24 +08:00
|
|
|
|
1998-12-17 05:58:53 +08:00
|
|
|
if (uninstallFlags & RPMUNINSTALL_TEST)
|
|
|
|
transFlags |= RPMTRANS_FLAG_TEST;
|
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)) {
|
1999-01-07 01:33:50 +08:00
|
|
|
const char *dn;
|
|
|
|
dn = rpmGetPath( (rootdir ? rootdir : ""), "%{_dbpath}", NULL);
|
|
|
|
rpmMessage(RPMMESS_ERROR, _("cannot open %s/packages.rpm\n"), dn);
|
|
|
|
xfree(dn);
|
1998-11-21 04:18:22 +08:00
|
|
|
exit(EXIT_FAILURE);
|
1996-01-06 02:12:55 +08:00
|
|
|
}
|
1996-06-11 01:41:24 +08:00
|
|
|
|
|
|
|
j = 0;
|
1998-12-17 05:58:53 +08:00
|
|
|
rpmdep = rpmtransCreateSet(db, rootdir);
|
1997-04-01 04:15:41 +08:00
|
|
|
for (arg = argv; *arg; arg++) {
|
1997-05-31 05:14:34 +08:00
|
|
|
rc = rpmdbFindByLabel(db, *arg, &matches);
|
1999-01-07 01:33:50 +08:00
|
|
|
switch (rc) {
|
|
|
|
case 1:
|
1998-12-15 05:34:11 +08:00
|
|
|
rpmMessage(RPMMESS_ERROR, _("package %s is not installed\n"), *arg);
|
1996-06-11 01:41:24 +08:00
|
|
|
numFailed++;
|
1999-01-07 01:33:50 +08:00
|
|
|
break;
|
|
|
|
case 2:
|
1998-12-15 05:34:11 +08:00
|
|
|
rpmMessage(RPMMESS_ERROR, _("searching for package %s\n"), *arg);
|
1996-06-11 01:41:24 +08:00
|
|
|
numFailed++;
|
1999-01-07 01:33:50 +08:00
|
|
|
break;
|
|
|
|
default:
|
1996-06-11 01:41:24 +08:00
|
|
|
count = 0;
|
1998-11-20 02:10:28 +08:00
|
|
|
for (i = 0; i < dbiIndexSetCount(matches); i++)
|
|
|
|
if (dbiIndexRecordOffset(matches, i)) count++;
|
1996-06-11 01:41:24 +08:00
|
|
|
|
1997-04-01 04:15:41 +08:00
|
|
|
if (count > 1 && !(interfaceFlags & UNINSTALL_ALLMATCHES)) {
|
1998-12-15 05:34:11 +08:00
|
|
|
rpmMessage(RPMMESS_ERROR, _("\"%s\" specifies multiple packages\n"),
|
1997-04-29 10:45:19 +08:00
|
|
|
*arg);
|
1996-06-11 01:41:24 +08:00
|
|
|
numFailed++;
|
|
|
|
}
|
|
|
|
else {
|
1998-11-20 02:10:28 +08:00
|
|
|
for (i = 0; i < dbiIndexSetCount(matches); i++) {
|
|
|
|
unsigned int recOffset = dbiIndexRecordOffset(matches, i);
|
|
|
|
if (recOffset) {
|
1998-12-17 05:58:53 +08:00
|
|
|
rpmtransRemovePackage(rpmdep, recOffset);
|
|
|
|
numPackages++;
|
1996-06-11 01:41:24 +08:00
|
|
|
}
|
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);
|
1999-01-07 01:33:50 +08:00
|
|
|
break;
|
1996-06-11 01:41:24 +08:00
|
|
|
}
|
|
|
|
}
|
1997-04-01 04:15:41 +08:00
|
|
|
|
1996-11-19 02:02:36 +08:00
|
|
|
if (!(interfaceFlags & UNINSTALL_NODEPS)) {
|
1996-06-11 01:41:24 +08:00
|
|
|
if (rpmdepCheck(rpmdep, &conflicts, &numConflicts)) {
|
|
|
|
numFailed = numPackages;
|
|
|
|
stopUninstall = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!stopUninstall && conflicts) {
|
1998-12-15 05:34:11 +08:00
|
|
|
rpmMessage(RPMMESS_ERROR, _("removing these packages would break "
|
1997-04-29 10:45:19 +08:00
|
|
|
"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) {
|
1998-12-17 05:58:53 +08:00
|
|
|
numFailed += rpmRunTransactions(rpmdep, NULL, NULL, NULL, &probs,
|
|
|
|
transFlags);
|
1996-01-06 02:12:55 +08:00
|
|
|
}
|
|
|
|
|
1998-12-17 05:58:53 +08:00
|
|
|
rpmtransFree(rpmdep);
|
1996-01-06 02:12:55 +08:00
|
|
|
rpmdbClose(db);
|
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
|
|
|
|
1999-01-07 01:33:50 +08:00
|
|
|
int doSourceInstall(const char * rootdir, const char * arg, const char ** specFile,
|
1997-10-29 23:55:09 +08:00
|
|
|
char ** cookie) {
|
1998-11-19 05:41:05 +08:00
|
|
|
FD_t fd;
|
1996-02-15 04:09:14 +08:00
|
|
|
int rc;
|
|
|
|
|
1998-11-19 05:41:05 +08:00
|
|
|
fd = fdOpen(arg, O_RDONLY, 0);
|
|
|
|
if (fdFileno(fd) < 0) {
|
1998-12-15 05:34:11 +08:00
|
|
|
rpmMessage(RPMMESS_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())
|
1998-09-28 06:03:52 +08:00
|
|
|
fprintf(stdout, _("Installing %s\n"), arg);
|
1996-02-15 04:09:14 +08:00
|
|
|
|
1999-01-07 12:05:23 +08:00
|
|
|
rc = rpmInstallSourcePackage(rootdir, fd, specFile, NULL, NULL,
|
1998-12-17 05:58:53 +08:00
|
|
|
cookie);
|
1996-02-15 04:09:14 +08:00
|
|
|
if (rc == 1) {
|
1998-12-15 05:34:11 +08:00
|
|
|
rpmMessage(RPMMESS_ERROR, _("%s cannot be installed\n"), arg);
|
1998-11-21 04:18:22 +08:00
|
|
|
if (specFile) FREE(*specFile);
|
|
|
|
if (cookie) FREE(*cookie);
|
1996-02-15 04:09:14 +08:00
|
|
|
}
|
|
|
|
|
1998-11-19 05:41:05 +08:00
|
|
|
fdClose(fd);
|
1996-02-15 04:09:14 +08:00
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
1996-02-28 01:37:06 +08:00
|
|
|
|
1999-01-07 01:33:50 +08:00
|
|
|
void printDepFlags(FILE * f, const char * version, int flags) {
|
1996-07-21 07:20:56 +08:00
|
|
|
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
|
|
|
}
|
|
|
|
}
|