17 rpmps XrpmpsUnlink(rpmps ps, const char * msg,
18 const char * fn, unsigned ln)
20 if (_rpmps_debug > 0 && msg != NULL)
21 fprintf(stderr, "--> ps %p -- %d %s at %s:%u\n", ps, ps->nrefs, msg, fn, ln);
26 rpmps XrpmpsLink(rpmps ps, const char * msg,
27 const char * fn, unsigned ln)
30 if (_rpmps_debug > 0 && msg != NULL)
31 fprintf(stderr, "--> ps %p ++ %d %s at %s:%u\n", ps, ps->nrefs, msg, fn, ln);
35 int rpmpsNumProblems(rpmps ps)
39 numProblems = ps->numProblems;
43 rpmps rpmpsCreate(void)
45 rpmps ps = xcalloc(1, sizeof(*ps));
46 return rpmpsLink(ps, "create");
49 rpmps rpmpsFree(rpmps ps)
51 if (ps == NULL) return NULL;
52 ps = rpmpsUnlink(ps, "dereference");
58 for (i = 0; i < ps->numProblems; i++) {
59 rpmProblem p = ps->probs + i;
60 p->pkgNEVR = _free(p->pkgNEVR);
61 p->altNEVR = _free(p->altNEVR);
62 p->str1 = _free(p->str1);
64 ps->probs = _free(ps->probs);
70 void rpmpsAppend(rpmps ps, rpmProblemType type,
71 const char * pkgNEVR, fnpyKey key,
72 const char * dn, const char * bn,
73 const char * altNEVR, unsigned long ulong1)
78 if (ps == NULL) return;
80 if (ps->numProblems == ps->numProblemsAlloced) {
81 if (ps->numProblemsAlloced)
82 ps->numProblemsAlloced *= 2;
84 ps->numProblemsAlloced = 2;
85 ps->probs = xrealloc(ps->probs,
86 ps->numProblemsAlloced * sizeof(*ps->probs));
89 p = ps->probs + ps->numProblems;
91 memset(p, 0, sizeof(*p));
98 p->pkgNEVR = (pkgNEVR ? xstrdup(pkgNEVR) : NULL);
99 p->altNEVR = (altNEVR ? xstrdup(altNEVR) : NULL);
102 if (dn != NULL || bn != NULL) {
103 t = xcalloc(1, (dn != NULL ? strlen(dn) : 0) +
104 (bn != NULL ? strlen(bn) : 0) + 1);
106 if (dn != NULL) t = stpcpy(t, dn);
107 if (bn != NULL) t = stpcpy(t, bn);
111 #define XSTRCMP(a, b) ((!(a) && !(b)) || ((a) && (b) && !strcmp((a), (b))))
113 int rpmpsTrim(rpmps ps, rpmps filter)
119 if (ps == NULL || ps->numProblems == 0)
123 return (ps->numProblems == 0 ? 0 : 1);
128 while ((f - filter->probs) < filter->numProblems) {
129 if (!f->ignoreProblem) {
133 while ((t - ps->probs) < ps->numProblems) {
134 /* LCL: looks good to me <shrug> */
135 if (f->type == t->type && t->key == f->key &&
136 XSTRCMP(f->str1, t->str1))
142 /* XXX This can't happen, but let's be sane in case it does. */
143 if ((t - ps->probs) == ps->numProblems)
146 t->ignoreProblem = f->ignoreProblem;
150 if ((t - ps->probs) < ps->numProblems)
156 #if !defined(HAVE_VSNPRINTF)
157 static inline int vsnprintf(char * buf, int nb,
158 const char * fmt, va_list ap)
160 return vsprintf(buf, fmt, ap);
163 #if !defined(HAVE_SNPRINTF)
164 static inline int snprintf(char * buf, int nb, const char * fmt, ...)
169 rc = vsnprintf(buf, nb, fmt, ap);
175 const char * rpmProblemString(const rpmProblem prob)
177 const char * pkgNEVR = (prob->pkgNEVR ? prob->pkgNEVR : "?pkgNEVR?");
178 const char * altNEVR = (prob->altNEVR ? prob->altNEVR : "? ?altNEVR?");
179 const char * str1 = (prob->str1 ? prob->str1 : N_("different"));
180 int nb = strlen(pkgNEVR) + strlen(str1) + strlen(altNEVR) + 100;
181 char * buf = xmalloc(nb+1);
184 switch (prob->type) {
185 case RPMPROB_BADARCH:
186 rc = snprintf(buf, nb,
187 _("package %s is intended for a %s architecture"),
191 rc = snprintf(buf, nb,
192 _("package %s is intended for a %s operating system"),
195 case RPMPROB_PKG_INSTALLED:
196 rc = snprintf(buf, nb,
197 _("package %s is already installed"),
200 case RPMPROB_BADRELOCATE:
201 rc = snprintf(buf, nb,
202 _("path %s in package %s is not relocatable"),
205 case RPMPROB_NEW_FILE_CONFLICT:
206 rc = snprintf(buf, nb,
207 _("file %s conflicts between attempted installs of %s and %s"),
208 str1, pkgNEVR, altNEVR);
210 case RPMPROB_FILE_CONFLICT:
211 rc = snprintf(buf, nb,
212 _("file %s from install of %s conflicts with file from package %s"),
213 str1, pkgNEVR, altNEVR);
215 case RPMPROB_OLDPACKAGE:
216 rc = snprintf(buf, nb,
217 _("package %s (which is newer than %s) is already installed"),
220 case RPMPROB_DISKSPACE:
221 rc = snprintf(buf, nb,
222 _("installing package %s needs %ld%cB on the %s filesystem"),
224 prob->ulong1 > (1024*1024)
225 ? (prob->ulong1 + 1024 * 1024 - 1) / (1024 * 1024)
226 : (prob->ulong1 + 1023) / 1024,
227 prob->ulong1 > (1024*1024) ? 'M' : 'K',
230 case RPMPROB_DISKNODES:
231 rc = snprintf(buf, nb,
232 _("installing package %s needs %ld inodes on the %s filesystem"),
233 pkgNEVR, (long)prob->ulong1, str1);
235 case RPMPROB_REQUIRES:
236 rc = snprintf(buf, nb, _("%s is needed by %s%s"),
238 (prob->ulong1 ? "" : _("(installed) ")), pkgNEVR);
240 case RPMPROB_CONFLICT:
241 rc = snprintf(buf, nb, _("%s conflicts with %s%s"),
243 (prob->ulong1 ? "" : _("(installed) ")), pkgNEVR);
246 rc = snprintf(buf, nb,
247 _("unknown error %d encountered while manipulating package %s"),
248 prob->type, pkgNEVR);
256 static int sameProblem(const rpmProblem ap, const rpmProblem bp)
258 if (ap->type != bp->type)
261 if (bp->pkgNEVR && strcmp(ap->pkgNEVR, bp->pkgNEVR))
264 if (bp->altNEVR && strcmp(ap->altNEVR, bp->altNEVR))
267 if (bp->str1 && strcmp(ap->str1, bp->str1))
270 if (ap->ulong1 != bp->ulong1)
276 void rpmpsPrint(FILE *fp, rpmps ps)
281 if (ps == NULL || ps->probs == NULL || ps->numProblems <= 0)
287 for (i = 0; i < ps->numProblems; i++) {
293 if (p->ignoreProblem)
296 /* Filter already displayed problems. */
297 for (j = 0; j < i; j++) {
298 if (!sameProblem(p, ps->probs + j))
304 msg = rpmProblemString(p);
305 fprintf(fp, "\t%s\n", msg);