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"
|
|
|
|
|
1999-07-14 23:28:03 +08:00
|
|
|
static int hashesPrinted = 0;
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
if (hashesPrinted != 50) {
|
|
|
|
hashesNeeded = 50 * (total ? (((float) amount) / total) : 1);
|
|
|
|
while (hashesNeeded > hashesPrinted) {
|
|
|
|
printf("#");
|
|
|
|
fflush(stdout);
|
|
|
|
hashesPrinted++;
|
|
|
|
}
|
|
|
|
fflush(stdout);
|
|
|
|
hashesPrinted = hashesNeeded;
|
|
|
|
|
|
|
|
if (hashesPrinted == 50)
|
|
|
|
fprintf(stdout, "\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
printf("%-28s", s);
|
|
|
|
fflush(stdout);
|
|
|
|
} else {
|
|
|
|
s = headerSprintf(h, "%{NAME}-%{VERSION}-%{RELEASE}",
|
|
|
|
rpmTagTable, rpmHeaderFormats, NULL);
|
|
|
|
printf("%s\n", s);
|
|
|
|
}
|
|
|
|
free(s);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
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_PROGRESS:
|
|
|
|
case RPMCALLBACK_TRANS_START:
|
|
|
|
case RPMCALLBACK_TRANS_STOP:
|
|
|
|
case RPMCALLBACK_UNINST_PROGRESS:
|
|
|
|
case RPMCALLBACK_UNINST_START:
|
|
|
|
case RPMCALLBACK_UNINST_STOP:
|
|
|
|
/* ignore */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
1999-12-13 01:46:22 +08:00
|
|
|
int rpmInstall(const char * rootdir, const char ** fileArgv, int transFlags,
|
1999-07-14 23:28:03 +08:00
|
|
|
int interfaceFlags, int probFilter,
|
1999-11-27 00:19:30 +08:00
|
|
|
rpmRelocation * relocations)
|
|
|
|
{
|
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;
|
|
|
|
rpmTransactionSet rpmdep = NULL;
|
|
|
|
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;
|
|
|
|
xfree(tfn);
|
|
|
|
} else {
|
|
|
|
tmppkgURL[numTmpPkgs++] = pkgURL[i++] = tfn;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (argv) {
|
|
|
|
for (j = 0; j < argc; j++)
|
|
|
|
xfree(argv[j]);
|
|
|
|
xfree(argv);
|
|
|
|
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
|
|
|
|
|
|
|
/* 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);
|
1999-07-14 23:28:03 +08:00
|
|
|
xfree(dn);
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
rpmdep = rpmtransCreateSet(db, rootdir);
|
|
|
|
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]);
|
1999-12-13 01:46:22 +08:00
|
|
|
xfree(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
|
|
|
}
|
|
|
|
|
1999-11-27 00:19:30 +08:00
|
|
|
rc = rpmtransAddPackage(rpmdep, 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) {
|
1999-08-07 06:52:49 +08:00
|
|
|
xfree(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;
|
1999-07-14 23:28:03 +08:00
|
|
|
if (rpmdepCheck(rpmdep, &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)) {
|
1999-07-14 23:28:03 +08:00
|
|
|
if (rpmdepOrder(rpmdep)) {
|
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;
|
|
|
|
;
|
|
|
|
rpmMessage(RPMMESS_DEBUG, _("installing binary packages\n"));
|
2000-05-13 07:12:15 +08:00
|
|
|
rc = rpmRunTransactions(rpmdep, 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);
|
|
|
|
}
|
|
|
|
|
1999-12-13 01:46:22 +08:00
|
|
|
if (numRPMS) rpmtransFree(rpmdep);
|
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]);
|
|
|
|
xfree(tmppkgURL[i]);
|
1999-07-14 23:28:03 +08:00
|
|
|
}
|
2000-03-23 23:49:50 +08:00
|
|
|
xfree(tmppkgURL); tmppkgURL = NULL;
|
|
|
|
xfree(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++)
|
|
|
|
xfree(tmppkgURL[i]);
|
|
|
|
xfree(tmppkgURL);
|
|
|
|
}
|
|
|
|
if (pkgURL)
|
|
|
|
xfree(pkgURL);
|
|
|
|
if (dbIsOpen) rpmdbClose(db);
|
|
|
|
return numPkgs;
|
1999-07-14 23:28:03 +08:00
|
|
|
}
|
|
|
|
|
1999-07-14 23:43:30 +08:00
|
|
|
int rpmErase(const char * rootdir, const char ** argv, int transFlags,
|
2000-03-23 23:49:50 +08:00
|
|
|
int interfaceFlags)
|
|
|
|
{
|
1999-07-14 23:28:03 +08:00
|
|
|
rpmdb db;
|
|
|
|
int mode;
|
|
|
|
int count;
|
|
|
|
const char ** arg;
|
|
|
|
int numFailed = 0;
|
|
|
|
rpmTransactionSet rpmdep;
|
|
|
|
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);
|
|
|
|
xfree(dn);
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
|
|
|
|
rpmdep = rpmtransCreateSet(db, rootdir);
|
|
|
|
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) {
|
|
|
|
rpmtransRemovePackage(rpmdep, recOffset);
|
|
|
|
numPackages++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
rpmdbFreeIterator(mi);
|
1999-07-14 23:28:03 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!(interfaceFlags & UNINSTALL_NODEPS)) {
|
|
|
|
if (rpmdepCheck(rpmdep, &conflicts, &numConflicts)) {
|
|
|
|
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) {
|
|
|
|
numFailed += rpmRunTransactions(rpmdep, NULL, NULL, NULL, &probs,
|
|
|
|
transFlags, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
rpmtransFree(rpmdep);
|
|
|
|
rpmdbClose(db);
|
|
|
|
|
|
|
|
return numFailed;
|
|
|
|
}
|
|
|
|
|
1999-07-14 23:43:30 +08:00
|
|
|
int rpmInstallSource(const char * rootdir, const char * arg, const char ** specFile,
|
2000-06-19 19:35:29 +08:00
|
|
|
char ** cookie)
|
|
|
|
{
|
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) {
|
|
|
|
xfree(*specFile);
|
|
|
|
*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;
|
|
|
|
}
|