10 #include <rpm/rpmstring.h>
11 #include <rpm/rpmprob.h>
25 static rpmProblem rpmProblemUnlink(rpmProblem prob);
27 rpmProblem rpmProblemCreate(rpmProblemType type,
28 const char * pkgNEVR, fnpyKey key,
30 const char * str, uint64_t number)
32 rpmProblem p = xcalloc(1, sizeof(*p));
38 p->pkgNEVR = (pkgNEVR ? xstrdup(pkgNEVR) : NULL);
39 p->altNEVR = (altNEVR ? xstrdup(altNEVR) : NULL);
40 p->str1 = (str ? xstrdup(str) : NULL);
42 return rpmProblemLink(p);
45 rpmProblem rpmProblemFree(rpmProblem prob)
47 if (prob == NULL) return NULL;
49 if (prob->nrefs > 1) {
50 return rpmProblemUnlink(prob);
52 prob->pkgNEVR = _free(prob->pkgNEVR);
53 prob->altNEVR = _free(prob->altNEVR);
54 prob->str1 = _free(prob->str1);
59 rpmProblem rpmProblemLink(rpmProblem prob)
67 static rpmProblem rpmProblemUnlink(rpmProblem prob)
75 const char * rpmProblemGetPkgNEVR(rpmProblem p)
80 const char * rpmProblemGetAltNEVR(rpmProblem p)
85 fnpyKey rpmProblemGetKey(rpmProblem p)
90 rpmProblemType rpmProblemGetType(rpmProblem p)
95 const char * rpmProblemGetStr(rpmProblem p)
100 rpm_loff_t rpmProblemGetDiskNeed(rpmProblem p)
105 char * rpmProblemString(rpmProblem prob)
107 const char * pkgNEVR = (prob->pkgNEVR ? prob->pkgNEVR : "?pkgNEVR?");
108 const char * altNEVR = (prob->altNEVR ? prob->altNEVR : "? ?altNEVR?");
109 const char * str1 = (prob->str1 ? prob->str1 : N_("different"));
112 switch (prob->type) {
113 case RPMPROB_BADARCH:
114 rasprintf(&buf, _("package %s is intended for a %s architecture"),
118 rasprintf(&buf, _("package %s is intended for a %s operating system"),
121 case RPMPROB_PKG_INSTALLED:
122 rasprintf(&buf, _("package %s is already installed"), pkgNEVR);
124 case RPMPROB_BADRELOCATE:
125 rasprintf(&buf, _("path %s in package %s is not relocatable"),
128 case RPMPROB_NEW_FILE_CONFLICT:
130 _("file %s conflicts between attempted installs of %s and %s"),
131 str1, pkgNEVR, altNEVR);
133 case RPMPROB_FILE_CONFLICT:
135 _("file %s from install of %s conflicts with file from package %s"),
136 str1, pkgNEVR, altNEVR);
138 case RPMPROB_OLDPACKAGE:
140 _("package %s (which is newer than %s) is already installed"),
143 case RPMPROB_DISKSPACE:
145 _("installing package %s needs %" PRIu64 "%cB on the %s filesystem"),
147 prob->num1 > (1024*1024)
148 ? (prob->num1 + 1024 * 1024 - 1) / (1024 * 1024)
149 : (prob->num1 + 1023) / 1024,
150 prob->num1 > (1024*1024) ? 'M' : 'K',
153 case RPMPROB_DISKNODES:
155 _("installing package %s needs %" PRIu64 " inodes on the %s filesystem"),
156 pkgNEVR, prob->num1, str1);
158 case RPMPROB_REQUIRES:
159 rasprintf(&buf, _("%s is needed by %s%s"),
160 prob->str1, (prob->num1 ? _("(installed) ") : ""), altNEVR);
162 case RPMPROB_CONFLICT:
163 rasprintf(&buf, _("%s conflicts with %s%s"),
164 prob->str1, (prob->num1 ? _("(installed) ") : ""), altNEVR);
166 case RPMPROB_OBSOLETES:
167 rasprintf(&buf, _("%s is obsoleted by %s%s"),
168 prob->str1, (prob->num1 ? _("(installed) ") : ""), altNEVR);
172 _("unknown error %d encountered while manipulating package %s"),
173 prob->type, pkgNEVR);
180 static int cmpStr(const char *s1, const char *s2)
182 if (s1 == s2) return 0;
183 if (s1 && s2) return strcmp(s1, s2);
187 int rpmProblemCompare(rpmProblem ap, rpmProblem bp)
191 if (ap == NULL || bp == NULL)
193 if (ap->type != bp->type)
195 if (ap->key != bp->key)
197 if (ap->num1 != bp->num1)
199 if (cmpStr(ap->pkgNEVR, bp->pkgNEVR))
201 if (cmpStr(ap->altNEVR, bp->altNEVR))
203 if (cmpStr(ap->str1, bp->str1))