2002-07-01 06:47:32 +08:00
|
|
|
#include "system.h"
|
2005-01-18 07:58:09 +08:00
|
|
|
const char *__progname;
|
2002-07-01 06:47:32 +08:00
|
|
|
|
2007-12-08 20:02:32 +08:00
|
|
|
#include <rpm/rpmcli.h>
|
2002-07-01 06:47:32 +08:00
|
|
|
|
2007-12-08 20:02:32 +08:00
|
|
|
#include <rpm/rpmdb.h>
|
|
|
|
#include <rpm/rpmps.h>
|
|
|
|
#include <rpm/rpmte.h>
|
|
|
|
#include <rpm/rpmts.h>
|
|
|
|
#include <rpm/rpmds.h>
|
2002-07-01 06:47:32 +08:00
|
|
|
|
2007-12-08 20:02:32 +08:00
|
|
|
#include <rpm/rpmlog.h>
|
|
|
|
#include <rpm/rpmfileutil.h>
|
2007-11-23 16:27:29 +08:00
|
|
|
|
2007-11-23 18:47:48 +08:00
|
|
|
#include "lib/manifest.h"
|
2002-07-01 06:47:32 +08:00
|
|
|
#include "debug.h"
|
|
|
|
|
2002-07-02 21:16:50 +08:00
|
|
|
static int noDeps = 1;
|
2002-07-01 06:47:32 +08:00
|
|
|
|
2002-08-06 09:41:44 +08:00
|
|
|
static rpmVSFlags vsflags = 0;
|
2002-07-01 06:47:32 +08:00
|
|
|
|
2007-10-26 19:24:14 +08:00
|
|
|
static inline const char * identifyDepend(int32_t f)
|
2002-07-01 06:47:32 +08:00
|
|
|
{
|
|
|
|
if (isLegacyPreReq(f))
|
|
|
|
return "PreReq:";
|
|
|
|
f = _notpre(f);
|
|
|
|
if (f & RPMSENSE_SCRIPT_PRE)
|
|
|
|
return "Requires(pre):";
|
|
|
|
if (f & RPMSENSE_SCRIPT_POST)
|
|
|
|
return "Requires(post):";
|
|
|
|
if (f & RPMSENSE_SCRIPT_PREUN)
|
|
|
|
return "Requires(preun):";
|
|
|
|
if (f & RPMSENSE_SCRIPT_POSTUN)
|
|
|
|
return "Requires(postun):";
|
|
|
|
if (f & RPMSENSE_SCRIPT_VERIFY)
|
|
|
|
return "Requires(verify):";
|
|
|
|
if (f & RPMSENSE_FIND_REQUIRES)
|
|
|
|
return "Requires(auto):";
|
|
|
|
return "Requires:";
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
rpmGraph(rpmts ts, struct rpmInstallArguments_s * ia, const char ** fileArgv)
|
|
|
|
{
|
2002-07-02 21:16:50 +08:00
|
|
|
rpmps ps;
|
2007-12-18 16:17:18 +08:00
|
|
|
char ** pkgURL = NULL;
|
2002-07-01 06:47:32 +08:00
|
|
|
char * pkgState = NULL;
|
|
|
|
const char ** fnp;
|
2007-12-18 16:17:18 +08:00
|
|
|
char * fileURL = NULL;
|
2002-07-01 06:47:32 +08:00
|
|
|
int numPkgs = 0;
|
|
|
|
int numFailed = 0;
|
|
|
|
int prevx = 0;
|
|
|
|
int pkgx = 0;
|
2007-12-18 16:17:18 +08:00
|
|
|
char ** argv = NULL;
|
2002-07-01 06:47:32 +08:00
|
|
|
int argc = 0;
|
2007-12-18 16:17:18 +08:00
|
|
|
char ** av = NULL;
|
2002-07-01 06:47:32 +08:00
|
|
|
int ac = 0;
|
|
|
|
Header h;
|
|
|
|
rpmRC rpmrc;
|
|
|
|
int rc = 0;
|
2002-08-06 09:41:44 +08:00
|
|
|
rpmVSFlags ovsflags;
|
2002-07-01 06:47:32 +08:00
|
|
|
int i;
|
|
|
|
|
|
|
|
if (fileArgv == NULL)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (ia->qva_flags & VERIFY_DIGEST)
|
2002-08-06 09:41:44 +08:00
|
|
|
vsflags |= _RPMVSF_NODIGESTS;
|
2002-07-01 06:47:32 +08:00
|
|
|
if (ia->qva_flags & VERIFY_SIGNATURE)
|
2002-08-06 09:41:44 +08:00
|
|
|
vsflags |= _RPMVSF_NOSIGNATURES;
|
|
|
|
ovsflags = rpmtsSetVSFlags(ts, vsflags);
|
2002-07-01 06:47:32 +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;
|
|
|
|
|
|
|
|
argv = xrealloc(argv, (argc+2) * sizeof(*argv));
|
|
|
|
memcpy(argv+argc, av, ac * sizeof(*av));
|
|
|
|
argc += ac;
|
|
|
|
argv[argc] = NULL;
|
|
|
|
}
|
|
|
|
av = _free(av); ac = 0;
|
|
|
|
|
|
|
|
restart:
|
|
|
|
/* Allocate sufficient storage for next set of args. */
|
|
|
|
if (pkgx >= numPkgs) {
|
|
|
|
numPkgs = pkgx + argc;
|
|
|
|
pkgURL = xrealloc(pkgURL, (numPkgs + 1) * sizeof(*pkgURL));
|
|
|
|
memset(pkgURL + pkgx, 0, ((argc + 1) * sizeof(*pkgURL)));
|
|
|
|
pkgState = xrealloc(pkgState, (numPkgs + 1) * sizeof(*pkgState));
|
|
|
|
memset(pkgState + pkgx, 0, ((argc + 1) * sizeof(*pkgState)));
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Copy next set of args. */
|
|
|
|
for (i = 0; i < argc; i++) {
|
|
|
|
fileURL = _free(fileURL);
|
|
|
|
fileURL = argv[i];
|
|
|
|
argv[i] = NULL;
|
|
|
|
|
|
|
|
pkgURL[pkgx] = fileURL;
|
|
|
|
fileURL = NULL;
|
|
|
|
pkgx++;
|
|
|
|
}
|
|
|
|
fileURL = _free(fileURL);
|
|
|
|
|
|
|
|
/* Continue processing file arguments, building transaction set. */
|
2007-12-18 18:53:16 +08:00
|
|
|
for (fnp = (const char **) pkgURL+prevx; *fnp != NULL; fnp++, prevx++) {
|
2002-07-01 06:47:32 +08:00
|
|
|
const char * fileName;
|
|
|
|
FD_t fd;
|
|
|
|
|
|
|
|
(void) urlPath(*fnp, &fileName);
|
|
|
|
|
|
|
|
/* Try to read the header from a package file. */
|
|
|
|
fd = Fopen(*fnp, "r.ufdio");
|
|
|
|
if (fd == NULL || Ferror(fd)) {
|
2007-11-19 22:25:24 +08:00
|
|
|
rpmlog(RPMLOG_ERR, _("open of %s failed: %s\n"), *fnp,
|
2002-07-01 06:47:32 +08:00
|
|
|
Fstrerror(fd));
|
|
|
|
if (fd) {
|
|
|
|
Fclose(fd);
|
|
|
|
fd = NULL;
|
|
|
|
}
|
|
|
|
numFailed++; *fnp = NULL;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Read the header, verifying signatures (if present). */
|
2002-08-06 09:41:44 +08:00
|
|
|
ovsflags = rpmtsSetVSFlags(ts, vsflags);
|
2002-07-01 06:47:32 +08:00
|
|
|
rpmrc = rpmReadPackageFile(ts, fd, *fnp, &h);
|
2002-08-06 09:41:44 +08:00
|
|
|
ovsflags = rpmtsSetVSFlags(ts, ovsflags);
|
2002-07-01 06:47:32 +08:00
|
|
|
Fclose(fd);
|
|
|
|
fd = NULL;
|
|
|
|
|
2002-08-24 05:01:59 +08:00
|
|
|
switch (rpmrc) {
|
|
|
|
case RPMRC_FAIL:
|
|
|
|
default:
|
2007-10-09 19:49:02 +08:00
|
|
|
rpmlog(RPMLOG_ERR, _("%s cannot be installed\n"), *fnp);
|
2002-07-01 06:47:32 +08:00
|
|
|
numFailed++; *fnp = NULL;
|
2007-09-11 22:17:16 +08:00
|
|
|
break;
|
2002-08-24 05:01:59 +08:00
|
|
|
case RPMRC_OK:
|
|
|
|
rc = rpmtsAddInstallElement(ts, h, (fnpyKey)fileName, 0, NULL);
|
2007-09-11 22:17:16 +08:00
|
|
|
break;
|
2002-08-24 05:01:59 +08:00
|
|
|
case RPMRC_NOTFOUND:
|
|
|
|
goto maybe_manifest;
|
2007-09-11 22:17:16 +08:00
|
|
|
break;
|
2002-07-01 06:47:32 +08:00
|
|
|
}
|
2002-08-24 05:01:59 +08:00
|
|
|
h = headerFree(h);
|
|
|
|
continue;
|
2002-07-01 06:47:32 +08:00
|
|
|
|
2002-08-24 05:01:59 +08:00
|
|
|
maybe_manifest:
|
2002-07-01 06:47:32 +08:00
|
|
|
/* Try to read a package manifest. */
|
|
|
|
fd = Fopen(*fnp, "r.fpio");
|
|
|
|
if (fd == NULL || Ferror(fd)) {
|
2007-11-19 22:25:24 +08:00
|
|
|
rpmlog(RPMLOG_ERR, _("open of %s failed: %s\n"), *fnp,
|
2002-07-01 06:47:32 +08:00
|
|
|
Fstrerror(fd));
|
|
|
|
if (fd) {
|
|
|
|
Fclose(fd);
|
|
|
|
fd = NULL;
|
|
|
|
}
|
|
|
|
numFailed++; *fnp = NULL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Read list of packages from manifest. */
|
|
|
|
rc = rpmReadPackageManifest(fd, &argc, &argv);
|
|
|
|
if (rc)
|
2007-11-19 22:25:24 +08:00
|
|
|
rpmlog(RPMLOG_NOTICE, _("%s: read manifest failed: %s\n"),
|
2002-07-01 06:47:32 +08:00
|
|
|
fileURL, Fstrerror(fd));
|
|
|
|
Fclose(fd);
|
|
|
|
fd = NULL;
|
|
|
|
|
|
|
|
/* If successful, restart the query loop. */
|
|
|
|
if (rc == 0) {
|
|
|
|
prevx++;
|
|
|
|
goto restart;
|
|
|
|
}
|
|
|
|
|
|
|
|
numFailed++; *fnp = NULL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2002-07-02 21:16:50 +08:00
|
|
|
if (numFailed > 0) goto exit;
|
|
|
|
|
|
|
|
if (!noDeps) {
|
|
|
|
rc = rpmtsCheck(ts);
|
|
|
|
if (rc) {
|
|
|
|
numFailed += numPkgs;
|
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
ps = rpmtsProblems(ts);
|
|
|
|
if (rpmpsNumProblems(ps) > 0) {
|
2007-10-09 19:49:02 +08:00
|
|
|
rpmlog(RPMLOG_ERR, _("Failed dependencies:\n"));
|
2002-07-02 21:16:50 +08:00
|
|
|
rpmpsPrint(NULL, ps);
|
|
|
|
numFailed += numPkgs;
|
|
|
|
|
2007-10-31 16:37:18 +08:00
|
|
|
if (!(rpmtsFlags(ts) & RPMTRANS_FLAG_NOSUGGEST))
|
|
|
|
rpmtsPrintSuggests(ts);
|
2002-07-02 21:16:50 +08:00
|
|
|
|
|
|
|
}
|
|
|
|
ps = rpmpsFree(ps);
|
|
|
|
}
|
|
|
|
|
2002-07-01 06:47:32 +08:00
|
|
|
rc = rpmtsOrder(ts);
|
|
|
|
if (rc)
|
|
|
|
goto exit;
|
|
|
|
|
|
|
|
{ rpmtsi pi;
|
|
|
|
rpmte p;
|
|
|
|
rpmte q;
|
|
|
|
unsigned char * selected =
|
|
|
|
alloca(sizeof(*selected) * (rpmtsNElements(ts) + 1));
|
|
|
|
int oType = TR_ADDED;
|
|
|
|
|
|
|
|
fprintf(stdout, "digraph XXX {\n");
|
|
|
|
|
|
|
|
fprintf(stdout, " rankdir=LR\n");
|
|
|
|
|
|
|
|
fprintf(stdout, "//===== Packages:\n");
|
|
|
|
pi = rpmtsiInit(ts);
|
|
|
|
while ((p = rpmtsiNext(pi, oType)) != NULL) {
|
|
|
|
fprintf(stdout, "//%5d%5d %s\n", rpmteTree(p), rpmteDepth(p), rpmteN(p));
|
|
|
|
q = rpmteParent(p);
|
|
|
|
if (q != NULL)
|
|
|
|
fprintf(stdout, " \"%s\" -> \"%s\"\n", rpmteN(p), rpmteN(q));
|
|
|
|
else {
|
|
|
|
fprintf(stdout, " \"%s\"\n", rpmteN(p));
|
|
|
|
fprintf(stdout, " { rank=max ; \"%s\" }\n", rpmteN(p));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
pi = rpmtsiFree(pi);
|
|
|
|
|
|
|
|
fprintf(stdout, "}\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
rc = 0;
|
|
|
|
|
|
|
|
exit:
|
|
|
|
for (i = 0; i < numPkgs; i++)
|
|
|
|
pkgURL[i] = _free(pkgURL[i]);
|
|
|
|
pkgState = _free(pkgState);
|
|
|
|
pkgURL = _free(pkgURL);
|
|
|
|
argv = _free(argv);
|
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct poptOption optionsTable[] = {
|
2002-07-02 21:16:50 +08:00
|
|
|
{ "check", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &noDeps, 0,
|
|
|
|
N_("don't verify package dependencies"), NULL },
|
2002-08-06 09:41:44 +08:00
|
|
|
{ "nolegacy", '\0', POPT_BIT_SET, &vsflags, RPMVSF_NEEDPAYLOAD,
|
2002-07-01 06:47:32 +08:00
|
|
|
N_("don't verify header+payload signature"), NULL },
|
|
|
|
{ NULL, '\0', POPT_ARG_INCLUDE_TABLE, rpmcliAllPoptTable, 0,
|
|
|
|
N_("Common options for all rpm modes and executables:"),
|
|
|
|
NULL },
|
|
|
|
|
|
|
|
POPT_AUTOALIAS
|
|
|
|
POPT_AUTOHELP
|
|
|
|
POPT_TABLEEND
|
|
|
|
};
|
|
|
|
|
|
|
|
int
|
2007-09-18 11:53:37 +08:00
|
|
|
main(int argc, char *argv[])
|
2002-07-01 06:47:32 +08:00
|
|
|
{
|
|
|
|
rpmts ts = NULL;
|
|
|
|
struct rpmInstallArguments_s * ia = &rpmIArgs;
|
|
|
|
poptContext optCon;
|
|
|
|
int ec = 0;
|
|
|
|
|
|
|
|
optCon = rpmcliInit(argc, argv, optionsTable);
|
|
|
|
if (optCon == NULL)
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
|
|
|
|
ts = rpmtsCreate();
|
2002-07-28 08:41:15 +08:00
|
|
|
if (rpmcliQueryFlags & VERIFY_DIGEST)
|
2002-08-06 09:41:44 +08:00
|
|
|
vsflags |= _RPMVSF_NODIGESTS;
|
2002-07-28 08:41:15 +08:00
|
|
|
if (rpmcliQueryFlags & VERIFY_SIGNATURE)
|
2002-08-06 09:41:44 +08:00
|
|
|
vsflags |= _RPMVSF_NOSIGNATURES;
|
2002-07-28 08:41:15 +08:00
|
|
|
if (rpmcliQueryFlags & VERIFY_HDRCHK)
|
2002-08-06 09:41:44 +08:00
|
|
|
vsflags |= RPMVSF_NOHDRCHK;
|
|
|
|
(void) rpmtsSetVSFlags(ts, vsflags);
|
2002-07-01 06:47:32 +08:00
|
|
|
|
|
|
|
ec = rpmGraph(ts, ia, poptGetArgs(optCon));
|
|
|
|
|
|
|
|
ts = rpmtsFree(ts);
|
|
|
|
|
|
|
|
optCon = rpmcliFini(optCon);
|
|
|
|
|
|
|
|
return ec;
|
|
|
|
}
|