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"
|
|
|
|
|
2021-11-12 19:15:40 +08:00
|
|
|
#include <string.h>
|
|
|
|
|
2007-12-08 20:02:32 +08:00
|
|
|
#include <rpm/rpmcli.h>
|
2008-01-30 19:53:51 +08:00
|
|
|
#include <rpm/rpmtag.h>
|
|
|
|
#include <rpm/rpmlib.h> /* rpmReadPackageFile, vercmp etc */
|
2007-12-08 20:02:32 +08:00
|
|
|
#include <rpm/rpmdb.h>
|
|
|
|
#include <rpm/rpmds.h>
|
|
|
|
#include <rpm/rpmts.h>
|
2016-12-15 00:57:58 +08:00
|
|
|
#include <rpm/rpmsq.h>
|
2007-12-08 20:02:32 +08:00
|
|
|
#include <rpm/rpmlog.h>
|
|
|
|
#include <rpm/rpmfileutil.h>
|
2002-04-12 00:55:19 +08:00
|
|
|
|
2010-03-23 22:29:59 +08:00
|
|
|
#include "lib/rpmgi.h"
|
2007-11-23 18:39:29 +08:00
|
|
|
#include "lib/manifest.h"
|
2000-12-13 04:03:45 +08:00
|
|
|
#include "debug.h"
|
1999-12-13 01:46:22 +08:00
|
|
|
|
2012-01-03 17:56:37 +08:00
|
|
|
static int rpmcliPackagesTotal = 0;
|
|
|
|
static int rpmcliHashesCurrent = 0;
|
|
|
|
static int rpmcliHashesTotal = 0;
|
|
|
|
static int rpmcliProgressCurrent = 0;
|
|
|
|
static int rpmcliProgressTotal = 0;
|
2014-03-26 15:32:53 +08:00
|
|
|
static int rpmcliProgressState = 0;
|
2000-10-29 02:45:58 +08:00
|
|
|
|
2001-03-24 04:27:48 +08:00
|
|
|
/**
|
2002-08-05 00:55:55 +08:00
|
|
|
* Print a CLI progress bar.
|
|
|
|
* @todo Unsnarl isatty(STDOUT_FILENO) from the control flow.
|
|
|
|
* @param amount current
|
|
|
|
* @param total final
|
2001-03-24 04:27:48 +08:00
|
|
|
*/
|
2008-06-09 17:00:12 +08:00
|
|
|
static void printHash(const rpm_loff_t amount, const rpm_loff_t total)
|
2000-06-19 19:35:29 +08:00
|
|
|
{
|
1999-07-14 23:28:03 +08:00
|
|
|
int hashesNeeded;
|
|
|
|
|
2012-03-19 14:21:17 +08:00
|
|
|
rpmcliHashesTotal = (isatty (STDOUT_FILENO) ? 34 : 40);
|
2000-10-29 02:45:58 +08:00
|
|
|
|
2002-08-05 00:55:55 +08:00
|
|
|
if (rpmcliHashesCurrent != rpmcliHashesTotal) {
|
2002-08-08 05:55:43 +08:00
|
|
|
float pct = (total ? (((float) amount) / total) : 1.0);
|
|
|
|
hashesNeeded = (rpmcliHashesTotal * pct) + 0.5;
|
2002-08-05 00:55:55 +08:00
|
|
|
while (hashesNeeded > rpmcliHashesCurrent) {
|
2001-01-25 20:58:03 +08:00
|
|
|
if (isatty (STDOUT_FILENO)) {
|
|
|
|
int i;
|
2002-08-05 00:55:55 +08:00
|
|
|
for (i = 0; i < rpmcliHashesCurrent; i++)
|
|
|
|
(void) putchar ('#');
|
|
|
|
for (; i < rpmcliHashesTotal; i++)
|
|
|
|
(void) putchar (' ');
|
2002-08-08 05:55:43 +08:00
|
|
|
fprintf(stdout, "(%3d%%)", (int)((100 * pct) + 0.5));
|
2002-08-05 00:55:55 +08:00
|
|
|
for (i = 0; i < (rpmcliHashesTotal + 6); i++)
|
|
|
|
(void) putchar ('\b');
|
2001-01-25 20:58:03 +08:00
|
|
|
} else
|
2001-09-15 21:49:11 +08:00
|
|
|
fprintf(stdout, "#");
|
2000-10-29 02:45:58 +08:00
|
|
|
|
2002-08-05 00:55:55 +08:00
|
|
|
rpmcliHashesCurrent++;
|
1999-07-14 23:28:03 +08:00
|
|
|
}
|
2001-05-01 06:32:22 +08:00
|
|
|
(void) fflush(stdout);
|
1999-07-14 23:28:03 +08:00
|
|
|
|
2002-08-05 00:55:55 +08:00
|
|
|
if (rpmcliHashesCurrent == rpmcliHashesTotal) {
|
2001-01-25 20:58:03 +08:00
|
|
|
int i;
|
2002-08-05 00:55:55 +08:00
|
|
|
rpmcliProgressCurrent++;
|
2002-01-28 00:49:06 +08:00
|
|
|
if (isatty(STDOUT_FILENO)) {
|
2002-08-05 00:55:55 +08:00
|
|
|
for (i = 1; i < rpmcliHashesCurrent; i++)
|
|
|
|
(void) putchar ('#');
|
|
|
|
pct = (rpmcliProgressTotal
|
|
|
|
? (((float) rpmcliProgressCurrent) / rpmcliProgressTotal)
|
|
|
|
: 1);
|
2002-08-08 05:55:43 +08:00
|
|
|
fprintf(stdout, " [%3d%%]", (int)((100 * pct) + 0.5));
|
2002-01-28 00:49:06 +08:00
|
|
|
}
|
|
|
|
fprintf(stdout, "\n");
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-02-12 19:55:09 +08:00
|
|
|
static rpmVSFlags setvsFlags(struct rpmInstallArguments_s * ia)
|
|
|
|
{
|
|
|
|
rpmVSFlags vsflags;
|
|
|
|
|
|
|
|
if (ia->installInterfaceFlags & (INSTALL_UPGRADE | INSTALL_ERASE))
|
|
|
|
vsflags = rpmExpandNumeric("%{?_vsflags_erase}");
|
|
|
|
else
|
|
|
|
vsflags = rpmExpandNumeric("%{?_vsflags_install}");
|
|
|
|
|
2017-11-14 17:03:04 +08:00
|
|
|
vsflags |= rpmcliVSFlags;
|
2009-02-12 19:55:09 +08:00
|
|
|
|
|
|
|
return vsflags;
|
|
|
|
}
|
|
|
|
|
2007-09-12 01:07:39 +08:00
|
|
|
void * rpmShowProgress(const void * arg,
|
2001-07-07 04:37:42 +08:00
|
|
|
const rpmCallbackType what,
|
2008-06-09 17:00:12 +08:00
|
|
|
const rpm_loff_t amount,
|
|
|
|
const rpm_loff_t total,
|
2007-09-12 01:07:39 +08:00
|
|
|
fnpyKey key,
|
|
|
|
void * data)
|
2000-06-19 19:35:29 +08:00
|
|
|
{
|
|
|
|
Header h = (Header) arg;
|
2000-05-13 07:12:15 +08:00
|
|
|
int flags = (int) ((long)data);
|
1999-07-14 23:28:03 +08:00
|
|
|
void * rc = NULL;
|
2001-11-08 08:12:49 +08:00
|
|
|
const char * filename = (const char *)key;
|
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");
|
2007-09-12 01:07:39 +08:00
|
|
|
/* FIX: still necessary? */
|
2002-08-14 00:36:44 +08:00
|
|
|
if (fd == NULL || Ferror(fd)) {
|
2007-11-19 22:25:24 +08:00
|
|
|
rpmlog(RPMLOG_ERR, _("open of %s failed: %s\n"), filename,
|
2002-08-14 00:36:44 +08:00
|
|
|
Fstrerror(fd));
|
2003-01-24 04:23:24 +08:00
|
|
|
if (fd != NULL) {
|
2009-05-28 14:43:40 +08:00
|
|
|
Fclose(fd);
|
2002-08-14 00:36:44 +08:00
|
|
|
fd = NULL;
|
|
|
|
}
|
|
|
|
} else
|
2010-03-22 19:25:57 +08:00
|
|
|
fd = fdLink(fd);
|
2003-01-24 04:23:24 +08:00
|
|
|
return (void *)fd;
|
2007-09-12 01:07:39 +08:00
|
|
|
break;
|
1999-07-14 23:28:03 +08:00
|
|
|
|
2001-01-25 20:58:03 +08:00
|
|
|
case RPMCALLBACK_INST_CLOSE_FILE:
|
2007-09-12 01:07:39 +08:00
|
|
|
/* FIX: still necessary? */
|
2010-03-22 19:25:57 +08:00
|
|
|
fd = fdFree(fd);
|
2003-01-24 04:23:24 +08:00
|
|
|
if (fd != NULL) {
|
2009-05-28 14:43:40 +08:00
|
|
|
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:
|
2012-01-05 22:17:33 +08:00
|
|
|
case RPMCALLBACK_UNINST_START:
|
2014-03-26 15:32:53 +08:00
|
|
|
if (rpmcliProgressState != what) {
|
|
|
|
rpmcliProgressState = what;
|
2012-01-05 22:17:33 +08:00
|
|
|
if (flags & INSTALL_HASH) {
|
|
|
|
if (what == RPMCALLBACK_INST_START) {
|
2012-01-11 02:26:55 +08:00
|
|
|
fprintf(stdout, _("Updating / installing...\n"));
|
2012-01-05 22:17:33 +08:00
|
|
|
} else {
|
2012-01-11 02:26:55 +08:00
|
|
|
fprintf(stdout, _("Cleaning up / removing...\n"));
|
2012-01-05 22:17:33 +08:00
|
|
|
}
|
|
|
|
fflush(stdout);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-08-05 00:55:55 +08:00
|
|
|
rpmcliHashesCurrent = 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) {
|
2012-03-19 14:43:58 +08:00
|
|
|
char *s = headerGetAsString(h, RPMTAG_NEVR);
|
2001-01-25 20:58:03 +08:00
|
|
|
if (isatty (STDOUT_FILENO))
|
2012-03-19 14:21:17 +08:00
|
|
|
fprintf(stdout, "%4d:%-33.33s", rpmcliProgressCurrent + 1, s);
|
2002-01-28 00:49:06 +08:00
|
|
|
else
|
2012-03-19 14:21:17 +08:00
|
|
|
fprintf(stdout, "%-38.38s", s);
|
2001-05-01 06:32:22 +08:00
|
|
|
(void) fflush(stdout);
|
2011-05-29 03:30:41 +08:00
|
|
|
free(s);
|
2001-01-25 20:58:03 +08:00
|
|
|
} else {
|
2012-03-19 14:43:58 +08:00
|
|
|
char *s = headerGetAsString(h, RPMTAG_NEVRA);
|
2001-01-25 20:58:03 +08:00
|
|
|
fprintf(stdout, "%s\n", s);
|
2001-05-01 06:32:22 +08:00
|
|
|
(void) fflush(stdout);
|
2011-05-29 03:30:41 +08:00
|
|
|
free(s);
|
1999-07-14 23:28:03 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2012-01-05 20:34:46 +08:00
|
|
|
case RPMCALLBACK_INST_STOP:
|
|
|
|
break;
|
|
|
|
|
2001-01-25 20:58:03 +08:00
|
|
|
case RPMCALLBACK_TRANS_PROGRESS:
|
|
|
|
case RPMCALLBACK_INST_PROGRESS:
|
2012-01-05 22:17:33 +08:00
|
|
|
case RPMCALLBACK_UNINST_PROGRESS:
|
2018-05-09 18:49:41 +08:00
|
|
|
case RPMCALLBACK_VERIFY_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:
|
2018-05-09 18:49:41 +08:00
|
|
|
case RPMCALLBACK_VERIFY_START:
|
2002-08-05 00:55:55 +08:00
|
|
|
rpmcliHashesCurrent = 0;
|
|
|
|
rpmcliProgressTotal = 1;
|
|
|
|
rpmcliProgressCurrent = 0;
|
2012-01-03 17:49:32 +08:00
|
|
|
rpmcliPackagesTotal = total;
|
2014-03-26 15:32:53 +08:00
|
|
|
rpmcliProgressState = what;
|
2001-01-25 20:58:03 +08:00
|
|
|
if (!(flags & INSTALL_LABEL))
|
|
|
|
break;
|
2018-05-09 18:49:41 +08:00
|
|
|
if (flags & INSTALL_HASH) {
|
|
|
|
fprintf(stdout, "%-38s", (what == RPMCALLBACK_TRANS_START) ?
|
|
|
|
_("Preparing...") : _("Verifying..."));
|
|
|
|
} else {
|
|
|
|
fprintf(stdout, "%s\n", (what == RPMCALLBACK_TRANS_START) ?
|
|
|
|
_("Preparing packages...") : _("Verifying packages..."));
|
|
|
|
}
|
2001-05-01 06:32:22 +08:00
|
|
|
(void) fflush(stdout);
|
2001-01-25 20:58:03 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case RPMCALLBACK_TRANS_STOP:
|
2018-05-09 18:49:41 +08:00
|
|
|
case RPMCALLBACK_VERIFY_STOP:
|
2001-01-25 20:58:03 +08:00
|
|
|
if (flags & INSTALL_HASH)
|
|
|
|
printHash(1, 1); /* Fixes "preparing..." progress bar */
|
2002-08-05 00:55:55 +08:00
|
|
|
rpmcliProgressTotal = rpmcliPackagesTotal;
|
|
|
|
rpmcliProgressCurrent = 0;
|
|
|
|
break;
|
|
|
|
|
2001-01-25 20:58:03 +08:00
|
|
|
case RPMCALLBACK_UNINST_STOP:
|
2002-08-05 00:55:55 +08:00
|
|
|
break;
|
2002-04-11 06:10:13 +08:00
|
|
|
case RPMCALLBACK_UNPACK_ERROR:
|
2002-08-05 00:55:55 +08:00
|
|
|
break;
|
2002-04-11 06:10:13 +08:00
|
|
|
case RPMCALLBACK_CPIO_ERROR:
|
2002-08-05 00:55:55 +08:00
|
|
|
break;
|
2007-12-07 22:19:21 +08:00
|
|
|
case RPMCALLBACK_SCRIPT_ERROR:
|
|
|
|
break;
|
2012-01-03 19:10:26 +08:00
|
|
|
case RPMCALLBACK_SCRIPT_START:
|
|
|
|
break;
|
|
|
|
case RPMCALLBACK_SCRIPT_STOP:
|
|
|
|
break;
|
2002-08-05 00:55:55 +08:00
|
|
|
case RPMCALLBACK_UNKNOWN:
|
|
|
|
default:
|
1999-07-14 23:28:03 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2009-02-12 20:00:21 +08:00
|
|
|
static void setNotifyFlag(struct rpmInstallArguments_s * ia,
|
|
|
|
rpmts ts)
|
|
|
|
{
|
2009-05-28 14:43:40 +08:00
|
|
|
int notifyFlags;
|
2009-02-12 20:00:21 +08:00
|
|
|
|
|
|
|
notifyFlags = ia->installInterfaceFlags | (rpmIsVerbose() ? INSTALL_LABEL : 0 );
|
2009-05-28 14:43:40 +08:00
|
|
|
rpmtsSetNotifyCallback(ts, rpmShowProgress, (void *) ((long)notifyFlags));
|
2009-02-12 20:00:21 +08:00
|
|
|
}
|
|
|
|
|
2001-09-15 21:49:11 +08:00
|
|
|
struct rpmEIU {
|
|
|
|
int numFailed;
|
|
|
|
int numPkgs;
|
2007-12-18 18:08:13 +08:00
|
|
|
char ** pkgURL;
|
2008-04-07 17:11:16 +08:00
|
|
|
char ** fnp;
|
2002-03-13 23:06:07 +08:00
|
|
|
char * pkgState;
|
2001-09-15 21:49:11 +08:00
|
|
|
int prevx;
|
|
|
|
int pkgx;
|
|
|
|
int numRPMS;
|
|
|
|
int numSRPMS;
|
2008-04-07 17:11:16 +08:00
|
|
|
char ** sourceURL;
|
2001-09-15 21:49:11 +08:00
|
|
|
int argc;
|
2007-12-18 18:08:13 +08:00
|
|
|
char ** argv;
|
2002-03-13 23:06:07 +08:00
|
|
|
rpmRelocation * relocations;
|
2001-09-15 21:49:11 +08:00
|
|
|
rpmRC rpmrc;
|
|
|
|
};
|
|
|
|
|
2022-01-27 16:28:37 +08:00
|
|
|
static int rpmcliTransaction(rpmts ts, struct rpmInstallArguments_s * ia)
|
2009-02-12 18:24:31 +08:00
|
|
|
{
|
|
|
|
rpmps ps;
|
2022-01-27 16:28:37 +08:00
|
|
|
int numPackages = rpmtsNElements(ts);
|
2009-02-12 18:24:31 +08:00
|
|
|
|
|
|
|
int rc = 0;
|
|
|
|
int stop = 0;
|
|
|
|
|
|
|
|
int eflags = ia->installInterfaceFlags & INSTALL_ERASE;
|
|
|
|
|
|
|
|
if (!(ia->installInterfaceFlags & INSTALL_NODEPS)) {
|
|
|
|
|
|
|
|
if (rpmtsCheck(ts)) {
|
|
|
|
rc = numPackages;
|
|
|
|
stop = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
ps = rpmtsProblems(ts);
|
|
|
|
if (!stop && rpmpsNumProblems(ps) > 0) {
|
|
|
|
rpmlog(RPMLOG_ERR, _("Failed dependencies:\n"));
|
|
|
|
rpmpsPrint(NULL, ps);
|
|
|
|
rc = numPackages;
|
|
|
|
stop = 1;
|
|
|
|
}
|
|
|
|
ps = rpmpsFree(ps);
|
|
|
|
}
|
|
|
|
|
2010-03-26 22:14:52 +08:00
|
|
|
if (!stop && !(ia->installInterfaceFlags & INSTALL_NOORDER)) {
|
2009-02-12 18:24:31 +08:00
|
|
|
if (rpmtsOrder(ts)) {
|
|
|
|
rc = numPackages;
|
|
|
|
stop = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (numPackages && !stop) {
|
2022-01-21 16:39:52 +08:00
|
|
|
const char *msg;
|
|
|
|
if (ia->installInterfaceFlags & INSTALL_RESTORE)
|
|
|
|
msg = "restoring packages";
|
|
|
|
else if (ia->installInterfaceFlags & INSTALL_ERASE)
|
|
|
|
msg = "erasing packages";
|
|
|
|
else
|
|
|
|
msg = "installing binary packages";
|
|
|
|
|
|
|
|
rpmlog(RPMLOG_DEBUG, "%s\n", msg);
|
2010-03-26 22:14:52 +08:00
|
|
|
rpmtsClean(ts);
|
|
|
|
rc = rpmtsRun(ts, NULL, ia->probFilter);
|
2009-02-12 18:24:31 +08:00
|
|
|
|
|
|
|
ps = rpmtsProblems(ts);
|
|
|
|
|
2014-08-19 23:41:13 +08:00
|
|
|
if (rpmpsNumProblems(ps) > 0 && (eflags || rc > 0))
|
|
|
|
rpmpsPrint(NULL, ps);
|
2009-02-12 18:24:31 +08:00
|
|
|
ps = rpmpsFree(ps);
|
|
|
|
}
|
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2009-02-12 20:27:35 +08:00
|
|
|
static int tryReadManifest(struct rpmEIU * eiu)
|
|
|
|
{
|
2009-05-28 14:43:40 +08:00
|
|
|
int rc;
|
2009-02-12 20:27:35 +08:00
|
|
|
|
|
|
|
/* Try to read a package manifest. */
|
2011-07-08 15:20:02 +08:00
|
|
|
FD_t fd = Fopen(*eiu->fnp, "r.ufdio");
|
2009-05-28 14:41:03 +08:00
|
|
|
if (fd == NULL || Ferror(fd)) {
|
2009-02-12 20:27:35 +08:00
|
|
|
rpmlog(RPMLOG_ERR, _("open of %s failed: %s\n"), *eiu->fnp,
|
2009-05-28 14:41:03 +08:00
|
|
|
Fstrerror(fd));
|
|
|
|
if (fd != NULL) {
|
2009-05-28 14:43:40 +08:00
|
|
|
Fclose(fd);
|
2009-05-28 14:41:03 +08:00
|
|
|
fd = NULL;
|
2009-02-12 20:27:35 +08:00
|
|
|
}
|
2016-03-30 16:28:14 +08:00
|
|
|
eiu->numFailed++;
|
|
|
|
*eiu->fnp = NULL;
|
2009-02-12 20:27:35 +08:00
|
|
|
return RPMRC_FAIL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Read list of packages from manifest. */
|
2009-05-28 14:41:03 +08:00
|
|
|
rc = rpmReadPackageManifest(fd, &eiu->argc, &eiu->argv);
|
2009-02-12 20:27:35 +08:00
|
|
|
if (rc != RPMRC_OK)
|
|
|
|
rpmlog(RPMLOG_ERR, _("%s: not an rpm package (or package manifest): %s\n"),
|
2009-05-28 14:41:03 +08:00
|
|
|
*eiu->fnp, Fstrerror(fd));
|
2009-05-28 14:43:40 +08:00
|
|
|
Fclose(fd);
|
2009-05-28 14:41:03 +08:00
|
|
|
fd = NULL;
|
2009-02-12 20:27:35 +08:00
|
|
|
|
2016-03-28 01:55:08 +08:00
|
|
|
if (rc != RPMRC_OK) {
|
|
|
|
eiu->numFailed++;
|
|
|
|
*eiu->fnp = NULL;
|
|
|
|
}
|
2009-02-12 20:27:35 +08:00
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2011-03-23 18:15:07 +08:00
|
|
|
static int tryReadHeader(rpmts ts, struct rpmEIU * eiu, Header * hdrp)
|
2009-03-14 19:08:10 +08:00
|
|
|
{
|
|
|
|
/* Try to read the header from a package file. */
|
2009-05-28 14:41:03 +08:00
|
|
|
FD_t fd = Fopen(*eiu->fnp, "r.ufdio");
|
|
|
|
if (fd == NULL || Ferror(fd)) {
|
2009-03-14 19:08:10 +08:00
|
|
|
rpmlog(RPMLOG_ERR, _("open of %s failed: %s\n"), *eiu->fnp,
|
2009-05-28 14:41:03 +08:00
|
|
|
Fstrerror(fd));
|
|
|
|
if (fd != NULL) {
|
|
|
|
Fclose(fd);
|
|
|
|
fd = NULL;
|
2009-03-14 19:08:10 +08:00
|
|
|
}
|
2016-03-30 16:28:14 +08:00
|
|
|
eiu->numFailed++;
|
|
|
|
*eiu->fnp = NULL;
|
2009-03-14 19:08:10 +08:00
|
|
|
return RPMRC_FAIL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Read the header, verifying signatures (if present). */
|
2011-03-23 18:15:07 +08:00
|
|
|
eiu->rpmrc = rpmReadPackageFile(ts, fd, *eiu->fnp, hdrp);
|
2009-05-28 14:41:03 +08:00
|
|
|
Fclose(fd);
|
|
|
|
fd = NULL;
|
2009-03-14 19:08:10 +08:00
|
|
|
|
|
|
|
/* Honor --nomanifest */
|
|
|
|
if (eiu->rpmrc == RPMRC_NOTFOUND && (giFlags & RPMGI_NOMANIFEST))
|
|
|
|
eiu->rpmrc = RPMRC_FAIL;
|
|
|
|
|
2017-02-27 23:37:18 +08:00
|
|
|
if (eiu->rpmrc == RPMRC_FAIL) {
|
2009-03-14 19:08:10 +08:00
|
|
|
rpmlog(RPMLOG_ERR, _("%s cannot be installed\n"), *eiu->fnp);
|
2016-03-30 16:28:14 +08:00
|
|
|
eiu->numFailed++;
|
|
|
|
*eiu->fnp = NULL;
|
2009-03-14 19:08:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return RPMRC_OK;
|
|
|
|
}
|
2009-02-12 18:24:31 +08:00
|
|
|
|
2009-03-14 20:02:59 +08:00
|
|
|
|
|
|
|
/* On --freshen, verify package is installed and newer */
|
2011-03-23 18:13:25 +08:00
|
|
|
static int checkFreshenStatus(rpmts ts, Header h)
|
2009-03-14 20:02:59 +08:00
|
|
|
{
|
|
|
|
rpmdbMatchIterator mi = NULL;
|
2011-03-23 18:13:25 +08:00
|
|
|
const char * name = headerGetString(h, RPMTAG_NAME);
|
|
|
|
const char *arch = headerGetString(h, RPMTAG_ARCH);
|
2010-06-01 18:55:15 +08:00
|
|
|
Header oldH = NULL;
|
2009-03-14 20:02:59 +08:00
|
|
|
|
|
|
|
if (name != NULL)
|
2010-10-22 16:49:52 +08:00
|
|
|
mi = rpmtsInitIterator(ts, RPMDBI_NAME, name, 0);
|
2010-06-01 18:55:15 +08:00
|
|
|
if (rpmtsColor(ts) && arch)
|
|
|
|
rpmdbSetIteratorRE(mi, RPMTAG_ARCH, RPMMIRE_DEFAULT, arch);
|
|
|
|
|
2009-03-14 20:02:59 +08:00
|
|
|
while ((oldH = rpmdbNextIterator(mi)) != NULL) {
|
2010-06-01 18:55:15 +08:00
|
|
|
/* Package is newer than those currently installed. */
|
2011-03-23 18:13:25 +08:00
|
|
|
if (rpmVersionCompare(oldH, h) < 0)
|
2010-06-01 18:55:15 +08:00
|
|
|
break;
|
2009-03-14 20:02:59 +08:00
|
|
|
}
|
2010-06-01 18:55:15 +08:00
|
|
|
|
2011-05-29 03:30:41 +08:00
|
|
|
rpmdbFreeIterator(mi);
|
2011-03-23 18:13:25 +08:00
|
|
|
return (oldH != NULL);
|
2009-03-14 20:02:59 +08:00
|
|
|
}
|
|
|
|
|
2014-08-26 17:34:47 +08:00
|
|
|
static int rpmNoGlob(const char *fn, int *argcPtr, ARGV_t * argvPtr)
|
|
|
|
{
|
|
|
|
struct stat sb;
|
|
|
|
int rc = stat(fn, &sb);
|
|
|
|
if (rc == 0) {
|
|
|
|
argvAdd(argvPtr, fn);
|
|
|
|
*argcPtr = 1;
|
|
|
|
} else {
|
|
|
|
*argcPtr = 0;
|
|
|
|
}
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2000-09-02 05:15:40 +08:00
|
|
|
/** @todo Generalize --freshen policies. */
|
2008-04-07 17:11:16 +08:00
|
|
|
int rpmInstall(rpmts ts, struct rpmInstallArguments_s * ia, ARGV_t fileArgv)
|
1999-11-27 00:19:30 +08:00
|
|
|
{
|
2008-04-25 18:54:59 +08:00
|
|
|
struct rpmEIU * eiu = xcalloc(1, sizeof(*eiu));
|
2002-03-13 23:06:07 +08:00
|
|
|
rpmRelocation * relocations;
|
2007-12-18 18:08:13 +08:00
|
|
|
char * fileURL = NULL;
|
2009-03-14 19:08:10 +08:00
|
|
|
rpmVSFlags vsflags, ovsflags;
|
2018-06-27 19:45:49 +08:00
|
|
|
rpmVSFlags ovfyflags;
|
2001-04-10 20:36:45 +08:00
|
|
|
int rc;
|
|
|
|
int i;
|
1999-07-14 23:28:03 +08:00
|
|
|
|
2011-04-19 15:09:22 +08:00
|
|
|
vsflags = setvsFlags(ia);
|
|
|
|
ovsflags = rpmtsSetVSFlags(ts, (vsflags | RPMVSF_NEEDPAYLOAD));
|
2018-06-27 19:45:49 +08:00
|
|
|
/* for rpm cli, --nosignature/--nodigest applies to both vs and vfyflags */
|
|
|
|
ovfyflags = rpmtsSetVfyFlags(ts, (rpmtsVfyFlags(ts) | rpmcliVSFlags));
|
2011-04-19 15:09:22 +08:00
|
|
|
|
2001-10-26 12:16:19 +08:00
|
|
|
if (fileArgv == NULL) goto exit;
|
2001-05-04 05:00:18 +08:00
|
|
|
|
2018-06-27 16:22:41 +08:00
|
|
|
if (rpmcliVfyLevelMask) {
|
|
|
|
int vfylevel = rpmtsVfyLevel(ts);
|
|
|
|
vfylevel &= ~rpmcliVfyLevelMask;
|
|
|
|
rpmtsSetVfyLevel(ts, vfylevel);
|
2018-06-19 19:27:58 +08:00
|
|
|
}
|
|
|
|
|
2002-03-17 23:49:09 +08:00
|
|
|
(void) rpmtsSetFlags(ts, ia->transFlags);
|
2003-12-26 07:00:44 +08:00
|
|
|
|
2002-03-13 23:06:07 +08:00
|
|
|
relocations = ia->relocations;
|
|
|
|
|
2009-02-12 20:00:21 +08:00
|
|
|
setNotifyFlag(ia, ts);
|
2001-09-15 21:49:11 +08:00
|
|
|
|
|
|
|
if ((eiu->relocations = relocations) != NULL) {
|
|
|
|
while (eiu->relocations->oldPath)
|
|
|
|
eiu->relocations++;
|
|
|
|
if (eiu->relocations->newPath == NULL)
|
|
|
|
eiu->relocations = NULL;
|
|
|
|
}
|
1999-07-14 23:28:03 +08:00
|
|
|
|
2001-04-10 20:36:45 +08:00
|
|
|
/* Build fully globbed list of arguments in argv[argc]. */
|
2001-09-15 21:49:11 +08:00
|
|
|
for (eiu->fnp = fileArgv; *eiu->fnp != NULL; eiu->fnp++) {
|
2008-04-21 15:33:02 +08:00
|
|
|
ARGV_t av = NULL;
|
|
|
|
int ac = 0;
|
|
|
|
|
2014-08-26 17:34:47 +08:00
|
|
|
if (giFlags & RPMGI_NOGLOB) {
|
2015-01-09 19:45:57 +08:00
|
|
|
rc = rpmNoGlob(*eiu->fnp, &ac, &av);
|
2014-08-26 17:34:47 +08:00
|
|
|
} else {
|
2015-01-09 19:45:57 +08:00
|
|
|
char * fn = rpmEscapeSpaces(*eiu->fnp);
|
2014-08-26 17:34:47 +08:00
|
|
|
rc = rpmGlob(fn, &ac, &av);
|
2015-01-09 19:45:57 +08:00
|
|
|
fn = _free(fn);
|
2014-08-26 17:34:47 +08:00
|
|
|
}
|
2002-10-26 22:43:43 +08:00
|
|
|
if (rc || ac == 0) {
|
2014-08-26 17:34:47 +08:00
|
|
|
if (giFlags & RPMGI_NOGLOB) {
|
|
|
|
rpmlog(RPMLOG_ERR, _("File not found: %s\n"), *eiu->fnp);
|
|
|
|
} else {
|
|
|
|
rpmlog(RPMLOG_ERR, _("File not found by glob: %s\n"), *eiu->fnp);
|
|
|
|
}
|
2008-08-05 20:32:49 +08:00
|
|
|
eiu->numFailed++;
|
2021-06-25 17:21:46 +08:00
|
|
|
argvFree(av);
|
2002-10-26 22:43:43 +08:00
|
|
|
continue;
|
|
|
|
}
|
1999-07-14 23:28:03 +08:00
|
|
|
|
2008-04-21 15:33:02 +08:00
|
|
|
argvAppend(&(eiu->argv), av);
|
|
|
|
argvFree(av);
|
2001-09-15 21:49:11 +08:00
|
|
|
eiu->argc += ac;
|
2001-04-10 20:36:45 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
restart:
|
|
|
|
/* Allocate sufficient storage for next set of args. */
|
2001-09-15 21:49:11 +08:00
|
|
|
if (eiu->pkgx >= eiu->numPkgs) {
|
|
|
|
eiu->numPkgs = eiu->pkgx + eiu->argc;
|
|
|
|
eiu->pkgURL = xrealloc(eiu->pkgURL,
|
|
|
|
(eiu->numPkgs + 1) * sizeof(*eiu->pkgURL));
|
|
|
|
memset(eiu->pkgURL + eiu->pkgx, 0,
|
|
|
|
((eiu->argc + 1) * sizeof(*eiu->pkgURL)));
|
|
|
|
eiu->pkgState = xrealloc(eiu->pkgState,
|
|
|
|
(eiu->numPkgs + 1) * sizeof(*eiu->pkgState));
|
|
|
|
memset(eiu->pkgState + eiu->pkgx, 0,
|
|
|
|
((eiu->argc + 1) * sizeof(*eiu->pkgState)));
|
2001-04-10 20:36:45 +08:00
|
|
|
}
|
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. */
|
2001-09-15 21:49:11 +08:00
|
|
|
for (i = 0; i < eiu->argc; i++) {
|
2001-04-10 20:36:45 +08:00
|
|
|
fileURL = _free(fileURL);
|
2001-09-15 21:49:11 +08:00
|
|
|
fileURL = eiu->argv[i];
|
|
|
|
eiu->argv[i] = NULL;
|
1999-07-14 23:28:03 +08:00
|
|
|
|
2001-04-10 20:36:45 +08:00
|
|
|
switch (urlIsURL(fileURL)) {
|
2004-11-04 21:29:11 +08:00
|
|
|
case URL_IS_HTTPS:
|
1999-07-14 23:28:03 +08:00
|
|
|
case URL_IS_HTTP:
|
2004-11-04 21:29:11 +08:00
|
|
|
case URL_IS_FTP:
|
2010-01-21 19:45:34 +08:00
|
|
|
{ char *tfn = NULL;
|
2008-04-11 16:45:35 +08:00
|
|
|
FD_t tfd;
|
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
|
|
|
|
2008-05-03 17:34:19 +08:00
|
|
|
tfd = rpmMkTempFile(rpmtsRootDir(ts), &tfn);
|
2008-04-11 16:45:35 +08:00
|
|
|
if (tfd && tfn) {
|
|
|
|
Fclose(tfd);
|
|
|
|
rc = urlGetFile(fileURL, tfn);
|
|
|
|
} else {
|
|
|
|
rc = -1;
|
1999-12-13 01:46:22 +08:00
|
|
|
}
|
2001-04-10 20:36:45 +08:00
|
|
|
|
2008-04-11 16:45:35 +08:00
|
|
|
if (rc != 0) {
|
2007-10-09 19:49:02 +08:00
|
|
|
rpmlog(RPMLOG_ERR,
|
2008-07-07 15:48:06 +08:00
|
|
|
_("skipping %s - transfer failed\n"), fileURL);
|
2001-09-15 21:49:11 +08:00
|
|
|
eiu->numFailed++;
|
|
|
|
eiu->pkgURL[eiu->pkgx] = NULL;
|
2001-04-10 20:36:45 +08:00
|
|
|
tfn = _free(tfn);
|
2007-09-12 01:07:39 +08:00
|
|
|
break;
|
1999-07-14 23:28:03 +08:00
|
|
|
}
|
2001-09-15 21:49:11 +08:00
|
|
|
eiu->pkgState[eiu->pkgx] = 1;
|
|
|
|
eiu->pkgURL[eiu->pkgx] = tfn;
|
|
|
|
eiu->pkgx++;
|
2007-09-12 01:07:39 +08:00
|
|
|
} break;
|
1999-11-27 00:19:30 +08:00
|
|
|
case URL_IS_PATH:
|
2004-11-29 05:14:41 +08:00
|
|
|
case URL_IS_DASH: /* WRONG WRONG WRONG */
|
|
|
|
case URL_IS_HKP: /* WRONG WRONG WRONG */
|
1999-07-14 23:28:03 +08:00
|
|
|
default:
|
2001-09-15 21:49:11 +08:00
|
|
|
eiu->pkgURL[eiu->pkgx] = fileURL;
|
2001-04-10 20:36:45 +08:00
|
|
|
fileURL = NULL;
|
2001-09-15 21:49:11 +08:00
|
|
|
eiu->pkgx++;
|
2007-09-12 01:07:39 +08:00
|
|
|
break;
|
1999-07-14 23:28:03 +08:00
|
|
|
}
|
|
|
|
}
|
2001-04-10 20:36:45 +08:00
|
|
|
fileURL = _free(fileURL);
|
1999-07-14 23:28:03 +08:00
|
|
|
|
2001-09-15 21:49:11 +08:00
|
|
|
if (eiu->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. */
|
2008-04-07 17:11:16 +08:00
|
|
|
for (eiu->fnp = eiu->pkgURL+eiu->prevx;
|
2001-09-15 21:49:11 +08:00
|
|
|
*eiu->fnp != NULL;
|
|
|
|
eiu->fnp++, eiu->prevx++)
|
|
|
|
{
|
2011-03-23 18:15:07 +08:00
|
|
|
Header h = NULL;
|
1999-11-27 00:19:30 +08:00
|
|
|
const char * fileName;
|
2001-04-10 20:36:45 +08:00
|
|
|
|
2007-10-09 19:48:04 +08:00
|
|
|
rpmlog(RPMLOG_DEBUG, "============== %s\n", *eiu->fnp);
|
2001-09-15 21:49:11 +08:00
|
|
|
(void) urlPath(*eiu->fnp, &fileName);
|
2001-02-13 03:02:15 +08:00
|
|
|
|
2011-03-23 18:15:07 +08:00
|
|
|
if (tryReadHeader(ts, eiu, &h) == RPMRC_FAIL)
|
1999-07-14 23:28:03 +08:00
|
|
|
continue;
|
|
|
|
|
2009-03-14 19:08:10 +08:00
|
|
|
if (eiu->rpmrc == RPMRC_NOTFOUND) {
|
2009-02-12 20:27:35 +08:00
|
|
|
rc = tryReadManifest(eiu);
|
|
|
|
if (rc == RPMRC_OK) {
|
|
|
|
eiu->prevx++;
|
2009-03-14 19:08:10 +08:00
|
|
|
goto restart;
|
2009-02-12 20:27:35 +08:00
|
|
|
}
|
2001-04-10 20:36:45 +08:00
|
|
|
}
|
2001-09-15 21:49:11 +08:00
|
|
|
|
2011-03-23 18:15:50 +08:00
|
|
|
if (headerIsSource(h)) {
|
2017-07-12 22:34:22 +08:00
|
|
|
if (ia->installInterfaceFlags & INSTALL_FRESHEN) {
|
|
|
|
headerFree(h);
|
|
|
|
continue;
|
|
|
|
}
|
2008-03-07 15:47:51 +08:00
|
|
|
rpmlog(RPMLOG_DEBUG, "\tadded source package [%d]\n",
|
2001-09-15 21:49:11 +08:00
|
|
|
eiu->numSRPMS);
|
|
|
|
eiu->sourceURL = xrealloc(eiu->sourceURL,
|
|
|
|
(eiu->numSRPMS + 2) * sizeof(*eiu->sourceURL));
|
|
|
|
eiu->sourceURL[eiu->numSRPMS] = *eiu->fnp;
|
|
|
|
*eiu->fnp = NULL;
|
|
|
|
eiu->numSRPMS++;
|
|
|
|
eiu->sourceURL[eiu->numSRPMS] = NULL;
|
2001-04-10 20:36:45 +08:00
|
|
|
continue;
|
|
|
|
}
|
2001-09-15 21:49:11 +08:00
|
|
|
|
2002-08-24 05:01:59 +08:00
|
|
|
if (eiu->relocations) {
|
2008-05-26 18:17:07 +08:00
|
|
|
struct rpmtd_s prefixes;
|
|
|
|
|
2011-03-23 18:15:07 +08:00
|
|
|
headerGet(h, RPMTAG_PREFIXES, &prefixes, HEADERGET_DEFAULT);
|
2008-05-26 18:17:07 +08:00
|
|
|
if (rpmtdCount(&prefixes) == 1) {
|
|
|
|
eiu->relocations->oldPath = xstrdup(rpmtdGetString(&prefixes));
|
|
|
|
rpmtdFreeData(&prefixes);
|
2002-08-24 05:01:59 +08:00
|
|
|
} else {
|
2009-09-02 17:06:34 +08:00
|
|
|
rpmlog(RPMLOG_ERR, _("package %s is not relocatable\n"),
|
2011-03-23 18:15:07 +08:00
|
|
|
headerGetString(h, RPMTAG_NAME));
|
2002-08-24 05:01:59 +08:00
|
|
|
eiu->numFailed++;
|
|
|
|
goto exit;
|
2001-04-10 20:36:45 +08:00
|
|
|
}
|
2002-08-24 05:01:59 +08:00
|
|
|
}
|
1999-07-14 23:28:03 +08:00
|
|
|
|
2009-03-14 20:02:59 +08:00
|
|
|
if (ia->installInterfaceFlags & INSTALL_FRESHEN)
|
2011-03-23 18:15:07 +08:00
|
|
|
if (checkFreshenStatus(ts, h) != 1) {
|
|
|
|
headerFree(h);
|
2009-03-14 20:02:59 +08:00
|
|
|
continue;
|
2011-03-23 18:13:25 +08:00
|
|
|
}
|
2000-06-23 08:49:43 +08:00
|
|
|
|
2014-03-04 19:43:01 +08:00
|
|
|
if (ia->installInterfaceFlags & INSTALL_REINSTALL)
|
|
|
|
rc = rpmtsAddReinstallElement(ts, h, (fnpyKey)fileName);
|
|
|
|
else
|
|
|
|
rc = rpmtsAddInstallElement(ts, h, (fnpyKey)fileName,
|
2002-03-17 23:49:09 +08:00
|
|
|
(ia->installInterfaceFlags & INSTALL_UPGRADE) != 0,
|
|
|
|
relocations);
|
2001-10-28 06:31:10 +08:00
|
|
|
|
2011-03-23 18:15:07 +08:00
|
|
|
headerFree(h);
|
2002-08-24 05:01:59 +08:00
|
|
|
if (eiu->relocations)
|
2008-03-25 04:42:34 +08:00
|
|
|
eiu->relocations->oldPath = _free(eiu->relocations->oldPath);
|
1999-09-21 11:22:53 +08:00
|
|
|
|
2017-02-27 23:37:18 +08:00
|
|
|
switch (rc) {
|
2002-08-24 05:01:59 +08:00
|
|
|
case 0:
|
2008-03-07 15:47:51 +08:00
|
|
|
rpmlog(RPMLOG_DEBUG, "\tadded binary package [%d]\n",
|
2001-09-15 21:49:11 +08:00
|
|
|
eiu->numRPMS);
|
2007-09-12 01:07:39 +08:00
|
|
|
break;
|
2002-08-24 05:01:59 +08:00
|
|
|
case 1:
|
2007-10-09 19:49:02 +08:00
|
|
|
rpmlog(RPMLOG_ERR,
|
2001-09-15 21:49:11 +08:00
|
|
|
_("error reading from file %s\n"), *eiu->fnp);
|
2002-08-24 05:01:59 +08:00
|
|
|
eiu->numFailed++;
|
|
|
|
goto exit;
|
2007-09-12 01:07:39 +08:00
|
|
|
break;
|
2007-04-16 20:16:35 +08:00
|
|
|
default:
|
|
|
|
eiu->numFailed++;
|
|
|
|
goto exit;
|
2007-09-12 01:07:39 +08:00
|
|
|
break;
|
2001-04-10 20:36:45 +08:00
|
|
|
}
|
1999-07-14 23:28:03 +08:00
|
|
|
|
2002-08-24 05:01:59 +08:00
|
|
|
eiu->numRPMS++;
|
1999-07-14 23:28:03 +08:00
|
|
|
}
|
|
|
|
|
2008-03-07 15:47:51 +08:00
|
|
|
rpmlog(RPMLOG_DEBUG, "found %d source and %d binary packages\n",
|
2001-09-15 21:49:11 +08:00
|
|
|
eiu->numSRPMS, eiu->numRPMS);
|
1999-07-14 23:28:03 +08:00
|
|
|
|
2001-09-15 21:49:11 +08:00
|
|
|
if (eiu->numFailed) goto exit;
|
2001-02-10 22:35:55 +08:00
|
|
|
|
2009-02-12 18:24:31 +08:00
|
|
|
if (eiu->numRPMS) {
|
2022-01-27 16:28:37 +08:00
|
|
|
int rc = rpmcliTransaction(ts, ia);
|
2009-02-12 18:24:31 +08:00
|
|
|
if (rc < 0)
|
|
|
|
eiu->numFailed += eiu->numRPMS;
|
|
|
|
else if (rc > 0)
|
|
|
|
eiu->numFailed += rc;
|
1999-07-14 23:28:03 +08:00
|
|
|
}
|
|
|
|
|
2009-02-12 19:43:20 +08:00
|
|
|
if (eiu->numSRPMS && (eiu->sourceURL != NULL)) {
|
2014-03-26 15:37:32 +08:00
|
|
|
rpmcliProgressState = 0;
|
|
|
|
rpmcliProgressTotal = 0;
|
|
|
|
rpmcliProgressCurrent = 0;
|
2001-09-15 21:49:11 +08:00
|
|
|
for (i = 0; i < eiu->numSRPMS; i++) {
|
2009-02-12 19:43:20 +08:00
|
|
|
if (eiu->sourceURL[i] != NULL) {
|
|
|
|
rc = RPMRC_OK;
|
|
|
|
if (!(rpmtsFlags(ts) & RPMTRANS_FLAG_TEST))
|
|
|
|
rc = rpmInstallSource(ts, eiu->sourceURL[i], NULL, NULL);
|
|
|
|
if (rc != 0)
|
|
|
|
eiu->numFailed++;
|
2001-02-13 03:02:15 +08:00
|
|
|
}
|
1999-07-14 23:28:03 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-04-10 20:36:45 +08:00
|
|
|
exit:
|
2009-02-12 19:43:20 +08:00
|
|
|
if (eiu->pkgURL != NULL) {
|
|
|
|
for (i = 0; i < eiu->numPkgs; i++) {
|
|
|
|
if (eiu->pkgURL[i] == NULL) continue;
|
|
|
|
if (eiu->pkgState[i] == 1)
|
|
|
|
(void) unlink(eiu->pkgURL[i]);
|
|
|
|
eiu->pkgURL[i] = _free(eiu->pkgURL[i]);
|
|
|
|
}
|
1999-07-14 23:28:03 +08:00
|
|
|
}
|
2001-09-15 21:49:11 +08:00
|
|
|
eiu->pkgState = _free(eiu->pkgState);
|
|
|
|
eiu->pkgURL = _free(eiu->pkgURL);
|
|
|
|
eiu->argv = _free(eiu->argv);
|
2008-05-07 17:15:22 +08:00
|
|
|
rc = eiu->numFailed;
|
2008-04-25 18:54:59 +08:00
|
|
|
free(eiu);
|
2001-10-26 12:16:19 +08:00
|
|
|
|
2002-08-16 02:50:46 +08:00
|
|
|
rpmtsEmpty(ts);
|
2011-04-19 15:09:22 +08:00
|
|
|
rpmtsSetVSFlags(ts, ovsflags);
|
2018-06-27 19:45:49 +08:00
|
|
|
rpmtsSetVfyFlags(ts, ovfyflags);
|
2002-08-16 02:50:46 +08:00
|
|
|
|
2008-05-07 17:15:22 +08:00
|
|
|
return rc;
|
1999-07-14 23:28:03 +08:00
|
|
|
}
|
|
|
|
|
2008-04-07 17:11:16 +08:00
|
|
|
int rpmErase(rpmts ts, struct rpmInstallArguments_s * ia, ARGV_const_t argv)
|
2000-03-23 23:49:50 +08:00
|
|
|
{
|
2008-04-07 17:11:16 +08:00
|
|
|
char * const * arg;
|
2008-09-18 15:26:39 +08:00
|
|
|
char *qfmt = NULL;
|
1999-07-14 23:28:03 +08:00
|
|
|
int numFailed = 0;
|
|
|
|
int numPackages = 0;
|
2002-08-08 05:55:43 +08:00
|
|
|
rpmVSFlags vsflags, ovsflags;
|
1999-07-14 23:28:03 +08:00
|
|
|
|
2001-05-04 05:00:18 +08:00
|
|
|
if (argv == NULL) return 0;
|
|
|
|
|
2009-02-12 19:55:09 +08:00
|
|
|
vsflags = setvsFlags(ia);
|
2002-08-06 09:41:44 +08:00
|
|
|
ovsflags = rpmtsSetVSFlags(ts, vsflags);
|
2002-07-25 00:21:23 +08:00
|
|
|
|
2002-03-17 23:49:09 +08:00
|
|
|
(void) rpmtsSetFlags(ts, ia->transFlags);
|
2002-03-13 23:06:07 +08:00
|
|
|
|
2009-02-12 20:00:21 +08:00
|
|
|
setNotifyFlag(ia, ts);
|
2002-03-13 23:06:07 +08:00
|
|
|
|
2008-09-18 15:26:39 +08:00
|
|
|
qfmt = rpmExpand("%{?_query_all_fmt}\n", NULL);
|
1999-07-14 23:28:03 +08:00
|
|
|
for (arg = argv; *arg; arg++) {
|
2012-09-06 15:48:51 +08:00
|
|
|
rpmdbMatchIterator mi = rpmtsInitIterator(ts, RPMDBI_LABEL, *arg, 0);
|
|
|
|
int matches = rpmdbGetIteratorCount(mi);
|
2008-09-18 15:26:39 +08:00
|
|
|
int erasing = 1;
|
2000-04-27 08:10:28 +08:00
|
|
|
|
2008-09-18 15:04:51 +08:00
|
|
|
if (! matches) {
|
2007-10-09 19:49:02 +08:00
|
|
|
rpmlog(RPMLOG_ERR, _("package %s is not installed\n"), *arg);
|
2000-04-27 08:10:28 +08:00
|
|
|
numFailed++;
|
|
|
|
} else {
|
|
|
|
Header h; /* XXX iterator owns the reference */
|
2003-06-25 03:29:36 +08:00
|
|
|
|
2008-09-18 15:26:39 +08:00
|
|
|
if (matches > 1 &&
|
2009-02-12 18:24:31 +08:00
|
|
|
!(ia->installInterfaceFlags & UNINSTALL_ALLMATCHES)) {
|
2008-09-18 15:26:39 +08:00
|
|
|
rpmlog(RPMLOG_ERR, _("\"%s\" specifies multiple packages:\n"),
|
2003-06-25 03:29:36 +08:00
|
|
|
*arg);
|
2008-09-18 15:26:39 +08:00
|
|
|
numFailed++;
|
|
|
|
erasing = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
while ((h = rpmdbNextIterator(mi)) != NULL) {
|
2008-11-13 01:36:58 +08:00
|
|
|
if (erasing) {
|
|
|
|
(void) rpmtsAddEraseElement(ts, h, -1);
|
2000-04-27 08:10:28 +08:00
|
|
|
numPackages++;
|
2008-09-18 15:26:39 +08:00
|
|
|
} else {
|
|
|
|
char *nevra = headerFormat(h, qfmt, NULL);
|
|
|
|
rpmlog(RPMLOG_NOTICE, " %s", nevra);
|
|
|
|
free(nevra);
|
2000-04-27 08:10:28 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-09-06 15:48:51 +08:00
|
|
|
rpmdbFreeIterator(mi);
|
1999-07-14 23:28:03 +08:00
|
|
|
}
|
2008-09-18 15:26:39 +08:00
|
|
|
free(qfmt);
|
1999-07-14 23:28:03 +08:00
|
|
|
|
2004-10-10 03:40:09 +08:00
|
|
|
if (numFailed) goto exit;
|
2022-01-27 16:28:37 +08:00
|
|
|
numFailed = rpmcliTransaction(ts, ia);
|
2004-10-10 03:40:09 +08:00
|
|
|
exit:
|
2002-08-16 02:50:46 +08:00
|
|
|
rpmtsEmpty(ts);
|
2011-04-19 15:09:22 +08:00
|
|
|
rpmtsSetVSFlags(ts, ovsflags);
|
2002-08-16 02:50:46 +08:00
|
|
|
|
2018-03-09 16:25:37 +08:00
|
|
|
return (numFailed < 0) ? numPackages : numFailed;
|
1999-07-14 23:28:03 +08:00
|
|
|
}
|
|
|
|
|
2022-01-21 16:39:52 +08:00
|
|
|
static int handleRestorePackage(QVA_t qva, rpmts ts, Header h)
|
|
|
|
{
|
|
|
|
return rpmtsAddRestoreElement(ts, h);
|
|
|
|
}
|
|
|
|
|
|
|
|
int rpmRestore(rpmts ts, struct rpmInstallArguments_s * ia, ARGV_const_t argv)
|
|
|
|
{
|
|
|
|
QVA_t qva = &rpmQVKArgs;
|
|
|
|
int rc;
|
|
|
|
rpmVSFlags vsflags = setvsFlags(ia);
|
|
|
|
rpmVSFlags ovsflags = rpmtsSetVSFlags(ts, vsflags);
|
|
|
|
|
|
|
|
rpmtsSetFlags(ts, ia->transFlags);
|
|
|
|
setNotifyFlag(ia, ts);
|
|
|
|
|
|
|
|
if (qva->qva_showPackage == NULL)
|
|
|
|
qva->qva_showPackage = handleRestorePackage;
|
|
|
|
|
|
|
|
rc = rpmcliArgIter(ts, qva, argv);
|
|
|
|
if (rc == 0) {
|
|
|
|
rc = rpmcliTransaction(ts, ia);
|
|
|
|
}
|
|
|
|
|
|
|
|
rpmtsEmpty(ts);
|
|
|
|
rpmtsSetVSFlags(ts, ovsflags);
|
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2002-05-20 02:42:25 +08:00
|
|
|
int rpmInstallSource(rpmts ts, const char * arg,
|
2007-12-18 17:56:54 +08:00
|
|
|
char ** specFilePtr, char ** cookie)
|
2000-06-19 19:35:29 +08:00
|
|
|
{
|
1999-07-14 23:28:03 +08:00
|
|
|
FD_t fd;
|
|
|
|
int rc;
|
|
|
|
|
2002-08-08 05:55:43 +08:00
|
|
|
|
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)) {
|
2007-10-09 19:49:02 +08:00
|
|
|
rpmlog(RPMLOG_ERR, _("cannot open %s: %s\n"), arg, Fstrerror(fd));
|
2003-01-24 04:23:24 +08:00
|
|
|
if (fd != NULL) (void) Fclose(fd);
|
1999-07-14 23:28:03 +08:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2009-02-12 19:43:20 +08:00
|
|
|
if (rpmIsVerbose() && specFilePtr != NULL)
|
1999-07-14 23:28:03 +08:00
|
|
|
fprintf(stdout, _("Installing %s\n"), arg);
|
|
|
|
|
2001-05-04 05:00:18 +08:00
|
|
|
{
|
2002-08-09 00:06:13 +08:00
|
|
|
rpmVSFlags ovsflags =
|
2009-02-12 19:43:20 +08:00
|
|
|
rpmtsSetVSFlags(ts, (specFilePtr) ? (rpmtsVSFlags(ts) | RPMVSF_NEEDPAYLOAD) : rpmtsVSFlags(ts));
|
2002-04-11 06:10:13 +08:00
|
|
|
rpmRC rpmrc = rpmInstallSourcePackage(ts, fd, specFilePtr, cookie);
|
2001-02-13 03:02:15 +08:00
|
|
|
rc = (rpmrc == RPMRC_OK ? 0 : 1);
|
2011-05-30 20:50:29 +08:00
|
|
|
rpmtsSetVSFlags(ts, ovsflags);
|
2001-02-13 03:02:15 +08:00
|
|
|
}
|
|
|
|
if (rc != 0) {
|
2007-10-09 19:49:02 +08:00
|
|
|
rpmlog(RPMLOG_ERR, _("%s cannot be installed\n"), arg);
|
2002-04-11 06:10:13 +08:00
|
|
|
if (specFilePtr && *specFilePtr)
|
|
|
|
*specFilePtr = _free(*specFilePtr);
|
2001-03-24 04:27:48 +08:00
|
|
|
if (cookie && *cookie)
|
|
|
|
*cookie = _free(*cookie);
|
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
|
|
|
|