15 /*@access rpmProblem @*/
19 static int _ps_debug = 0;
21 rpmps XrpmpsUnlink(rpmps ps, const char * msg,
22 const char * fn, unsigned ln)
25 if (_ps_debug > 0 && msg != NULL)
26 fprintf(stderr, "--> ps %p -- %d %s at %s:%u\n", ps, ps->nrefs, msg, fn, ln);
34 rpmps XrpmpsLink(rpmps ps, const char * msg,
35 const char * fn, unsigned ln)
39 if (_ps_debug > 0 && msg != NULL)
40 fprintf(stderr, "--> ps %p ++ %d %s at %s:%u\n", ps, ps->nrefs, msg, fn, ln);
47 rpmps rpmpsCreate(void)
49 rpmps ps = xcalloc(1, sizeof(*ps));
50 return rpmpsLink(ps, "create");
53 rpmps rpmpsFree(rpmps ps)
55 if (ps == NULL) return NULL;
56 ps = rpmpsUnlink(ps, "dereference");
62 for (i = 0; i < ps->numProblems; i++) {
63 rpmProblem p = ps->probs + i;
64 p->pkgNEVR = _free(p->pkgNEVR);
65 p->altNEVR = _free(p->altNEVR);
66 p->str1 = _free(p->str1);
68 ps->probs = _free(ps->probs);
74 void rpmpsAppend(rpmps ps, rpmProblemType type,
75 const char * pkgNEVR, fnpyKey key,
76 const char * dn, const char * bn,
77 const char * altNEVR, unsigned long ulong1)
82 if (ps == NULL) return;
84 if (ps->numProblems == ps->numProblemsAlloced) {
85 if (ps->numProblemsAlloced)
86 ps->numProblemsAlloced *= 2;
88 ps->numProblemsAlloced = 2;
89 ps->probs = xrealloc(ps->probs,
90 ps->numProblemsAlloced * sizeof(*ps->probs));
93 p = ps->probs + ps->numProblems;
95 memset(p, 0, sizeof(*p));
100 p->ignoreProblem = 0;
102 p->pkgNEVR = (pkgNEVR ? xstrdup(pkgNEVR) : NULL);
103 p->altNEVR = (altNEVR ? xstrdup(altNEVR) : NULL);
106 if (dn != NULL || bn != NULL) {
107 t = xcalloc(1, (dn != NULL ? strlen(dn) : 0) +
108 (bn != NULL ? strlen(bn) : 0) + 1);
110 if (dn != NULL) t = stpcpy(t, dn);
111 if (bn != NULL) t = stpcpy(t, bn);
115 #define XSTRCMP(a, b) ((!(a) && !(b)) || ((a) && (b) && !strcmp((a), (b))))
117 int rpmpsTrim(rpmps ps, rpmps filter)
123 if (ps == NULL || ps->numProblems == 0)
127 return (ps->numProblems == 0 ? 0 : 1);
132 while ((f - filter->probs) < filter->numProblems) {
133 if (!f->ignoreProblem) {
137 while ((t - ps->probs) < ps->numProblems) {
138 /*@-nullpass@*/ /* LCL: looks good to me <shrug> */
139 if (f->type == t->type && t->key == f->key &&
140 XSTRCMP(f->str1, t->str1))
141 /*@innerbreak@*/ break;
147 /* XXX This can't happen, but let's be sane in case it does. */
148 if ((t - ps->probs) == ps->numProblems)
151 t->ignoreProblem = f->ignoreProblem;
155 if ((t - ps->probs) < ps->numProblems)
161 /* XXX FIXME: merge into problems */
162 /* XXX used in verify.c rpmlibprov.c */
163 void printDepFlags(FILE * fp, const char * version, int flags)
168 if (flags & RPMSENSE_LESS)
170 if (flags & RPMSENSE_GREATER)
172 if (flags & RPMSENSE_EQUAL)
176 fprintf(fp, " %s", version);
179 #if !defined(HAVE_VSNPRINTF)
180 /*@-shadow -bufferoverflowhigh @*/
181 static inline int vsnprintf(/*@out@*/ char * buf, /*@unused@*/ int nb,
182 const char * fmt, va_list ap)
184 return vsprintf(buf, fmt, ap);
186 /*@=shadow =bufferoverflowhigh @*/
188 #if !defined(HAVE_SNPRINTF)
189 static inline int snprintf(/*@out@*/ char * buf, int nb, const char * fmt, ...)
194 rc = vsnprintf(buf, nb, fmt, ap);
200 const char * rpmProblemString(const rpmProblem prob)
203 const char * pkgNEVR = (prob->pkgNEVR ? prob->pkgNEVR : "?pkgNEVR?");
205 const char * altNEVR = (prob->altNEVR ? prob->altNEVR : "?altNEVR?");
207 const char * str1 = (prob->str1 ? prob->str1 : N_("different"));
208 int nb = strlen(pkgNEVR) + strlen(str1) + strlen(altNEVR) + 100;
209 char * buf = xmalloc(nb+1);
212 switch (prob->type) {
213 case RPMPROB_BADARCH:
214 rc = snprintf(buf, nb,
215 _("package %s is intended for a %s architecture"),
219 rc = snprintf(buf, nb,
220 _("package %s is intended for a %s operating system"),
223 case RPMPROB_PKG_INSTALLED:
224 rc = snprintf(buf, nb,
225 _("package %s is already installed"),
228 case RPMPROB_BADRELOCATE:
229 rc = snprintf(buf, nb,
230 _("path %s in package %s is not relocateable"),
233 case RPMPROB_NEW_FILE_CONFLICT:
234 rc = snprintf(buf, nb,
235 _("file %s conflicts between attempted installs of %s and %s"),
236 str1, pkgNEVR, altNEVR);
238 case RPMPROB_FILE_CONFLICT:
239 rc = snprintf(buf, nb,
240 _("file %s from install of %s conflicts with file from package %s"),
241 str1, pkgNEVR, altNEVR);
243 case RPMPROB_OLDPACKAGE:
244 rc = snprintf(buf, nb,
245 _("package %s (which is newer than %s) is already installed"),
248 case RPMPROB_DISKSPACE:
249 rc = snprintf(buf, nb,
250 _("installing package %s needs %ld%cB on the %s filesystem"),
252 prob->ulong1 > (1024*1024)
253 ? (prob->ulong1 + 1024 * 1024 - 1) / (1024 * 1024)
254 : (prob->ulong1 + 1023) / 1024,
255 prob->ulong1 > (1024*1024) ? 'M' : 'K',
258 case RPMPROB_DISKNODES:
259 rc = snprintf(buf, nb,
260 _("installing package %s needs %ld inodes on the %s filesystem"),
261 pkgNEVR, (long)prob->ulong1, str1);
263 case RPMPROB_BADPRETRANS:
264 rc = snprintf(buf, nb,
265 _("package %s pre-transaction syscall(s): %s failed: %s"),
266 pkgNEVR, str1, strerror(prob->ulong1));
268 case RPMPROB_REQUIRES:
269 rc = snprintf(buf, nb, _("package %s has unsatisfied Requires: %s\n"),
272 case RPMPROB_CONFLICT:
273 rc = snprintf(buf, nb, _("package %s has unsatisfied Conflicts: %s\n"),
277 rc = snprintf(buf, nb,
278 _("unknown error %d encountered while manipulating package %s"),
279 prob->type, pkgNEVR);
287 void rpmProblemPrint(FILE *fp, rpmProblem prob)
289 const char * msg = rpmProblemString(prob);
290 fprintf(fp, "%s\n", msg);
294 void rpmpsPrint(FILE *fp, rpmps ps)
304 for (i = 0; i < ps->numProblems; i++) {
305 rpmProblem myprob = ps->probs + i;
306 if (!myprob->ignoreProblem)
307 rpmProblemPrint(fp, myprob);
311 static int sameProblem(const rpmProblem ap, const rpmProblem bp)
314 if (ap->type != bp->type)
317 if (bp->pkgNEVR && strcmp(ap->pkgNEVR, bp->pkgNEVR))
320 if (bp->altNEVR && strcmp(ap->altNEVR, bp->altNEVR))
323 if (bp->str1 && strcmp(ap->str1, bp->str1))
326 if (ap->ulong1 != bp->ulong1)
332 /* XXX FIXME: merge into rpmpsPrint */
333 void printDepProblems(FILE * fp, rpmps ps)
337 if (ps && ps->probs != NULL)
338 for (i = 0; i < ps->numProblems; i++) {
339 const char * pkgNEVR;
340 const char * altNEVR;
346 /* Filter already displayed problems. */
347 for (j = 0; j < i; j++) {
348 if (!sameProblem(p, ps->probs + j))
349 /*@innerbreak@*/ break;
354 pkgNEVR = (p->pkgNEVR ? p->pkgNEVR : "?pkgNEVR?");
355 altNEVR = (p->altNEVR ? p->altNEVR : "? ?altNEVR?");
357 fprintf(fp, "\t%s %s %s\n", altNEVR+2,
358 ((altNEVR[0] == 'C' && altNEVR[1] == ' ')
359 ? _("conflicts with") : _("is needed by")),