2000-08-28 03:27:03 +08:00
|
|
|
/** \ingroup rpmcli
|
|
|
|
* \file lib/rpminstall.c
|
|
|
|
*/
|
|
|
|
|
1999-07-14 23:28:03 +08:00
|
|
|
#include "system.h"
|
|
|
|
|
1999-07-14 23:43:30 +08:00
|
|
|
#include <rpmlib.h>
|
|
|
|
#include <rpmmacro.h>
|
|
|
|
#include <rpmurl.h>
|
1999-07-14 23:28:03 +08:00
|
|
|
|
1999-12-13 01:46:22 +08:00
|
|
|
#include "misc.h"
|
2000-12-13 04:03:45 +08:00
|
|
|
#include "debug.h"
|
1999-12-13 01:46:22 +08:00
|
|
|
|
2000-10-29 01:16:25 +08:00
|
|
|
/*@access Header@*/ /* XXX compared with NULL */
|
|
|
|
/*@access FD_t@*/ /* XXX compared with NULL */
|
|
|
|
|
2000-10-29 02:45:58 +08:00
|
|
|
/* Define if you want percentage progress in the hash bars when
|
|
|
|
* writing to a tty (ordinary hash bars otherwise) --claudio
|
|
|
|
*/
|
|
|
|
#define FANCY_HASH
|
|
|
|
|
1999-07-14 23:28:03 +08:00
|
|
|
static int hashesPrinted = 0;
|
|
|
|
|
2000-10-29 02:45:58 +08:00
|
|
|
#ifdef FANCY_HASH
|
|
|
|
static int packagesTotal = 0;
|
|
|
|
static int progressTotal = 0;
|
|
|
|
static int progressCurrent = 0;
|
|
|
|
#endif
|
|
|
|
|
2000-06-19 19:35:29 +08:00
|
|
|
static void printHash(const unsigned long amount, const unsigned long total)
|
|
|
|
{
|
1999-07-14 23:28:03 +08:00
|
|
|
int hashesNeeded;
|
2000-10-29 02:45:58 +08:00
|
|
|
int hashesTotal = 50;
|
1999-07-14 23:28:03 +08:00
|
|
|
|
2000-10-29 02:45:58 +08:00
|
|
|
#ifdef FANCY_HASH
|
|
|
|
if (isatty (STDOUT_FILENO))
|
|
|
|
hashesTotal = 44;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (hashesPrinted != hashesTotal) {
|
|
|
|
hashesNeeded = hashesTotal * (total ? (((float) amount) / total) : 1);
|
1999-07-14 23:28:03 +08:00
|
|
|
while (hashesNeeded > hashesPrinted) {
|
2000-10-29 02:45:58 +08:00
|
|
|
#ifdef FANCY_HASH
|
|
|
|
if (isatty (STDOUT_FILENO)) {
|
|
|
|
int i;
|
|
|
|
for (i = 0; i < hashesPrinted; i++) putchar ('#');
|
|
|
|
for (; i < hashesTotal; i++) putchar (' ');
|
|
|
|
printf ("(%3d%%)", (int)(100 * (total ? (((float) amount) / total) : 1)));
|
|
|
|
for (i = 0; i < (hashesTotal + 6); i++) putchar ('\b');
|
|
|
|
} else
|
|
|
|
#endif
|
|
|
|
fprintf(stdout, "#");
|
|
|
|
|
1999-07-14 23:28:03 +08:00
|
|
|
fflush(stdout);
|
|
|
|
hashesPrinted++;
|
|
|
|
}
|
|
|
|
fflush(stdout);
|
|
|
|
hashesPrinted = hashesNeeded;
|
|
|
|
|
2000-10-29 02:45:58 +08:00
|
|
|
if (hashesPrinted == hashesTotal) {
|
|
|
|
#ifdef FANCY_HASH
|
|
|
|
int i;
|
|
|
|
progressCurrent++;
|
|
|
|
for (i = 1; i < hashesPrinted; i++) putchar ('#');
|
|
|
|
printf (" [%3d%%]\n", (int)(100 * (progressTotal ?
|
|
|
|
(((float) progressCurrent) / progressTotal) : 1)));
|
|
|
|
#else
|
|
|
|
fprintf (stdout, "\n");
|
|
|
|
#endif
|
|
|
|
}
|
1999-07-14 23:28:03 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-01-24 23:58:35 +08:00
|
|
|
/**
|
|
|
|
*/
|
2000-06-19 19:35:29 +08:00
|
|
|
static void * showProgress(const void * arg, const rpmCallbackType what,
|
1999-07-14 23:28:03 +08:00
|
|
|
const unsigned long amount,
|
|
|
|
const unsigned long total,
|
2000-06-19 19:35:29 +08:00
|
|
|
const void * pkgKey, void * data)
|
|
|
|
{
|
|
|
|
Header h = (Header) arg;
|
1999-07-14 23:28:03 +08:00
|
|
|
char * s;
|
2000-05-13 07:12:15 +08:00
|
|
|
int flags = (int) ((long)data);
|
1999-07-14 23:28:03 +08:00
|
|
|
void * rc = NULL;
|
|
|
|
const char * filename = pkgKey;
|
|
|
|
static FD_t fd;
|
|
|
|
|
|
|
|
switch (what) {
|
|
|
|
case RPMCALLBACK_INST_OPEN_FILE:
|
1999-11-10 04:57:38 +08:00
|
|
|
fd = Fopen(filename, "r.ufdio");
|
1999-11-16 07:57:18 +08:00
|
|
|
fd = fdLink(fd, "persist (showProgress)");
|
1999-07-14 23:28:03 +08:00
|
|
|
return fd;
|
|
|
|
|
|
|
|
case RPMCALLBACK_INST_CLOSE_FILE:
|
1999-11-16 07:57:18 +08:00
|
|
|
fd = fdFree(fd, "persist (showProgress)");
|
|
|
|
if (fd) {
|
|
|
|
Fclose(fd);
|
|
|
|
fd = NULL;
|
|
|
|
}
|
1999-07-14 23:28:03 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case RPMCALLBACK_INST_START:
|
|
|
|
hashesPrinted = 0;
|
|
|
|
if (flags & INSTALL_LABEL) {
|
|
|
|
if (flags & INSTALL_HASH) {
|
|
|
|
s = headerSprintf(h, "%{NAME}",
|
|
|
|
rpmTagTable, rpmHeaderFormats, NULL);
|
2000-10-29 02:45:58 +08:00
|
|
|
#ifdef FANCY_HASH
|
|
|
|
if (isatty (STDOUT_FILENO))
|
|
|
|
fprintf(stdout, "%4d:%-23.23s", progressCurrent + 1, s);
|
|
|
|
else
|
|
|
|
#else
|
|
|
|
fprintf(stdout, "%-28s", s);
|
|
|
|
#endif
|
1999-07-14 23:28:03 +08:00
|
|
|
fflush(stdout);
|
|
|
|
} else {
|
|
|
|
s = headerSprintf(h, "%{NAME}-%{VERSION}-%{RELEASE}",
|
|
|
|
rpmTagTable, rpmHeaderFormats, NULL);
|
2000-10-29 02:45:58 +08:00
|
|
|
fprintf(stdout, "%s\n", s);
|
1999-07-14 23:28:03 +08:00
|
|
|
}
|
|
|
|
free(s);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2000-10-29 02:45:58 +08:00
|
|
|
case RPMCALLBACK_TRANS_PROGRESS:
|
1999-07-14 23:28:03 +08:00
|
|
|
case RPMCALLBACK_INST_PROGRESS:
|
|
|
|
if (flags & INSTALL_PERCENT) {
|
|
|
|
fprintf(stdout, "%%%% %f\n", (total
|
|
|
|
? ((float) ((((float) amount) / total) * 100))
|
|
|
|
: 100.0));
|
|
|
|
} else if (flags & INSTALL_HASH) {
|
|
|
|
printHash(amount, total);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case RPMCALLBACK_TRANS_START:
|
2000-10-29 02:45:58 +08:00
|
|
|
hashesPrinted = 0;
|
|
|
|
#ifdef FANCY_HASH
|
|
|
|
progressTotal = 1;
|
|
|
|
progressCurrent = 0;
|
|
|
|
#endif
|
|
|
|
if (flags & INSTALL_LABEL) {
|
|
|
|
if (flags & INSTALL_HASH) {
|
|
|
|
fprintf(stdout, "%-28s", _("Preparing..."));
|
|
|
|
fflush(stdout);
|
|
|
|
} else {
|
|
|
|
printf("%s\n", _("Preparing packages for installation..."));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
1999-07-14 23:28:03 +08:00
|
|
|
case RPMCALLBACK_TRANS_STOP:
|
2000-10-29 02:45:58 +08:00
|
|
|
if (flags & INSTALL_HASH) {
|
|
|
|
printHash(1, 1); /* Fixes "preparing..." progress bar */
|
|
|
|
}
|
|
|
|
#ifdef FANCY_HASH
|
|
|
|
progressTotal = packagesTotal;
|
|
|
|
progressCurrent = 0;
|
|
|
|
#endif
|
|
|
|
break;
|
|
|
|
|
1999-07-14 23:28:03 +08:00
|
|
|
case RPMCALLBACK_UNINST_PROGRESS:
|
|
|
|
case RPMCALLBACK_UNINST_START:
|
|
|
|
case RPMCALLBACK_UNINST_STOP:
|
|
|
|
/* ignore */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2000-09-02 05:15:40 +08:00
|
|
|
/** @todo Generalize --freshen policies. */
|
2000-08-30 06:04:33 +08:00
|
|
|
int rpmInstall(const char * rootdir, const char ** fileArgv,
|
|
|
|
rpmtransFlags transFlags,
|
|
|
|
rpmInstallInterfaceFlags interfaceFlags,
|
|
|
|
rpmprobFilterFlags probFilter,
|
|
|
|
rpmRelocation * relocations)
|
1999-11-27 00:19:30 +08:00
|
|
|
{
|
1999-07-14 23:28:03 +08:00
|
|
|
rpmdb db = NULL;
|
|
|
|
FD_t fd;
|
|
|
|
int i;
|
|
|
|
int mode, rc, major;
|
1999-12-13 01:46:22 +08:00
|
|
|
const char ** pkgURL = NULL;
|
|
|
|
const char ** tmppkgURL = NULL;
|
1999-11-27 00:19:30 +08:00
|
|
|
const char ** fileURL;
|
1999-12-13 01:46:22 +08:00
|
|
|
int numPkgs;
|
|
|
|
int numTmpPkgs = 0, numRPMS = 0, numSRPMS = 0;
|
1999-07-14 23:28:03 +08:00
|
|
|
int numFailed = 0;
|
|
|
|
Header h;
|
|
|
|
int isSource;
|
2001-01-24 23:58:35 +08:00
|
|
|
rpmTransactionSet ts = NULL;
|
1999-07-14 23:28:03 +08:00
|
|
|
int numConflicts;
|
|
|
|
int stopInstall = 0;
|
|
|
|
int notifyFlags = interfaceFlags | (rpmIsVerbose() ? INSTALL_LABEL : 0 );
|
|
|
|
int dbIsOpen = 0;
|
1999-11-27 00:19:30 +08:00
|
|
|
const char ** sourceURL;
|
1999-07-14 23:28:03 +08:00
|
|
|
rpmRelocation * defaultReloc;
|
|
|
|
|
|
|
|
if (transFlags & RPMTRANS_FLAG_TEST)
|
|
|
|
mode = O_RDONLY;
|
|
|
|
else
|
2000-04-27 08:10:28 +08:00
|
|
|
mode = O_RDWR | O_CREAT; /* XXX can't O_EXCL */
|
1999-07-14 23:28:03 +08:00
|
|
|
|
|
|
|
for (defaultReloc = relocations; defaultReloc && defaultReloc->oldPath;
|
|
|
|
defaultReloc++);
|
|
|
|
if (defaultReloc && !defaultReloc->newPath) defaultReloc = NULL;
|
|
|
|
|
|
|
|
rpmMessage(RPMMESS_DEBUG, _("counting packages to install\n"));
|
1999-12-13 01:46:22 +08:00
|
|
|
for (fileURL = fileArgv, numPkgs = 0; *fileURL; fileURL++, numPkgs++)
|
1999-07-14 23:28:03 +08:00
|
|
|
;
|
|
|
|
|
1999-12-13 01:46:22 +08:00
|
|
|
rpmMessage(RPMMESS_DEBUG, _("found %d packages\n"), numPkgs);
|
1999-07-14 23:28:03 +08:00
|
|
|
|
1999-12-13 01:46:22 +08:00
|
|
|
pkgURL = xcalloc( (numPkgs + 1), sizeof(*pkgURL) );
|
|
|
|
tmppkgURL = xcalloc( (numPkgs + 1), sizeof(*tmppkgURL) );
|
1999-07-14 23:28:03 +08:00
|
|
|
|
|
|
|
rpmMessage(RPMMESS_DEBUG, _("looking for packages to download\n"));
|
1999-12-13 01:46:22 +08:00
|
|
|
for (fileURL = fileArgv, i = 0; *fileURL; fileURL++) {
|
1999-07-14 23:28:03 +08:00
|
|
|
|
1999-11-27 00:19:30 +08:00
|
|
|
switch (urlIsURL(*fileURL)) {
|
1999-07-14 23:28:03 +08:00
|
|
|
case URL_IS_FTP:
|
|
|
|
case URL_IS_HTTP:
|
|
|
|
{ int myrc;
|
1999-12-13 01:46:22 +08:00
|
|
|
int j;
|
1999-07-14 23:28:03 +08:00
|
|
|
const char *tfn;
|
1999-12-13 01:46:22 +08:00
|
|
|
const char ** argv;
|
|
|
|
int argc;
|
1999-07-14 23:28:03 +08:00
|
|
|
|
1999-12-13 01:46:22 +08:00
|
|
|
myrc = rpmGlob(*fileURL, &argc, &argv);
|
|
|
|
if (myrc) {
|
|
|
|
rpmMessage(RPMMESS_ERROR,
|
|
|
|
_("skipping %s - rpmGlob failed(%d)\n"),
|
|
|
|
*fileURL, myrc);
|
|
|
|
numFailed++;
|
|
|
|
pkgURL[i] = NULL;
|
|
|
|
break;
|
1999-07-14 23:28:03 +08:00
|
|
|
}
|
1999-12-13 01:46:22 +08:00
|
|
|
if (argc > 1) {
|
|
|
|
numPkgs += argc - 1;
|
|
|
|
pkgURL = xrealloc(pkgURL, (numPkgs + 1) * sizeof(*pkgURL));
|
|
|
|
tmppkgURL = xrealloc(tmppkgURL, (numPkgs + 1) * sizeof(*tmppkgURL));
|
1999-11-27 00:19:30 +08:00
|
|
|
}
|
1999-07-14 23:28:03 +08:00
|
|
|
|
1999-12-13 01:46:22 +08:00
|
|
|
for (j = 0; j < argc; j++) {
|
|
|
|
|
|
|
|
if (rpmIsVerbose())
|
|
|
|
fprintf(stdout, _("Retrieving %s\n"), argv[j]);
|
|
|
|
|
|
|
|
{ char tfnbuf[64];
|
|
|
|
strcpy(tfnbuf, "rpm-xfer.XXXXXX");
|
|
|
|
/*@-unrecog@*/ mktemp(tfnbuf) /*@=unrecog@*/;
|
|
|
|
tfn = rpmGenPath(rootdir, "%{_tmppath}/", tfnbuf);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* XXX undefined %{name}/%{version}/%{release} here */
|
|
|
|
/* XXX %{_tmpdir} does not exist */
|
|
|
|
rpmMessage(RPMMESS_DEBUG, _(" ... as %s\n"), tfn);
|
|
|
|
myrc = urlGetFile(argv[j], tfn);
|
|
|
|
if (myrc < 0) {
|
|
|
|
rpmMessage(RPMMESS_ERROR,
|
1999-07-14 23:28:03 +08:00
|
|
|
_("skipping %s - transfer failed - %s\n"),
|
1999-12-13 01:46:22 +08:00
|
|
|
argv[j], ftpStrerror(myrc));
|
|
|
|
numFailed++;
|
|
|
|
pkgURL[i] = NULL;
|
2000-12-13 04:03:45 +08:00
|
|
|
free((void *)tfn);
|
1999-12-13 01:46:22 +08:00
|
|
|
} else {
|
|
|
|
tmppkgURL[numTmpPkgs++] = pkgURL[i++] = tfn;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (argv) {
|
|
|
|
for (j = 0; j < argc; j++)
|
2000-12-13 04:03:45 +08:00
|
|
|
free((void *)argv[j]);
|
|
|
|
free((void *)argv);
|
1999-12-13 01:46:22 +08:00
|
|
|
argv = NULL;
|
1999-07-14 23:28:03 +08:00
|
|
|
}
|
|
|
|
} break;
|
1999-11-27 00:19:30 +08:00
|
|
|
case URL_IS_PATH:
|
1999-07-14 23:28:03 +08:00
|
|
|
default:
|
1999-11-27 00:19:30 +08:00
|
|
|
pkgURL[i++] = *fileURL;
|
1999-07-14 23:28:03 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
1999-12-14 03:27:34 +08:00
|
|
|
pkgURL[i] = NULL;
|
|
|
|
tmppkgURL[numTmpPkgs] = NULL;
|
1999-07-14 23:28:03 +08:00
|
|
|
|
1999-11-27 00:19:30 +08:00
|
|
|
sourceURL = alloca(sizeof(*sourceURL) * i);
|
1999-07-14 23:28:03 +08:00
|
|
|
|
1999-12-13 01:46:22 +08:00
|
|
|
rpmMessage(RPMMESS_DEBUG, _("retrieved %d packages\n"), numTmpPkgs);
|
1999-07-14 23:28:03 +08:00
|
|
|
|
2000-08-30 06:04:33 +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.
|
|
|
|
*/
|
1999-11-27 00:19:30 +08:00
|
|
|
for (fileURL = pkgURL; *fileURL; fileURL++) {
|
|
|
|
const char * fileName;
|
|
|
|
(void) urlPath(*fileURL, &fileName);
|
|
|
|
fd = Fopen(*fileURL, "r.ufdio");
|
1999-12-13 01:46:22 +08:00
|
|
|
if (fd == NULL || Ferror(fd)) {
|
1999-11-27 00:19:30 +08:00
|
|
|
rpmMessage(RPMMESS_ERROR, _("cannot open file %s: %s\n"), *fileURL,
|
1999-11-11 06:09:49 +08:00
|
|
|
Fstrerror(fd));
|
1999-12-13 01:46:22 +08:00
|
|
|
if (fd) Fclose(fd);
|
1999-07-14 23:28:03 +08:00
|
|
|
numFailed++;
|
1999-11-27 00:19:30 +08:00
|
|
|
pkgURL[i] = NULL;
|
1999-07-14 23:28:03 +08:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
rc = rpmReadPackageHeader(fd, &h, &isSource, &major, NULL);
|
|
|
|
|
|
|
|
switch (rc) {
|
|
|
|
case 1:
|
1999-10-28 07:18:10 +08:00
|
|
|
Fclose(fd);
|
1999-07-14 23:28:03 +08:00
|
|
|
rpmMessage(RPMMESS_ERROR,
|
|
|
|
_("%s does not appear to be a RPM package\n"),
|
1999-11-27 00:19:30 +08:00
|
|
|
*fileURL);
|
1999-07-14 23:28:03 +08:00
|
|
|
break;
|
|
|
|
default:
|
1999-11-27 00:19:30 +08:00
|
|
|
rpmMessage(RPMMESS_ERROR, _("%s cannot be installed\n"), *fileURL);
|
1999-07-14 23:28:03 +08:00
|
|
|
numFailed++;
|
1999-11-27 00:19:30 +08:00
|
|
|
pkgURL[i] = NULL;
|
1999-07-14 23:28:03 +08:00
|
|
|
break;
|
|
|
|
case 0:
|
|
|
|
if (isSource) {
|
1999-12-13 01:46:22 +08:00
|
|
|
sourceURL[numSRPMS++] = fileName;
|
1999-10-28 07:18:10 +08:00
|
|
|
Fclose(fd);
|
1999-07-14 23:28:03 +08:00
|
|
|
} else {
|
|
|
|
if (!dbIsOpen) {
|
|
|
|
if (rpmdbOpen(rootdir, &db, mode, 0644)) {
|
|
|
|
const char *dn;
|
|
|
|
dn = rpmGetPath( (rootdir ? rootdir : ""),
|
|
|
|
"%{_dbpath}", NULL);
|
|
|
|
rpmMessage(RPMMESS_ERROR,
|
2000-07-12 12:02:35 +08:00
|
|
|
_("cannot open Packages database in %s\n"), dn);
|
2000-12-13 04:03:45 +08:00
|
|
|
free((void *)dn);
|
2001-01-04 04:19:27 +08:00
|
|
|
numFailed++;
|
|
|
|
pkgURL[i] = NULL;
|
|
|
|
break;
|
1999-07-14 23:28:03 +08:00
|
|
|
}
|
2001-01-24 23:58:35 +08:00
|
|
|
ts = rpmtransCreateSet(db, rootdir);
|
1999-07-14 23:28:03 +08:00
|
|
|
dbIsOpen = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (defaultReloc) {
|
1999-12-13 01:46:22 +08:00
|
|
|
const char ** paths;
|
1999-07-14 23:28:03 +08:00
|
|
|
int c;
|
|
|
|
|
|
|
|
if (headerGetEntry(h, RPMTAG_PREFIXES, NULL,
|
|
|
|
(void **) &paths, &c) && (c == 1)) {
|
1999-09-21 11:22:53 +08:00
|
|
|
defaultReloc->oldPath = xstrdup(paths[0]);
|
2000-12-13 04:03:45 +08:00
|
|
|
free((void *)paths);
|
1999-07-14 23:28:03 +08:00
|
|
|
} else {
|
1999-12-13 01:46:22 +08:00
|
|
|
const char * name;
|
|
|
|
headerNVR(h, &name, NULL, NULL);
|
1999-07-14 23:28:03 +08:00
|
|
|
rpmMessage(RPMMESS_ERROR,
|
|
|
|
_("package %s is not relocateable\n"), name);
|
|
|
|
|
1999-12-13 01:46:22 +08:00
|
|
|
goto errxit;
|
|
|
|
/*@notreached@*/
|
1999-07-14 23:28:03 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-07-12 12:02:35 +08:00
|
|
|
/* On --freshen, verify package is installed and newer */
|
2000-06-23 08:49:43 +08:00
|
|
|
if (interfaceFlags & INSTALL_FRESHEN) {
|
2000-07-12 12:02:35 +08:00
|
|
|
rpmdbMatchIterator mi;
|
2000-06-23 08:49:43 +08:00
|
|
|
const char * name;
|
2000-07-12 12:02:35 +08:00
|
|
|
Header oldH;
|
|
|
|
int count;
|
2000-06-23 08:49:43 +08:00
|
|
|
|
|
|
|
headerNVR(h, &name, NULL, NULL);
|
2000-07-12 12:02:35 +08:00
|
|
|
mi = rpmdbInitIterator(db, RPMTAG_NAME, name, 0);
|
|
|
|
count = rpmdbGetIteratorCount(mi);
|
|
|
|
while ((oldH = rpmdbNextIterator(mi)) != NULL) {
|
|
|
|
if (rpmVersionCompare(oldH, h) < 0)
|
|
|
|
continue;
|
|
|
|
/* same or newer package already installed */
|
|
|
|
count = 0;
|
2000-06-23 08:49:43 +08:00
|
|
|
break;
|
2000-07-12 12:02:35 +08:00
|
|
|
}
|
|
|
|
rpmdbFreeIterator(mi);
|
|
|
|
if (count == 0) {
|
|
|
|
headerFree(h);
|
|
|
|
Fclose(fd);
|
|
|
|
break; /* XXX out of switch */
|
|
|
|
}
|
|
|
|
/* Package is newer than those currently installed. */
|
2000-06-23 08:49:43 +08:00
|
|
|
}
|
|
|
|
|
2001-01-24 23:58:35 +08:00
|
|
|
rc = rpmtransAddPackage(ts, h, NULL, fileName,
|
1999-07-14 23:28:03 +08:00
|
|
|
(interfaceFlags & INSTALL_UPGRADE) != 0,
|
|
|
|
relocations);
|
1999-09-21 11:22:53 +08:00
|
|
|
|
|
|
|
headerFree(h); /* XXX reference held by transaction set */
|
1999-10-28 07:18:10 +08:00
|
|
|
Fclose(fd);
|
1999-09-21 11:22:53 +08:00
|
|
|
|
|
|
|
switch(rc) {
|
|
|
|
case 0:
|
|
|
|
break;
|
|
|
|
case 1:
|
1999-07-14 23:28:03 +08:00
|
|
|
rpmMessage(RPMMESS_ERROR,
|
1999-11-27 00:19:30 +08:00
|
|
|
_("error reading from file %s\n"), *fileURL);
|
1999-12-13 01:46:22 +08:00
|
|
|
goto errxit;
|
1999-09-21 11:22:53 +08:00
|
|
|
/*@notreached@*/ break;
|
|
|
|
case 2:
|
1999-07-14 23:28:03 +08:00
|
|
|
rpmMessage(RPMMESS_ERROR,
|
|
|
|
_("file %s requires a newer version of RPM\n"),
|
1999-11-27 00:19:30 +08:00
|
|
|
*fileURL);
|
1999-12-13 01:46:22 +08:00
|
|
|
goto errxit;
|
1999-09-21 11:22:53 +08:00
|
|
|
/*@notreached@*/ break;
|
1999-07-14 23:28:03 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (defaultReloc) {
|
2000-12-13 04:03:45 +08:00
|
|
|
free((void *)defaultReloc->oldPath);
|
1999-07-14 23:28:03 +08:00
|
|
|
defaultReloc->oldPath = NULL;
|
|
|
|
}
|
|
|
|
|
1999-12-13 01:46:22 +08:00
|
|
|
numRPMS++;
|
1999-07-14 23:28:03 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
rpmMessage(RPMMESS_DEBUG, _("found %d source and %d binary packages\n"),
|
1999-12-13 01:46:22 +08:00
|
|
|
numSRPMS, numRPMS);
|
1999-07-14 23:28:03 +08:00
|
|
|
|
1999-12-13 01:46:22 +08:00
|
|
|
if (numRPMS && !(interfaceFlags & INSTALL_NODEPS)) {
|
1999-09-18 06:02:44 +08:00
|
|
|
struct rpmDependencyConflict * conflicts;
|
2001-01-24 23:58:35 +08:00
|
|
|
if (rpmdepCheck(ts, &conflicts, &numConflicts)) {
|
1999-12-13 01:46:22 +08:00
|
|
|
numFailed = numPkgs;
|
1999-07-14 23:28:03 +08:00
|
|
|
stopInstall = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!stopInstall && conflicts) {
|
|
|
|
rpmMessage(RPMMESS_ERROR, _("failed dependencies:\n"));
|
|
|
|
printDepProblems(stderr, conflicts, numConflicts);
|
|
|
|
rpmdepFreeConflicts(conflicts, numConflicts);
|
1999-12-13 01:46:22 +08:00
|
|
|
numFailed = numPkgs;
|
1999-07-14 23:28:03 +08:00
|
|
|
stopInstall = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-12-13 01:46:22 +08:00
|
|
|
if (numRPMS && !(interfaceFlags & INSTALL_NOORDER)) {
|
2001-01-24 23:58:35 +08:00
|
|
|
if (rpmdepOrder(ts)) {
|
1999-12-13 01:46:22 +08:00
|
|
|
numFailed = numPkgs;
|
1999-07-14 23:28:03 +08:00
|
|
|
stopInstall = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-12-13 01:46:22 +08:00
|
|
|
if (numRPMS && !stopInstall) {
|
1999-07-14 23:28:03 +08:00
|
|
|
rpmProblemSet probs = NULL;
|
2000-10-29 02:45:58 +08:00
|
|
|
|
|
|
|
#ifdef FANCY_HASH
|
|
|
|
packagesTotal = numRPMS;
|
|
|
|
#endif
|
1999-07-14 23:28:03 +08:00
|
|
|
rpmMessage(RPMMESS_DEBUG, _("installing binary packages\n"));
|
2001-01-24 23:58:35 +08:00
|
|
|
rc = rpmRunTransactions(ts, showProgress, (void *) ((long)notifyFlags),
|
1999-07-14 23:28:03 +08:00
|
|
|
NULL, &probs, transFlags, probFilter);
|
|
|
|
|
|
|
|
if (rc < 0) {
|
1999-12-13 01:46:22 +08:00
|
|
|
numFailed += numRPMS;
|
|
|
|
} else if (rc > 0) {
|
1999-07-14 23:28:03 +08:00
|
|
|
numFailed += rc;
|
|
|
|
rpmProblemSetPrint(stderr, probs);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (probs) rpmProblemSetFree(probs);
|
|
|
|
}
|
|
|
|
|
2001-01-24 23:58:35 +08:00
|
|
|
if (numRPMS) rpmtransFree(ts);
|
1999-07-14 23:28:03 +08:00
|
|
|
|
1999-12-13 01:46:22 +08:00
|
|
|
if (numSRPMS && !stopInstall) {
|
|
|
|
for (i = 0; i < numSRPMS; i++) {
|
1999-11-27 00:19:30 +08:00
|
|
|
fd = Fopen(sourceURL[i], "r.ufdio");
|
1999-12-13 01:46:22 +08:00
|
|
|
if (fd == NULL || Ferror(fd)) {
|
1999-11-11 06:09:49 +08:00
|
|
|
rpmMessage(RPMMESS_ERROR, _("cannot open file %s: %s\n"),
|
1999-11-27 00:19:30 +08:00
|
|
|
sourceURL[i], Fstrerror(fd));
|
1999-12-13 01:46:22 +08:00
|
|
|
if (fd) Fclose(fd);
|
1999-07-14 23:28:03 +08:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(transFlags & RPMTRANS_FLAG_TEST))
|
|
|
|
numFailed += rpmInstallSourcePackage(rootdir, fd, NULL,
|
2000-05-13 07:12:15 +08:00
|
|
|
showProgress, (void *) ((long)notifyFlags), NULL);
|
1999-07-14 23:28:03 +08:00
|
|
|
|
1999-10-28 07:18:10 +08:00
|
|
|
Fclose(fd);
|
1999-07-14 23:28:03 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-12-13 01:46:22 +08:00
|
|
|
for (i = 0; i < numTmpPkgs; i++) {
|
1999-11-27 00:19:30 +08:00
|
|
|
Unlink(tmppkgURL[i]);
|
2000-12-13 04:03:45 +08:00
|
|
|
free((void *)tmppkgURL[i]);
|
1999-07-14 23:28:03 +08:00
|
|
|
}
|
2000-12-13 04:03:45 +08:00
|
|
|
free((void *)tmppkgURL); tmppkgURL = NULL;
|
|
|
|
free((void *)pkgURL); pkgURL = NULL;
|
1999-07-14 23:28:03 +08:00
|
|
|
|
|
|
|
/* FIXME how do we close our various fd's? */
|
|
|
|
|
|
|
|
if (dbIsOpen) rpmdbClose(db);
|
|
|
|
|
|
|
|
return numFailed;
|
1999-12-13 01:46:22 +08:00
|
|
|
|
|
|
|
errxit:
|
|
|
|
if (tmppkgURL) {
|
|
|
|
for (i = 0; i < numTmpPkgs; i++)
|
2000-12-13 04:03:45 +08:00
|
|
|
free((void *)tmppkgURL[i]);
|
|
|
|
free((void *)tmppkgURL);
|
1999-12-13 01:46:22 +08:00
|
|
|
}
|
|
|
|
if (pkgURL)
|
2000-12-13 04:03:45 +08:00
|
|
|
free((void *)pkgURL);
|
1999-12-13 01:46:22 +08:00
|
|
|
if (dbIsOpen) rpmdbClose(db);
|
|
|
|
return numPkgs;
|
1999-07-14 23:28:03 +08:00
|
|
|
}
|
|
|
|
|
2000-08-30 06:04:33 +08:00
|
|
|
int rpmErase(const char * rootdir, const char ** argv,
|
|
|
|
rpmtransFlags transFlags,
|
|
|
|
rpmEraseInterfaceFlags interfaceFlags)
|
2000-03-23 23:49:50 +08:00
|
|
|
{
|
1999-07-14 23:28:03 +08:00
|
|
|
rpmdb db;
|
|
|
|
int mode;
|
|
|
|
int count;
|
|
|
|
const char ** arg;
|
|
|
|
int numFailed = 0;
|
2001-01-24 23:58:35 +08:00
|
|
|
rpmTransactionSet ts;
|
1999-07-14 23:28:03 +08:00
|
|
|
struct rpmDependencyConflict * conflicts;
|
|
|
|
int numConflicts;
|
|
|
|
int stopUninstall = 0;
|
|
|
|
int numPackages = 0;
|
|
|
|
rpmProblemSet probs;
|
|
|
|
|
|
|
|
if (transFlags & RPMTRANS_FLAG_TEST)
|
|
|
|
mode = O_RDONLY;
|
|
|
|
else
|
|
|
|
mode = O_RDWR | O_EXCL;
|
|
|
|
|
|
|
|
if (rpmdbOpen(rootdir, &db, mode, 0644)) {
|
|
|
|
const char *dn;
|
|
|
|
dn = rpmGetPath( (rootdir ? rootdir : ""), "%{_dbpath}", NULL);
|
|
|
|
rpmMessage(RPMMESS_ERROR, _("cannot open %s/packages.rpm\n"), dn);
|
2000-12-13 04:03:45 +08:00
|
|
|
free((void *)dn);
|
2001-01-04 04:19:27 +08:00
|
|
|
return -1;
|
1999-07-14 23:28:03 +08:00
|
|
|
}
|
|
|
|
|
2001-01-24 23:58:35 +08:00
|
|
|
ts = rpmtransCreateSet(db, rootdir);
|
1999-07-14 23:28:03 +08:00
|
|
|
for (arg = argv; *arg; arg++) {
|
2000-04-27 08:10:28 +08:00
|
|
|
rpmdbMatchIterator mi;
|
|
|
|
|
|
|
|
/* XXX HACK to get rpmdbFindByLabel out of the API */
|
|
|
|
mi = rpmdbInitIterator(db, RPMDBI_LABEL, *arg, 0);
|
|
|
|
count = rpmdbGetIteratorCount(mi);
|
|
|
|
if (count <= 0) {
|
|
|
|
rpmMessage(RPMMESS_ERROR, _("package %s is not installed\n"), *arg);
|
|
|
|
numFailed++;
|
|
|
|
} else if (!(count == 1 || (interfaceFlags & UNINSTALL_ALLMATCHES))) {
|
|
|
|
rpmMessage(RPMMESS_ERROR, _("\"%s\" specifies multiple packages\n"),
|
|
|
|
*arg);
|
|
|
|
numFailed++;
|
|
|
|
} else {
|
|
|
|
Header h; /* XXX iterator owns the reference */
|
|
|
|
while ((h = rpmdbNextIterator(mi)) != NULL) {
|
|
|
|
unsigned int recOffset = rpmdbGetIteratorOffset(mi);
|
|
|
|
if (recOffset) {
|
2001-01-24 23:58:35 +08:00
|
|
|
rpmtransRemovePackage(ts, recOffset);
|
2000-04-27 08:10:28 +08:00
|
|
|
numPackages++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
rpmdbFreeIterator(mi);
|
1999-07-14 23:28:03 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!(interfaceFlags & UNINSTALL_NODEPS)) {
|
2001-01-24 23:58:35 +08:00
|
|
|
if (rpmdepCheck(ts, &conflicts, &numConflicts)) {
|
1999-07-14 23:28:03 +08:00
|
|
|
numFailed = numPackages;
|
|
|
|
stopUninstall = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!stopUninstall && conflicts) {
|
|
|
|
rpmMessage(RPMMESS_ERROR, _("removing these packages would break "
|
|
|
|
"dependencies:\n"));
|
|
|
|
printDepProblems(stderr, conflicts, numConflicts);
|
|
|
|
rpmdepFreeConflicts(conflicts, numConflicts);
|
|
|
|
numFailed += numPackages;
|
|
|
|
stopUninstall = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!stopUninstall) {
|
2001-01-24 23:58:35 +08:00
|
|
|
numFailed += rpmRunTransactions(ts, NULL, NULL, NULL, &probs,
|
1999-07-14 23:28:03 +08:00
|
|
|
transFlags, 0);
|
|
|
|
}
|
|
|
|
|
2001-01-24 23:58:35 +08:00
|
|
|
rpmtransFree(ts);
|
1999-07-14 23:28:03 +08:00
|
|
|
rpmdbClose(db);
|
|
|
|
|
|
|
|
return numFailed;
|
|
|
|
}
|
|
|
|
|
2000-08-30 06:04:33 +08:00
|
|
|
int rpmInstallSource(const char * rootdir, const char * arg,
|
|
|
|
const char ** specFile, char ** cookie)
|
2000-06-19 19:35:29 +08:00
|
|
|
{
|
1999-07-14 23:28:03 +08:00
|
|
|
FD_t fd;
|
|
|
|
int rc;
|
|
|
|
|
1999-11-05 05:26:08 +08:00
|
|
|
fd = Fopen(arg, "r.ufdio");
|
1999-12-13 01:46:22 +08:00
|
|
|
if (fd == NULL || Ferror(fd)) {
|
1999-11-11 06:09:49 +08:00
|
|
|
rpmMessage(RPMMESS_ERROR, _("cannot open %s: %s\n"), arg, Fstrerror(fd));
|
1999-12-13 01:46:22 +08:00
|
|
|
if (fd) Fclose(fd);
|
1999-07-14 23:28:03 +08:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (rpmIsVerbose())
|
|
|
|
fprintf(stdout, _("Installing %s\n"), arg);
|
|
|
|
|
|
|
|
rc = rpmInstallSourcePackage(rootdir, fd, specFile, NULL, NULL,
|
|
|
|
cookie);
|
|
|
|
if (rc == 1) {
|
|
|
|
rpmMessage(RPMMESS_ERROR, _("%s cannot be installed\n"), arg);
|
2000-03-23 23:49:50 +08:00
|
|
|
if (specFile && *specFile) {
|
2000-12-13 04:03:45 +08:00
|
|
|
free((void *)*specFile);
|
2000-03-23 23:49:50 +08:00
|
|
|
*specFile = NULL;
|
|
|
|
}
|
|
|
|
if (cookie && *cookie) {
|
|
|
|
free(*cookie);
|
|
|
|
*cookie = NULL;
|
|
|
|
}
|
1999-07-14 23:28:03 +08:00
|
|
|
}
|
|
|
|
|
1999-10-28 07:18:10 +08:00
|
|
|
Fclose(fd);
|
1999-07-14 23:28:03 +08:00
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|