1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
|
#include "system.h"
#include <rpmcli.h>
#include "rpmdb.h"
#include "rpmps.h"
#include "rpmte.h"
#define _RPMTS_INTERNAL /* ts->goal, ts->dbmode, ts->suggests */
#include "rpmts.h"
#include "manifest.h"
#include "misc.h" /* rpmGlob */
#include "debug.h"
static int noDeps = 1;
static rpmVSFlags vsflags = 0;
static inline /*@observer@*/ const char * const identifyDepend(int_32 f)
/*@*/
{
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)
/*@*/
{
rpmps ps;
const char ** pkgURL = NULL;
char * pkgState = NULL;
const char ** fnp;
const char * fileURL = NULL;
int numPkgs = 0;
int numFailed = 0;
int prevx = 0;
int pkgx = 0;
const char ** argv = NULL;
int argc = 0;
const char ** av = NULL;
int ac = 0;
Header h;
rpmRC rpmrc;
int rc = 0;
rpmVSFlags ovsflags;
int i;
if (fileArgv == NULL)
return 0;
if (ia->qva_flags & VERIFY_DIGEST)
vsflags |= _RPMVSF_NODIGESTS;
if (ia->qva_flags & VERIFY_SIGNATURE)
vsflags |= _RPMVSF_NOSIGNATURES;
ovsflags = rpmtsSetVSFlags(ts, vsflags);
/* 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. */
for (fnp = pkgURL+prevx; *fnp != NULL; fnp++, prevx++) {
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)) {
rpmError(RPMERR_OPEN, _("open of %s failed: %s\n"), *fnp,
Fstrerror(fd));
if (fd) {
Fclose(fd);
fd = NULL;
}
numFailed++; *fnp = NULL;
continue;
}
/* Read the header, verifying signatures (if present). */
ovsflags = rpmtsSetVSFlags(ts, vsflags);
rpmrc = rpmReadPackageFile(ts, fd, *fnp, &h);
ovsflags = rpmtsSetVSFlags(ts, ovsflags);
Fclose(fd);
fd = NULL;
switch (rpmrc) {
case RPMRC_FAIL:
default:
rpmMessage(RPMMESS_ERROR, _("%s cannot be installed\n"), *fnp);
numFailed++; *fnp = NULL;
/*@switchbreak@*/ break;
case RPMRC_OK:
rc = rpmtsAddInstallElement(ts, h, (fnpyKey)fileName, 0, NULL);
/*@switchbreak@*/ break;
case RPMRC_NOTFOUND:
goto maybe_manifest;
/*@notreached@*/ /*@switchbreak@*/ break;
}
h = headerFree(h);
continue;
maybe_manifest:
/* 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));
if (fd) {
Fclose(fd);
fd = NULL;
}
numFailed++; *fnp = NULL;
break;
}
/* Read list of packages from manifest. */
rc = rpmReadPackageManifest(fd, &argc, &argv);
if (rc)
rpmError(RPMERR_MANIFEST, _("%s: read manifest failed: %s\n"),
fileURL, Fstrerror(fd));
Fclose(fd);
fd = NULL;
/* If successful, restart the query loop. */
if (rc == 0) {
prevx++;
goto restart;
}
numFailed++; *fnp = NULL;
break;
}
if (numFailed > 0) goto exit;
if (!noDeps) {
rc = rpmtsCheck(ts);
if (rc) {
numFailed += numPkgs;
goto exit;
}
ps = rpmtsProblems(ts);
if (rpmpsNumProblems(ps) > 0) {
rpmMessage(RPMMESS_ERROR, _("Failed dependencies:\n"));
rpmpsPrint(NULL, ps);
numFailed += numPkgs;
/*@-branchstate@*/
if (ts->suggests != NULL && ts->nsuggests > 0) {
rpmMessage(RPMMESS_NORMAL, _(" Suggested resolutions:\n"));
for (i = 0; i < ts->nsuggests; i++) {
const char * str = ts->suggests[i];
if (str == NULL)
break;
rpmMessage(RPMMESS_NORMAL, "\t%s\n", str);
ts->suggests[i] = NULL;
str = _free(str);
}
ts->suggests = _free(ts->suggests);
}
/*@=branchstate@*/
}
ps = rpmpsFree(ps);
}
if (numFailed > 0) goto exit;
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[] = {
{ "check", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &noDeps, 0,
N_("don't verify package dependencies"), NULL },
{ "nolegacy", '\0', POPT_BIT_SET, &vsflags, RPMVSF_NEEDPAYLOAD,
N_("don't verify header+payload signature"), NULL },
{ "anaconda", '\0', POPT_BIT_SET|POPT_ARGFLAG_DOC_HIDDEN,
&rpmIArgs.transFlags, RPMTRANS_FLAG_ANACONDA,
N_("use anaconda \"presentation order\""), 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
main(int argc, char *const argv[])
{
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();
if (rpmcliQueryFlags & VERIFY_DIGEST)
vsflags |= _RPMVSF_NODIGESTS;
if (rpmcliQueryFlags & VERIFY_SIGNATURE)
vsflags |= _RPMVSF_NOSIGNATURES;
if (rpmcliQueryFlags & VERIFY_HDRCHK)
vsflags |= RPMVSF_NOHDRCHK;
(void) rpmtsSetVSFlags(ts, vsflags);
ec = rpmGraph(ts, ia, poptGetArgs(optCon));
ts = rpmtsFree(ts);
optCon = rpmcliFini(optCon);
return ec;
}
|