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"
|
|
|
|
|
2001-06-09 04:45:59 +08:00
|
|
|
#include <rpmcli.h>
|
1999-07-14 23:28:03 +08:00
|
|
|
|
2001-04-10 20:36:45 +08:00
|
|
|
#include "manifest.h"
|
2001-06-18 06:18:03 +08:00
|
|
|
#include "misc.h" /* XXX for rpmGlob() */
|
2000-12-13 04:03:45 +08:00
|
|
|
#include "debug.h"
|
1999-12-13 01:46:22 +08:00
|
|
|
|
2001-07-07 04:37:42 +08:00
|
|
|
/*@access rpmTransactionSet @*/ /* XXX compared with NULL */
|
|
|
|
/*@access rpmProblemSet @*/ /* XXX compared with NULL */
|
|
|
|
/*@access Header @*/ /* XXX compared with NULL */
|
|
|
|
/*@access FD_t @*/ /* XXX compared with NULL */
|
|
|
|
/*@access IDTX @*/
|
|
|
|
/*@access IDT @*/
|
2000-10-29 01:16:25 +08:00
|
|
|
|
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
|
2001-07-07 04:37:42 +08:00
|
|
|
int packagesTotal = 0;
|
2000-10-29 02:45:58 +08:00
|
|
|
static int progressTotal = 0;
|
|
|
|
static int progressCurrent = 0;
|
|
|
|
#endif
|
|
|
|
|
2001-03-24 04:27:48 +08:00
|
|
|
/**
|
|
|
|
*/
|
2000-06-19 19:35:29 +08:00
|
|
|
static void printHash(const unsigned long amount, const unsigned long total)
|
2001-06-06 03:26:22 +08:00
|
|
|
/*@modifies fileSystem @*/
|
2000-06-19 19:35:29 +08:00
|
|
|
{
|
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))
|
2001-01-25 20:58:03 +08:00
|
|
|
hashesTotal = 44;
|
2000-10-29 02:45:58 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
if (hashesPrinted != hashesTotal) {
|
2001-01-25 20:58:03 +08:00
|
|
|
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
|
2001-01-25 20:58:03 +08:00
|
|
|
if (isatty (STDOUT_FILENO)) {
|
|
|
|
int i;
|
2001-05-01 06:32:22 +08:00
|
|
|
for (i = 0; i < hashesPrinted; i++) (void) putchar ('#');
|
|
|
|
for (; i < hashesTotal; i++) (void) putchar (' ');
|
2001-01-25 20:58:03 +08:00
|
|
|
printf ("(%3d%%)",
|
|
|
|
(int)(100 * (total ? (((float) amount) / total) : 1)));
|
2001-05-01 06:32:22 +08:00
|
|
|
for (i = 0; i < (hashesTotal + 6); i++) (void) putchar ('\b');
|
2001-01-25 20:58:03 +08:00
|
|
|
} else
|
2000-10-29 02:45:58 +08:00
|
|
|
#endif
|
2001-01-25 20:58:03 +08:00
|
|
|
fprintf(stdout, "#");
|
2000-10-29 02:45:58 +08:00
|
|
|
|
1999-07-14 23:28:03 +08:00
|
|
|
hashesPrinted++;
|
|
|
|
}
|
2001-05-01 06:32:22 +08:00
|
|
|
(void) fflush(stdout);
|
1999-07-14 23:28:03 +08:00
|
|
|
hashesPrinted = hashesNeeded;
|
|
|
|
|
2001-01-25 20:58:03 +08:00
|
|
|
if (hashesPrinted == hashesTotal) {
|
2000-10-29 02:45:58 +08:00
|
|
|
#ifdef FANCY_HASH
|
2001-01-25 20:58:03 +08:00
|
|
|
int i;
|
|
|
|
progressCurrent++;
|
2001-05-01 06:32:22 +08:00
|
|
|
for (i = 1; i < hashesPrinted; i++) (void) putchar ('#');
|
2001-01-25 20:58:03 +08:00
|
|
|
printf (" [%3d%%]\n", (int)(100 * (progressTotal ?
|
|
|
|
(((float) progressCurrent) / progressTotal) : 1)));
|
2000-10-29 02:45:58 +08:00
|
|
|
#else
|
2001-01-25 20:58:03 +08:00
|
|
|
fprintf (stdout, "\n");
|
2000-10-29 02:45:58 +08:00
|
|
|
#endif
|
2001-01-25 20:58:03 +08:00
|
|
|
}
|
2001-05-01 06:32:22 +08:00
|
|
|
(void) fflush(stdout);
|
1999-07-14 23:28:03 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-07-07 04:37:42 +08:00
|
|
|
void * rpmShowProgress(/*@null@*/ const void * arg,
|
|
|
|
const rpmCallbackType what,
|
2001-05-04 05:00:18 +08:00
|
|
|
const unsigned long amount,
|
|
|
|
const unsigned long total,
|
|
|
|
/*@null@*/ const void * pkgKey,
|
|
|
|
/*@null@*/ void * data)
|
2001-06-06 03:26:22 +08:00
|
|
|
/*@modifies fileSystem @*/
|
2000-06-19 19:35:29 +08:00
|
|
|
{
|
2001-06-06 03:26:22 +08:00
|
|
|
/*@-castexpose@*/
|
2000-06-19 19:35:29 +08:00
|
|
|
Header h = (Header) arg;
|
2001-06-06 03:26:22 +08:00
|
|
|
/*@=castexpose@*/
|
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;
|
2001-05-04 05:00:18 +08:00
|
|
|
static FD_t fd = NULL;
|
1999-07-14 23:28:03 +08:00
|
|
|
|
|
|
|
switch (what) {
|
2001-01-25 20:58:03 +08:00
|
|
|
case RPMCALLBACK_INST_OPEN_FILE:
|
2001-05-04 05:00:18 +08:00
|
|
|
if (filename == NULL || filename[0] == '\0')
|
|
|
|
return NULL;
|
1999-11-10 04:57:38 +08:00
|
|
|
fd = Fopen(filename, "r.ufdio");
|
2001-01-25 20:58:03 +08:00
|
|
|
if (fd)
|
|
|
|
fd = fdLink(fd, "persist (showProgress)");
|
1999-07-14 23:28:03 +08:00
|
|
|
return fd;
|
2001-01-25 20:58:03 +08:00
|
|
|
/*@notreached@*/ break;
|
1999-07-14 23:28:03 +08:00
|
|
|
|
2001-01-25 20:58:03 +08:00
|
|
|
case RPMCALLBACK_INST_CLOSE_FILE:
|
1999-11-16 07:57:18 +08:00
|
|
|
fd = fdFree(fd, "persist (showProgress)");
|
|
|
|
if (fd) {
|
2001-05-01 06:32:22 +08:00
|
|
|
(void) Fclose(fd);
|
1999-11-16 07:57:18 +08:00
|
|
|
fd = NULL;
|
|
|
|
}
|
1999-07-14 23:28:03 +08:00
|
|
|
break;
|
|
|
|
|
2001-01-25 20:58:03 +08:00
|
|
|
case RPMCALLBACK_INST_START:
|
1999-07-14 23:28:03 +08:00
|
|
|
hashesPrinted = 0;
|
2001-05-04 05:00:18 +08:00
|
|
|
if (h == NULL || !(flags & INSTALL_LABEL))
|
2001-01-25 20:58:03 +08:00
|
|
|
break;
|
|
|
|
if (flags & INSTALL_HASH) {
|
2001-05-04 05:00:18 +08:00
|
|
|
s = headerSprintf(h, "%{NAME}",
|
|
|
|
rpmTagTable, rpmHeaderFormats, NULL);
|
2000-10-29 02:45:58 +08:00
|
|
|
#ifdef FANCY_HASH
|
2001-01-25 20:58:03 +08:00
|
|
|
if (isatty (STDOUT_FILENO))
|
|
|
|
fprintf(stdout, "%4d:%-23.23s", progressCurrent + 1, s);
|
|
|
|
else
|
2000-10-29 02:45:58 +08:00
|
|
|
#else
|
2001-01-25 20:58:03 +08:00
|
|
|
fprintf(stdout, "%-28s", s);
|
2000-10-29 02:45:58 +08:00
|
|
|
#endif
|
2001-05-01 06:32:22 +08:00
|
|
|
(void) fflush(stdout);
|
2001-05-04 05:00:18 +08:00
|
|
|
s = _free(s);
|
2001-01-25 20:58:03 +08:00
|
|
|
} else {
|
2001-04-10 20:36:45 +08:00
|
|
|
s = headerSprintf(h, "%{NAME}-%{VERSION}-%{RELEASE}",
|
1999-07-14 23:28:03 +08:00
|
|
|
rpmTagTable, rpmHeaderFormats, NULL);
|
2001-01-25 20:58:03 +08:00
|
|
|
fprintf(stdout, "%s\n", s);
|
2001-05-01 06:32:22 +08:00
|
|
|
(void) fflush(stdout);
|
2001-05-04 05:00:18 +08:00
|
|
|
s = _free(s);
|
1999-07-14 23:28:03 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2001-01-25 20:58:03 +08:00
|
|
|
case RPMCALLBACK_TRANS_PROGRESS:
|
|
|
|
case RPMCALLBACK_INST_PROGRESS:
|
2001-02-28 05:30:27 +08:00
|
|
|
if (flags & INSTALL_PERCENT)
|
2001-06-04 21:55:58 +08:00
|
|
|
fprintf(stdout, "%%%% %f\n", (double) (total
|
|
|
|
? ((((float) amount) / total) * 100)
|
1999-07-14 23:28:03 +08:00
|
|
|
: 100.0));
|
2001-02-28 05:30:27 +08:00
|
|
|
else if (flags & INSTALL_HASH)
|
1999-07-14 23:28:03 +08:00
|
|
|
printHash(amount, total);
|
2001-05-01 06:32:22 +08:00
|
|
|
(void) fflush(stdout);
|
1999-07-14 23:28:03 +08:00
|
|
|
break;
|
|
|
|
|
2001-01-25 20:58:03 +08:00
|
|
|
case RPMCALLBACK_TRANS_START:
|
|
|
|
hashesPrinted = 0;
|
2000-10-29 02:45:58 +08:00
|
|
|
#ifdef FANCY_HASH
|
2001-01-25 20:58:03 +08:00
|
|
|
progressTotal = 1;
|
|
|
|
progressCurrent = 0;
|
2000-10-29 02:45:58 +08:00
|
|
|
#endif
|
2001-01-25 20:58:03 +08:00
|
|
|
if (!(flags & INSTALL_LABEL))
|
|
|
|
break;
|
2001-02-28 05:30:27 +08:00
|
|
|
if (flags & INSTALL_HASH)
|
2001-01-25 20:58:03 +08:00
|
|
|
fprintf(stdout, "%-28s", _("Preparing..."));
|
2001-02-28 05:30:27 +08:00
|
|
|
else
|
2001-01-25 20:58:03 +08:00
|
|
|
printf("%s\n", _("Preparing packages for installation..."));
|
2001-05-01 06:32:22 +08:00
|
|
|
(void) fflush(stdout);
|
2001-01-25 20:58:03 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case RPMCALLBACK_TRANS_STOP:
|
|
|
|
if (flags & INSTALL_HASH)
|
|
|
|
printHash(1, 1); /* Fixes "preparing..." progress bar */
|
2000-10-29 02:45:58 +08:00
|
|
|
#ifdef FANCY_HASH
|
2001-01-25 20:58:03 +08:00
|
|
|
progressTotal = packagesTotal;
|
|
|
|
progressCurrent = 0;
|
2000-10-29 02:45:58 +08:00
|
|
|
#endif
|
2001-01-25 20:58:03 +08:00
|
|
|
break;
|
2000-10-29 02:45:58 +08:00
|
|
|
|
2001-01-25 20:58:03 +08:00
|
|
|
case RPMCALLBACK_UNINST_PROGRESS:
|
|
|
|
case RPMCALLBACK_UNINST_START:
|
|
|
|
case RPMCALLBACK_UNINST_STOP:
|
1999-07-14 23:28:03 +08:00
|
|
|
/* 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,
|
2001-04-10 20:36:45 +08:00
|
|
|
rpmtransFlags transFlags,
|
2000-08-30 06:04:33 +08:00
|
|
|
rpmInstallInterfaceFlags interfaceFlags,
|
2001-04-10 20:36:45 +08:00
|
|
|
rpmprobFilterFlags probFilter,
|
2000-08-30 06:04:33 +08:00
|
|
|
rpmRelocation * relocations)
|
1999-11-27 00:19:30 +08:00
|
|
|
{
|
2001-04-10 20:36:45 +08:00
|
|
|
rpmTransactionSet ts = NULL;
|
|
|
|
int notifyFlags = interfaceFlags | (rpmIsVerbose() ? INSTALL_LABEL : 0 );
|
1999-07-14 23:28:03 +08:00
|
|
|
rpmdb db = NULL;
|
1999-12-13 01:46:22 +08:00
|
|
|
const char ** pkgURL = NULL;
|
2001-04-10 20:36:45 +08:00
|
|
|
char * pkgState = NULL;
|
|
|
|
const char ** fnp;
|
|
|
|
const char * fileURL = NULL;
|
|
|
|
int numPkgs = 0;
|
|
|
|
int numRPMS = 0;
|
|
|
|
int numSRPMS = 0;
|
1999-07-14 23:28:03 +08:00
|
|
|
int numFailed = 0;
|
|
|
|
int stopInstall = 0;
|
|
|
|
int dbIsOpen = 0;
|
2001-04-10 20:36:45 +08:00
|
|
|
rpmRelocation * defaultReloc = relocations;
|
|
|
|
const char ** sourceURL = NULL;
|
|
|
|
int prevx;
|
|
|
|
int pkgx;
|
|
|
|
const char ** argv = NULL;
|
|
|
|
int argc = 0;
|
|
|
|
const char ** av = NULL;
|
|
|
|
int ac = 0;
|
|
|
|
Header h;
|
|
|
|
FD_t fd;
|
|
|
|
int rc;
|
|
|
|
int i;
|
1999-07-14 23:28:03 +08:00
|
|
|
|
2001-05-04 05:00:18 +08:00
|
|
|
if (fileArgv == NULL) return 0;
|
|
|
|
|
2001-04-10 20:36:45 +08:00
|
|
|
while (defaultReloc && defaultReloc->oldPath)
|
|
|
|
defaultReloc++;
|
1999-07-14 23:28:03 +08:00
|
|
|
if (defaultReloc && !defaultReloc->newPath) defaultReloc = NULL;
|
|
|
|
|
2001-04-10 20:36:45 +08:00
|
|
|
/* Build fully globbed list of arguments in argv[argc]. */
|
|
|
|
for (fnp = fileArgv; *fnp; fnp++) {
|
|
|
|
av = _free(av);
|
|
|
|
ac = 0;
|
|
|
|
rc = rpmGlob(*fnp, &ac, &av);
|
|
|
|
if (rc || ac == 0) continue;
|
1999-07-14 23:28:03 +08:00
|
|
|
|
2001-04-29 09:05:43 +08:00
|
|
|
if (argv == NULL)
|
|
|
|
argv = xmalloc((argc+ac+1) * sizeof(*argv));
|
|
|
|
else
|
|
|
|
argv = xrealloc(argv, (argc+ac+1) * sizeof(*argv));
|
2001-04-10 20:36:45 +08:00
|
|
|
memcpy(argv+argc, av, ac * sizeof(*av));
|
|
|
|
argc += ac;
|
|
|
|
argv[argc] = NULL;
|
|
|
|
}
|
|
|
|
av = _free(av);
|
|
|
|
|
|
|
|
numPkgs = 0;
|
|
|
|
prevx = 0;
|
|
|
|
pkgx = 0;
|
|
|
|
|
|
|
|
restart:
|
|
|
|
/* Allocate sufficient storage for next set of args. */
|
|
|
|
if (pkgx >= numPkgs) {
|
|
|
|
numPkgs = pkgx + argc;
|
2001-04-29 09:05:43 +08:00
|
|
|
if (pkgURL == NULL)
|
|
|
|
pkgURL = xmalloc( (numPkgs + 1) * sizeof(*pkgURL));
|
|
|
|
else
|
|
|
|
pkgURL = xrealloc(pkgURL, (numPkgs + 1) * sizeof(*pkgURL));
|
2001-04-10 20:36:45 +08:00
|
|
|
memset(pkgURL + pkgx, 0, ((argc + 1) * sizeof(*pkgURL)));
|
2001-04-29 09:05:43 +08:00
|
|
|
if (pkgState == NULL)
|
|
|
|
pkgState = xmalloc( (numPkgs + 1) * sizeof(*pkgState));
|
|
|
|
else
|
|
|
|
pkgState = xrealloc(pkgState, (numPkgs + 1) * sizeof(*pkgState));
|
2001-04-10 20:36:45 +08:00
|
|
|
memset(pkgState + pkgx, 0, ((argc + 1) * sizeof(*pkgState)));
|
|
|
|
}
|
1999-07-14 23:28:03 +08:00
|
|
|
|
2001-04-10 20:36:45 +08:00
|
|
|
/* Retrieve next set of args, cache on local storage. */
|
|
|
|
for (i = 0; i < argc; i++) {
|
|
|
|
fileURL = _free(fileURL);
|
|
|
|
fileURL = argv[i];
|
|
|
|
argv[i] = NULL;
|
1999-07-14 23:28:03 +08:00
|
|
|
|
2001-04-10 20:36:45 +08:00
|
|
|
switch (urlIsURL(fileURL)) {
|
1999-07-14 23:28:03 +08:00
|
|
|
case URL_IS_FTP:
|
|
|
|
case URL_IS_HTTP:
|
2001-04-10 20:36:45 +08:00
|
|
|
{ const char *tfn;
|
1999-12-13 01:46:22 +08:00
|
|
|
|
2001-04-10 20:36:45 +08:00
|
|
|
if (rpmIsVerbose())
|
|
|
|
fprintf(stdout, _("Retrieving %s\n"), fileURL);
|
1999-12-13 01:46:22 +08:00
|
|
|
|
2001-04-10 20:36:45 +08:00
|
|
|
{ char tfnbuf[64];
|
|
|
|
strcpy(tfnbuf, "rpm-xfer.XXXXXX");
|
|
|
|
/*@-unrecog@*/ mktemp(tfnbuf) /*@=unrecog@*/;
|
|
|
|
tfn = rpmGenPath(rootdir, "%{_tmppath}/", tfnbuf);
|
1999-12-13 01:46:22 +08:00
|
|
|
}
|
2001-04-10 20:36:45 +08:00
|
|
|
|
|
|
|
/* XXX undefined %{name}/%{version}/%{release} here */
|
|
|
|
/* XXX %{_tmpdir} does not exist */
|
|
|
|
rpmMessage(RPMMESS_DEBUG, _(" ... as %s\n"), tfn);
|
|
|
|
rc = urlGetFile(fileURL, tfn);
|
|
|
|
if (rc < 0) {
|
|
|
|
rpmMessage(RPMMESS_ERROR,
|
|
|
|
_("skipping %s - transfer failed - %s\n"),
|
|
|
|
fileURL, ftpStrerror(rc));
|
|
|
|
numFailed++;
|
|
|
|
pkgURL[pkgx] = NULL;
|
|
|
|
tfn = _free(tfn);
|
|
|
|
break;
|
1999-07-14 23:28:03 +08:00
|
|
|
}
|
2001-04-10 20:36:45 +08:00
|
|
|
pkgState[pkgx] = 1;
|
|
|
|
pkgURL[pkgx] = tfn;
|
|
|
|
pkgx++;
|
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:
|
2001-04-10 20:36:45 +08:00
|
|
|
pkgURL[pkgx] = fileURL;
|
|
|
|
fileURL = NULL;
|
|
|
|
pkgx++;
|
1999-07-14 23:28:03 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2001-04-10 20:36:45 +08:00
|
|
|
fileURL = _free(fileURL);
|
1999-07-14 23:28:03 +08:00
|
|
|
|
2001-04-10 20:36:45 +08:00
|
|
|
if (numFailed) goto exit;
|
1999-07-14 23:28:03 +08:00
|
|
|
|
2001-04-10 20:36:45 +08:00
|
|
|
/* Continue processing file arguments, building transaction set. */
|
2001-05-04 05:00:18 +08:00
|
|
|
for (fnp = pkgURL+prevx; *fnp != NULL; fnp++, prevx++) {
|
1999-11-27 00:19:30 +08:00
|
|
|
const char * fileName;
|
2001-02-13 03:02:15 +08:00
|
|
|
rpmRC rpmrc;
|
2001-04-10 20:36:45 +08:00
|
|
|
int isSource;
|
|
|
|
|
|
|
|
rpmMessage(RPMMESS_DEBUG, "============== %s\n", *fnp);
|
|
|
|
(void) urlPath(*fnp, &fileName);
|
2001-02-13 03:02:15 +08:00
|
|
|
|
2001-04-10 20:36:45 +08:00
|
|
|
/* Try to read the header from a package file. */
|
|
|
|
fd = Fopen(*fnp, "r.ufdio");
|
1999-12-13 01:46:22 +08:00
|
|
|
if (fd == NULL || Ferror(fd)) {
|
2001-04-10 20:36:45 +08:00
|
|
|
rpmError(RPMERR_OPEN, _("open of %s failed: %s\n"), *fnp,
|
|
|
|
Fstrerror(fd));
|
2001-05-01 06:32:22 +08:00
|
|
|
if (fd) (void) Fclose(fd);
|
2001-04-10 20:36:45 +08:00
|
|
|
numFailed++; *fnp = NULL;
|
1999-07-14 23:28:03 +08:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2001-06-06 03:26:22 +08:00
|
|
|
/*@-mustmod@*/ /* LCL: segfault */
|
2001-04-10 20:36:45 +08:00
|
|
|
rpmrc = rpmReadPackageHeader(fd, &h, &isSource, NULL, NULL);
|
2001-06-06 03:26:22 +08:00
|
|
|
/*@-mustmod@*/
|
2001-05-01 06:32:22 +08:00
|
|
|
(void) Fclose(fd);
|
1999-07-14 23:28:03 +08:00
|
|
|
|
2001-04-10 20:36:45 +08:00
|
|
|
if (rpmrc == RPMRC_FAIL || rpmrc == RPMRC_SHORTREAD) {
|
|
|
|
numFailed++; *fnp = NULL;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if ((rpmrc == RPMRC_OK || rpmrc == RPMRC_BADSIZE) && isSource) {
|
2001-04-24 04:56:59 +08:00
|
|
|
rpmMessage(RPMMESS_DEBUG, "\tadded source package [%d]\n",
|
|
|
|
numSRPMS);
|
2001-04-29 09:05:43 +08:00
|
|
|
if (sourceURL == NULL)
|
|
|
|
sourceURL = xmalloc((numSRPMS + 2) * sizeof(*sourceURL));
|
|
|
|
else
|
|
|
|
sourceURL = xrealloc(sourceURL,
|
|
|
|
(numSRPMS + 2) * sizeof(*sourceURL));
|
2001-04-10 20:36:45 +08:00
|
|
|
sourceURL[numSRPMS++] = *fnp;
|
2001-04-29 09:05:43 +08:00
|
|
|
sourceURL[numSRPMS] = NULL;
|
2001-04-10 20:36:45 +08:00
|
|
|
*fnp = NULL;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (rpmrc == RPMRC_OK || rpmrc == RPMRC_BADSIZE) {
|
|
|
|
if (!dbIsOpen) {
|
|
|
|
int mode = (transFlags & RPMTRANS_FLAG_TEST)
|
|
|
|
? O_RDONLY : (O_RDWR | O_CREAT);
|
|
|
|
|
|
|
|
if (rpmdbOpen(rootdir, &db, mode, 0644)) {
|
|
|
|
const char *dn;
|
|
|
|
dn = rpmGetPath( (rootdir ? rootdir : ""),
|
1999-07-14 23:28:03 +08:00
|
|
|
"%{_dbpath}", NULL);
|
2001-04-10 20:36:45 +08:00
|
|
|
rpmMessage(RPMMESS_ERROR,
|
2000-07-12 12:02:35 +08:00
|
|
|
_("cannot open Packages database in %s\n"), dn);
|
2001-04-10 20:36:45 +08:00
|
|
|
dn = _free(dn);
|
|
|
|
numFailed++; *fnp = NULL;
|
|
|
|
break;
|
1999-07-14 23:28:03 +08:00
|
|
|
}
|
2001-04-10 20:36:45 +08:00
|
|
|
ts = rpmtransCreateSet(db, rootdir);
|
|
|
|
dbIsOpen = 1;
|
|
|
|
}
|
1999-07-14 23:28:03 +08:00
|
|
|
|
2001-04-10 20:36:45 +08:00
|
|
|
if (defaultReloc) {
|
|
|
|
const char ** paths;
|
|
|
|
int pft;
|
|
|
|
int c;
|
1999-07-14 23:28:03 +08:00
|
|
|
|
2001-04-10 20:36:45 +08:00
|
|
|
if (headerGetEntry(h, RPMTAG_PREFIXES, &pft,
|
1999-07-14 23:28:03 +08:00
|
|
|
(void **) &paths, &c) && (c == 1)) {
|
2001-04-10 20:36:45 +08:00
|
|
|
defaultReloc->oldPath = xstrdup(paths[0]);
|
|
|
|
paths = headerFreeData(paths, pft);
|
|
|
|
} else {
|
|
|
|
const char * name;
|
2001-05-01 06:32:22 +08:00
|
|
|
(void) headerNVR(h, &name, NULL, NULL);
|
2001-04-10 20:36:45 +08:00
|
|
|
rpmMessage(RPMMESS_ERROR,
|
1999-07-14 23:28:03 +08:00
|
|
|
_("package %s is not relocateable\n"), name);
|
2001-04-10 20:36:45 +08:00
|
|
|
numFailed++;
|
|
|
|
goto exit;
|
|
|
|
/*@notreached@*/
|
1999-07-14 23:28:03 +08:00
|
|
|
}
|
2001-04-10 20:36:45 +08:00
|
|
|
}
|
1999-07-14 23:28:03 +08:00
|
|
|
|
2001-04-10 20:36:45 +08:00
|
|
|
/* On --freshen, verify package is installed and newer */
|
|
|
|
if (interfaceFlags & INSTALL_FRESHEN) {
|
|
|
|
rpmdbMatchIterator mi;
|
|
|
|
const char * name;
|
|
|
|
Header oldH;
|
|
|
|
int count;
|
|
|
|
|
2001-05-01 06:32:22 +08:00
|
|
|
(void) headerNVR(h, &name, NULL, NULL);
|
2001-04-10 20:36:45 +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;
|
2001-06-06 03:26:22 +08:00
|
|
|
/*@innerbreak@*/ break;
|
2000-06-23 08:49:43 +08:00
|
|
|
}
|
2001-04-30 06:43:01 +08:00
|
|
|
mi = rpmdbFreeIterator(mi);
|
2001-04-10 20:36:45 +08:00
|
|
|
if (count == 0) {
|
2001-05-23 22:25:19 +08:00
|
|
|
h = headerFree(h);
|
2001-04-10 20:36:45 +08:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
/* Package is newer than those currently installed. */
|
|
|
|
}
|
2000-06-23 08:49:43 +08:00
|
|
|
|
2001-04-10 20:36:45 +08:00
|
|
|
rc = rpmtransAddPackage(ts, h, NULL, fileName,
|
1999-07-14 23:28:03 +08:00
|
|
|
(interfaceFlags & INSTALL_UPGRADE) != 0,
|
|
|
|
relocations);
|
2001-05-23 22:25:19 +08:00
|
|
|
h = headerFree(h); /* XXX reference held by transaction set */
|
2001-04-10 20:36:45 +08:00
|
|
|
if (defaultReloc)
|
|
|
|
defaultReloc->oldPath = _free(defaultReloc->oldPath);
|
1999-09-21 11:22:53 +08:00
|
|
|
|
2001-04-10 20:36:45 +08:00
|
|
|
switch(rc) {
|
|
|
|
case 0:
|
2001-04-24 04:56:59 +08:00
|
|
|
rpmMessage(RPMMESS_DEBUG, "\tadded binary package [%d]\n",
|
|
|
|
numRPMS);
|
2001-04-10 20:36:45 +08:00
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
rpmMessage(RPMMESS_ERROR,
|
|
|
|
_("error reading from file %s\n"), *fnp);
|
|
|
|
numFailed++;
|
|
|
|
goto exit;
|
|
|
|
/*@notreached@*/ break;
|
|
|
|
case 2:
|
|
|
|
rpmMessage(RPMMESS_ERROR,
|
1999-07-14 23:28:03 +08:00
|
|
|
_("file %s requires a newer version of RPM\n"),
|
2001-04-10 20:36:45 +08:00
|
|
|
*fnp);
|
|
|
|
numFailed++;
|
|
|
|
goto exit;
|
|
|
|
/*@notreached@*/ break;
|
|
|
|
}
|
1999-07-14 23:28:03 +08:00
|
|
|
|
2001-04-10 20:36:45 +08:00
|
|
|
numRPMS++;
|
|
|
|
continue;
|
|
|
|
}
|
1999-07-14 23:28:03 +08:00
|
|
|
|
2001-04-10 20:36:45 +08:00
|
|
|
if (rpmrc != RPMRC_BADMAGIC) {
|
|
|
|
rpmMessage(RPMMESS_ERROR, _("%s cannot be installed\n"), *fnp);
|
|
|
|
numFailed++; *fnp = NULL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Try to read a package manifest. */
|
|
|
|
fd = Fopen(*fnp, "r.fpio");
|
|
|
|
if (fd == NULL || Ferror(fd)) {
|
|
|
|
rpmError(RPMERR_OPEN, _("open of %s failed: %s\n"), *fnp,
|
|
|
|
Fstrerror(fd));
|
2001-05-01 06:32:22 +08:00
|
|
|
if (fd) (void) Fclose(fd);
|
2001-04-10 20:36:45 +08:00
|
|
|
numFailed++; *fnp = NULL;
|
1999-07-14 23:28:03 +08:00
|
|
|
break;
|
|
|
|
}
|
2001-04-10 20:36:45 +08:00
|
|
|
|
|
|
|
/* Read list of packages from manifest. */
|
|
|
|
rc = rpmReadPackageManifest(fd, &argc, &argv);
|
|
|
|
if (rc)
|
|
|
|
rpmError(RPMERR_MANIFEST, _("%s: read manifest failed: %s\n"),
|
2001-05-04 05:00:18 +08:00
|
|
|
*fnp, Fstrerror(fd));
|
2001-05-01 06:32:22 +08:00
|
|
|
(void) Fclose(fd);
|
2001-04-10 20:36:45 +08:00
|
|
|
|
|
|
|
/* If successful, restart the query loop. */
|
|
|
|
if (rc == 0) {
|
|
|
|
prevx++;
|
|
|
|
goto restart;
|
|
|
|
}
|
|
|
|
|
|
|
|
numFailed++; *fnp = NULL;
|
|
|
|
break;
|
1999-07-14 23:28:03 +08:00
|
|
|
}
|
|
|
|
|
2001-04-10 20:36:45 +08:00
|
|
|
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
|
|
|
|
2001-04-10 20:36:45 +08:00
|
|
|
if (numFailed) goto exit;
|
2001-02-10 22:35:55 +08:00
|
|
|
|
1999-12-13 01:46:22 +08:00
|
|
|
if (numRPMS && !(interfaceFlags & INSTALL_NODEPS)) {
|
2001-06-01 06:31:14 +08:00
|
|
|
rpmDependencyConflict conflicts;
|
2001-04-10 20:36:45 +08:00
|
|
|
int numConflicts;
|
|
|
|
|
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);
|
2001-06-01 06:31:14 +08:00
|
|
|
conflicts = 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
|
2001-08-31 22:02:13 +08:00
|
|
|
packagesTotal = numRPMS + numSRPMS;
|
2000-10-29 02:45:58 +08:00
|
|
|
#endif
|
1999-07-14 23:28:03 +08:00
|
|
|
rpmMessage(RPMMESS_DEBUG, _("installing binary packages\n"));
|
2001-07-07 04:37:42 +08:00
|
|
|
rc = rpmRunTransactions(ts, rpmShowProgress,
|
|
|
|
(void *) ((long)notifyFlags),
|
|
|
|
NULL, &probs, transFlags, probFilter);
|
1999-07-14 23:28:03 +08:00
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2001-04-29 09:05:43 +08:00
|
|
|
if (probs != NULL) rpmProblemSetFree(probs);
|
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)) {
|
2001-04-10 20:36:45 +08:00
|
|
|
rpmMessage(RPMMESS_ERROR, _("cannot open file %s: %s\n"),
|
1999-11-27 00:19:30 +08:00
|
|
|
sourceURL[i], Fstrerror(fd));
|
2001-05-01 06:32:22 +08:00
|
|
|
if (fd) (void) Fclose(fd);
|
1999-07-14 23:28:03 +08:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2001-02-13 03:02:15 +08:00
|
|
|
if (!(transFlags & RPMTRANS_FLAG_TEST)) {
|
|
|
|
rpmRC rpmrc = rpmInstallSourcePackage(rootdir, fd, NULL,
|
2001-07-07 04:37:42 +08:00
|
|
|
rpmShowProgress, (void *) ((long)notifyFlags), NULL);
|
2001-02-13 03:02:15 +08:00
|
|
|
if (rpmrc != RPMRC_OK) numFailed++;
|
|
|
|
}
|
1999-07-14 23:28:03 +08:00
|
|
|
|
2001-05-01 06:32:22 +08:00
|
|
|
(void) Fclose(fd);
|
1999-07-14 23:28:03 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-04-10 20:36:45 +08:00
|
|
|
exit:
|
2001-07-07 04:37:42 +08:00
|
|
|
ts = rpmtransFree(ts);
|
2001-04-10 20:36:45 +08:00
|
|
|
for (i = 0; i < numPkgs; i++) {
|
|
|
|
if (pkgState[i] == 1)
|
2001-05-01 06:32:22 +08:00
|
|
|
(void) Unlink(pkgURL[i]);
|
2001-04-10 20:36:45 +08:00
|
|
|
pkgURL[i] = _free(pkgURL[i]);
|
1999-07-14 23:28:03 +08:00
|
|
|
}
|
2001-04-10 20:36:45 +08:00
|
|
|
pkgState = _free(pkgState);
|
2001-03-24 04:27:48 +08:00
|
|
|
pkgURL = _free(pkgURL);
|
2001-04-21 14:02:09 +08:00
|
|
|
argv = _free(argv);
|
2001-05-01 06:32:22 +08:00
|
|
|
if (dbIsOpen) (void) rpmdbClose(db);
|
1999-07-14 23:28:03 +08:00
|
|
|
return numFailed;
|
|
|
|
}
|
|
|
|
|
2000-08-30 06:04:33 +08:00
|
|
|
int rpmErase(const char * rootdir, const char ** argv,
|
2001-04-10 20:36:45 +08:00
|
|
|
rpmtransFlags transFlags,
|
2000-08-30 06:04:33 +08:00
|
|
|
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;
|
2001-06-01 06:31:14 +08:00
|
|
|
rpmDependencyConflict conflicts;
|
1999-07-14 23:28:03 +08:00
|
|
|
int numConflicts;
|
|
|
|
int stopUninstall = 0;
|
|
|
|
int numPackages = 0;
|
|
|
|
rpmProblemSet probs;
|
|
|
|
|
2001-05-04 05:00:18 +08:00
|
|
|
if (argv == NULL) return 0;
|
|
|
|
|
2001-04-10 20:36:45 +08:00
|
|
|
if (transFlags & RPMTRANS_FLAG_TEST)
|
1999-07-14 23:28:03 +08:00
|
|
|
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);
|
2001-03-24 04:27:48 +08:00
|
|
|
dn = _free(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-07-07 04:37:42 +08:00
|
|
|
(void) rpmtransRemovePackage(ts, recOffset);
|
2000-04-27 08:10:28 +08:00
|
|
|
numPackages++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2001-04-30 06:43:01 +08:00
|
|
|
mi = 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);
|
2001-06-01 06:31:14 +08:00
|
|
|
conflicts = rpmdepFreeConflicts(conflicts, numConflicts);
|
1999-07-14 23:28:03 +08:00
|
|
|
numFailed += numPackages;
|
|
|
|
stopUninstall = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!stopUninstall) {
|
2001-02-18 01:53:21 +08:00
|
|
|
transFlags |= RPMTRANS_FLAG_REVERSE;
|
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-07-07 04:37:42 +08:00
|
|
|
ts = rpmtransFree(ts);
|
2001-05-01 06:32:22 +08:00
|
|
|
(void) rpmdbClose(db);
|
1999-07-14 23:28:03 +08:00
|
|
|
|
|
|
|
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));
|
2001-05-01 06:32:22 +08:00
|
|
|
if (fd) (void) Fclose(fd);
|
1999-07-14 23:28:03 +08:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (rpmIsVerbose())
|
|
|
|
fprintf(stdout, _("Installing %s\n"), arg);
|
|
|
|
|
2001-05-04 05:00:18 +08:00
|
|
|
{
|
|
|
|
/*@-mayaliasunique@*/
|
|
|
|
rpmRC rpmrc = rpmInstallSourcePackage(rootdir, fd, specFile, NULL, NULL,
|
1999-07-14 23:28:03 +08:00
|
|
|
cookie);
|
2001-05-04 05:00:18 +08:00
|
|
|
/*@=mayaliasunique@*/
|
2001-02-13 03:02:15 +08:00
|
|
|
rc = (rpmrc == RPMRC_OK ? 0 : 1);
|
|
|
|
}
|
|
|
|
if (rc != 0) {
|
1999-07-14 23:28:03 +08:00
|
|
|
rpmMessage(RPMMESS_ERROR, _("%s cannot be installed\n"), arg);
|
2001-04-30 06:43:01 +08:00
|
|
|
/*@-unqualifiedtrans@*/
|
2001-03-24 04:27:48 +08:00
|
|
|
if (specFile && *specFile)
|
|
|
|
*specFile = _free(*specFile);
|
|
|
|
if (cookie && *cookie)
|
|
|
|
*cookie = _free(*cookie);
|
2001-04-30 06:43:01 +08:00
|
|
|
/*@=unqualifiedtrans@*/
|
1999-07-14 23:28:03 +08:00
|
|
|
}
|
|
|
|
|
2001-05-01 06:32:22 +08:00
|
|
|
(void) Fclose(fd);
|
1999-07-14 23:28:03 +08:00
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
2001-07-07 04:37:42 +08:00
|
|
|
|
|
|
|
static int reverse = -1;
|
|
|
|
|
|
|
|
/**
|
|
|
|
*/
|
|
|
|
static int IDTintcmp(const void * a, const void * b)
|
|
|
|
/*@*/
|
|
|
|
{
|
|
|
|
/*@-castexpose@*/
|
|
|
|
return ( reverse * (((IDT)a)->val.i32 - ((IDT)b)->val.i32) );
|
|
|
|
/*@=castexpose@*/
|
|
|
|
}
|
|
|
|
|
|
|
|
IDTX IDTXfree(IDTX idtx)
|
|
|
|
{
|
|
|
|
if (idtx) {
|
|
|
|
int i;
|
|
|
|
if (idtx->idt)
|
|
|
|
for (i = 0; i < idtx->nidt; i++) {
|
|
|
|
IDT idt = idtx->idt + i;
|
|
|
|
idt->h = headerFree(idt->h);
|
|
|
|
idt->key = _free(idt->key);
|
|
|
|
}
|
|
|
|
idtx->idt = _free(idtx->idt);
|
|
|
|
idtx = _free(idtx);
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
IDTX IDTXnew(void)
|
|
|
|
{
|
|
|
|
IDTX idtx = xcalloc(1, sizeof(*idtx));
|
|
|
|
idtx->delta = 10;
|
|
|
|
idtx->size = sizeof(*((IDT)0));
|
|
|
|
return idtx;
|
|
|
|
}
|
|
|
|
|
|
|
|
IDTX IDTXgrow(IDTX idtx, int need)
|
|
|
|
{
|
|
|
|
if (need < 0) return NULL;
|
|
|
|
if (idtx == NULL)
|
|
|
|
idtx = IDTXnew();
|
|
|
|
if (need == 0) return idtx;
|
|
|
|
|
|
|
|
if ((idtx->nidt + need) > idtx->alloced) {
|
|
|
|
while (need > 0) {
|
|
|
|
idtx->alloced += idtx->delta;
|
|
|
|
need -= idtx->delta;
|
|
|
|
}
|
|
|
|
idtx->idt = xrealloc(idtx->idt, (idtx->alloced * idtx->size) );
|
|
|
|
}
|
|
|
|
return idtx;
|
|
|
|
}
|
|
|
|
|
|
|
|
IDTX IDTXsort(IDTX idtx)
|
|
|
|
{
|
|
|
|
if (idtx != NULL && idtx->idt != NULL && idtx->nidt > 0)
|
|
|
|
qsort(idtx->idt, idtx->nidt, idtx->size, IDTintcmp);
|
|
|
|
return idtx;
|
|
|
|
}
|
|
|
|
|
|
|
|
IDTX IDTXload(rpmdb db, rpmTag tag)
|
|
|
|
{
|
|
|
|
IDTX idtx = NULL;
|
|
|
|
rpmdbMatchIterator mi;
|
|
|
|
HGE_t hge = (HGE_t) headerGetEntry;
|
|
|
|
Header h;
|
|
|
|
|
|
|
|
mi = rpmdbInitIterator(db, tag, NULL, 0);
|
|
|
|
while ((h = rpmdbNextIterator(mi)) != NULL) {
|
|
|
|
rpmTagType type;
|
|
|
|
int_32 count;
|
|
|
|
int_32 * tidp;
|
|
|
|
|
|
|
|
tidp = NULL;
|
|
|
|
if (!hge(h, tag, &type, (void **)&tidp, &count) || tidp == NULL)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (type == RPM_INT32_TYPE && (*tidp == 0 || *tidp == -1))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
idtx = IDTXgrow(idtx, 1);
|
|
|
|
if (idtx == NULL)
|
|
|
|
continue;
|
|
|
|
if (idtx->idt == NULL)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
{ IDT idt;
|
|
|
|
/*@-nullderef@*/
|
|
|
|
idt = idtx->idt + idtx->nidt;
|
|
|
|
/*@=nullderef@*/
|
|
|
|
idt->h = NULL;
|
|
|
|
idt->key = NULL;
|
|
|
|
idt->instance = rpmdbGetIteratorOffset(mi);
|
|
|
|
idt->val.i32 = *tidp;
|
|
|
|
}
|
|
|
|
idtx->nidt++;
|
|
|
|
}
|
|
|
|
mi = rpmdbFreeIterator(mi);
|
|
|
|
|
|
|
|
return IDTXsort(idtx);
|
|
|
|
}
|
|
|
|
|
|
|
|
IDTX IDTXglob(const char * globstr, rpmTag tag)
|
|
|
|
{
|
|
|
|
IDTX idtx = NULL;
|
|
|
|
HGE_t hge = (HGE_t) headerGetEntry;
|
|
|
|
Header h;
|
|
|
|
int_32 * tidp;
|
|
|
|
FD_t fd;
|
|
|
|
const char ** av = NULL;
|
|
|
|
int ac = 0;
|
|
|
|
int rc;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
ac = 0;
|
|
|
|
av = NULL;
|
|
|
|
rc = rpmGlob(globstr, &ac, &av);
|
|
|
|
|
|
|
|
if (rc == 0)
|
|
|
|
for (i = 0; i < ac; i++) {
|
|
|
|
rpmTagType type;
|
|
|
|
int_32 count;
|
|
|
|
int isSource;
|
|
|
|
rpmRC rpmrc;
|
|
|
|
|
|
|
|
fd = Fopen(av[i], "r.ufdio");
|
|
|
|
if (fd == NULL || Ferror(fd)) {
|
|
|
|
rpmError(RPMERR_OPEN, _("open of %s failed: %s\n"), av[i],
|
|
|
|
Fstrerror(fd));
|
|
|
|
if (fd) (void) Fclose(fd);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
rpmrc = rpmReadPackageHeader(fd, &h, &isSource, NULL, NULL);
|
|
|
|
if (rpmrc != RPMRC_OK || isSource) {
|
|
|
|
(void) Fclose(fd);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
tidp = NULL;
|
|
|
|
if (hge(h, tag, &type, (void **) &tidp, &count) && tidp) {
|
|
|
|
|
|
|
|
idtx = IDTXgrow(idtx, 1);
|
|
|
|
if (idtx == NULL || idtx->idt == NULL) {
|
|
|
|
h = headerFree(h);
|
|
|
|
(void) Fclose(fd);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
{ IDT idt;
|
|
|
|
idt = idtx->idt + idtx->nidt;
|
|
|
|
idt->h = headerLink(h);
|
|
|
|
idt->key = av[i];
|
|
|
|
av[i] = NULL;
|
|
|
|
idt->instance = 0;
|
|
|
|
idt->val.i32 = *tidp;
|
|
|
|
}
|
|
|
|
idtx->nidt++;
|
|
|
|
}
|
|
|
|
|
|
|
|
h = headerFree(h);
|
|
|
|
(void) Fclose(fd);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < ac; i++)
|
|
|
|
av[i] = _free(av[i]);
|
|
|
|
av = _free(av);
|
|
|
|
|
|
|
|
return idtx;
|
|
|
|
}
|
|
|
|
|
|
|
|
int rpmRollback(/*@unused@*/ struct rpmInstallArguments_s * ia,
|
|
|
|
/*@unused@*/ const char ** argv)
|
|
|
|
{
|
|
|
|
rpmdb db = NULL;
|
|
|
|
rpmTransactionSet ts = NULL;
|
|
|
|
IDTX itids = NULL;
|
|
|
|
const char * globstr = rpmExpand("%{_repackage_dir}/*.rpm", NULL);
|
|
|
|
IDTX rtids = NULL;
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
rc = rpmdbOpen(ia->rootdir, &db, O_RDWR, 0644);
|
|
|
|
|
|
|
|
ts = rpmtransCreateSet(db, ia->rootdir);
|
|
|
|
|
|
|
|
itids = IDTXload(db, RPMTAG_INSTALLTID);
|
|
|
|
rtids = IDTXglob(globstr, RPMTAG_REMOVETID);
|
|
|
|
|
|
|
|
globstr = _free(globstr);
|
|
|
|
rtids = IDTXfree(rtids);
|
|
|
|
itids = IDTXfree(itids);
|
|
|
|
|
|
|
|
ts = rpmtransFree(ts);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|