3 #include <rpm/rpmcli.h>
4 #include <rpm/rpmlib.h> /* rpmReadPackageFile */
11 #include <rpm/rpmlog.h>
12 #include <rpm/rpmfileutil.h>
14 #include "lib/manifest.h"
17 static int noDeps = 1;
19 static rpmVSFlags vsflags = 0;
22 rpmGraph(rpmts ts, struct rpmInstallArguments_s * ia, const char ** fileArgv)
24 char ** pkgURL = NULL;
25 char * pkgState = NULL;
27 char * fileURL = NULL;
45 /* Build fully globbed list of arguments in argv[argc]. */
46 for (fnp = fileArgv; *fnp; fnp++) {
49 rc = rpmGlob(*fnp, &ac, &av);
50 if (rc || ac == 0) continue;
52 argv = xrealloc(argv, (argc+2) * sizeof(*argv));
53 memcpy(argv+argc, av, ac * sizeof(*av));
57 av = _free(av); ac = 0;
60 /* Allocate sufficient storage for next set of args. */
61 if (pkgx >= numPkgs) {
62 numPkgs = pkgx + argc;
63 pkgURL = xrealloc(pkgURL, (numPkgs + 1) * sizeof(*pkgURL));
64 memset(pkgURL + pkgx, 0, ((argc + 1) * sizeof(*pkgURL)));
65 pkgState = xrealloc(pkgState, (numPkgs + 1) * sizeof(*pkgState));
66 memset(pkgState + pkgx, 0, ((argc + 1) * sizeof(*pkgState)));
69 /* Copy next set of args. */
70 for (i = 0; i < argc; i++) {
71 fileURL = _free(fileURL);
75 pkgURL[pkgx] = fileURL;
79 fileURL = _free(fileURL);
81 /* Continue processing file arguments, building transaction set. */
82 for (fnp = (const char **) pkgURL+prevx; *fnp != NULL; fnp++, prevx++) {
83 const char * fileName;
86 (void) urlPath(*fnp, &fileName);
88 /* Try to read the header from a package file. */
89 fd = Fopen(*fnp, "r.ufdio");
90 if (fd == NULL || Ferror(fd)) {
91 rpmlog(RPMLOG_ERR, _("open of %s failed: %s\n"), *fnp,
97 numFailed++; *fnp = NULL;
101 /* Read the header, verifying signatures (if present). */
102 ovsflags = rpmtsSetVSFlags(ts, vsflags);
103 rpmrc = rpmReadPackageFile(ts, fd, *fnp, &h);
104 rpmtsSetVSFlags(ts, ovsflags);
111 rpmlog(RPMLOG_ERR, _("%s cannot be installed\n"), *fnp);
112 numFailed++; *fnp = NULL;
115 rc = rpmtsAddInstallElement(ts, h, (fnpyKey)fileName, 0, NULL);
125 /* Try to read a package manifest. */
126 fd = Fopen(*fnp, "r.ufdio");
127 if (fd == NULL || Ferror(fd)) {
128 rpmlog(RPMLOG_ERR, _("open of %s failed: %s\n"), *fnp,
134 numFailed++; *fnp = NULL;
138 /* Read list of packages from manifest. */
139 rc = rpmReadPackageManifest(fd, &argc, &argv);
141 rpmlog(RPMLOG_NOTICE, _("%s: read manifest failed: %s\n"),
142 fileURL, Fstrerror(fd));
146 /* If successful, restart the query loop. */
152 numFailed++; *fnp = NULL;
156 if (numFailed > 0) goto exit;
162 numFailed += numPkgs;
165 ps = rpmtsProblems(ts);
166 if (rpmpsNumProblems(ps) > 0) {
167 rpmlog(RPMLOG_ERR, _("Failed dependencies:\n"));
168 rpmpsPrint(NULL, ps);
169 numFailed += numPkgs;
181 int oType = TR_ADDED;
183 fprintf(stdout, "digraph XXX {\n");
185 fprintf(stdout, " rankdir=LR\n");
187 fprintf(stdout, "//===== Packages:\n");
189 while ((p = rpmtsiNext(pi, oType)) != NULL) {
192 fprintf(stdout, " \"%s\" -> \"%s\"\n", rpmteN(p), rpmteN(q));
194 fprintf(stdout, " \"%s\"\n", rpmteN(p));
195 fprintf(stdout, " { rank=max ; \"%s\" }\n", rpmteN(p));
200 fprintf(stdout, "}\n");
206 for (i = 0; i < numPkgs; i++)
207 pkgURL[i] = _free(pkgURL[i]);
208 pkgState = _free(pkgState);
209 pkgURL = _free(pkgURL);
215 static struct poptOption optionsTable[] = {
216 { "check", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &noDeps, 0,
217 N_("don't verify package dependencies"), NULL },
218 { "nolegacy", '\0', POPT_BIT_SET, &vsflags, RPMVSF_NEEDPAYLOAD,
219 N_("don't verify header+payload signature"), NULL },
220 { NULL, '\0', POPT_ARG_INCLUDE_TABLE, rpmcliAllPoptTable, 0,
221 N_("Common options for all rpm modes and executables:"),
230 main(int argc, char *argv[])
233 struct rpmInstallArguments_s * ia = &rpmIArgs;
237 xsetprogname(argv[0]); /* Portability call -- see system.h */
239 optCon = rpmcliInit(argc, argv, optionsTable);
244 if (rpmcliQueryFlags & VERIFY_DIGEST)
245 vsflags |= _RPMVSF_NODIGESTS;
246 if (rpmcliQueryFlags & VERIFY_SIGNATURE)
247 vsflags |= _RPMVSF_NOSIGNATURES;
248 if (rpmcliQueryFlags & VERIFY_HDRCHK)
249 vsflags |= RPMVSF_NOHDRCHK;
250 (void) rpmtsSetVSFlags(ts, vsflags);
252 ec = rpmGraph(ts, ia, poptGetArgs(optCon));