2010-03-25 22:46:39 +08:00
|
|
|
/**
|
|
|
|
* \file lib/rpmps.c
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "system.h"
|
|
|
|
|
|
|
|
#include <inttypes.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
#include <rpm/rpmstring.h>
|
|
|
|
#include <rpm/rpmprob.h>
|
|
|
|
|
|
|
|
#include "debug.h"
|
|
|
|
|
|
|
|
struct rpmProblem_s {
|
|
|
|
char * pkgNEVR;
|
|
|
|
char * altNEVR;
|
|
|
|
fnpyKey key;
|
|
|
|
rpmProblemType type;
|
|
|
|
char * str1;
|
|
|
|
uint64_t num1;
|
|
|
|
int nrefs;
|
|
|
|
};
|
|
|
|
|
2010-09-13 18:08:33 +08:00
|
|
|
static rpmProblem rpmProblemUnlink(rpmProblem prob);
|
|
|
|
|
2010-03-25 22:46:39 +08:00
|
|
|
rpmProblem rpmProblemCreate(rpmProblemType type,
|
2010-03-26 16:41:10 +08:00
|
|
|
const char * pkgNEVR, fnpyKey key,
|
2010-03-25 22:46:39 +08:00
|
|
|
const char * altNEVR,
|
2010-03-26 16:41:10 +08:00
|
|
|
const char * str, uint64_t number)
|
2010-03-25 22:46:39 +08:00
|
|
|
{
|
|
|
|
rpmProblem p = xcalloc(1, sizeof(*p));
|
|
|
|
|
|
|
|
p->type = type;
|
|
|
|
p->key = key;
|
|
|
|
p->num1 = number;
|
|
|
|
|
|
|
|
p->pkgNEVR = (pkgNEVR ? xstrdup(pkgNEVR) : NULL);
|
|
|
|
p->altNEVR = (altNEVR ? xstrdup(altNEVR) : NULL);
|
2010-03-26 16:41:10 +08:00
|
|
|
p->str1 = (str ? xstrdup(str) : NULL);
|
2010-03-25 22:46:39 +08:00
|
|
|
|
|
|
|
return rpmProblemLink(p);
|
|
|
|
}
|
|
|
|
|
|
|
|
rpmProblem rpmProblemFree(rpmProblem prob)
|
|
|
|
{
|
|
|
|
if (prob == NULL) return NULL;
|
|
|
|
|
|
|
|
if (prob->nrefs > 1) {
|
|
|
|
return rpmProblemUnlink(prob);
|
|
|
|
}
|
|
|
|
prob->pkgNEVR = _free(prob->pkgNEVR);
|
|
|
|
prob->altNEVR = _free(prob->altNEVR);
|
|
|
|
prob->str1 = _free(prob->str1);
|
|
|
|
free(prob);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
rpmProblem rpmProblemLink(rpmProblem prob)
|
|
|
|
{
|
|
|
|
if (prob) {
|
|
|
|
prob->nrefs++;
|
|
|
|
}
|
|
|
|
return prob;
|
|
|
|
}
|
|
|
|
|
2010-09-13 18:08:33 +08:00
|
|
|
static rpmProblem rpmProblemUnlink(rpmProblem prob)
|
2010-03-25 22:46:39 +08:00
|
|
|
{
|
|
|
|
if (prob) {
|
|
|
|
prob->nrefs--;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char * rpmProblemGetPkgNEVR(rpmProblem p)
|
|
|
|
{
|
|
|
|
return (p->pkgNEVR);
|
|
|
|
}
|
|
|
|
|
|
|
|
const char * rpmProblemGetAltNEVR(rpmProblem p)
|
|
|
|
{
|
|
|
|
return (p->altNEVR);
|
|
|
|
}
|
|
|
|
|
|
|
|
fnpyKey rpmProblemGetKey(rpmProblem p)
|
|
|
|
{
|
|
|
|
return (p->key);
|
|
|
|
}
|
|
|
|
|
|
|
|
rpmProblemType rpmProblemGetType(rpmProblem p)
|
|
|
|
{
|
|
|
|
return (p->type);
|
|
|
|
}
|
|
|
|
|
|
|
|
const char * rpmProblemGetStr(rpmProblem p)
|
|
|
|
{
|
|
|
|
return (p->str1);
|
|
|
|
}
|
|
|
|
|
|
|
|
rpm_loff_t rpmProblemGetDiskNeed(rpmProblem p)
|
|
|
|
{
|
|
|
|
return (p->num1);
|
|
|
|
}
|
|
|
|
|
|
|
|
char * rpmProblemString(rpmProblem prob)
|
|
|
|
{
|
|
|
|
const char * pkgNEVR = (prob->pkgNEVR ? prob->pkgNEVR : "?pkgNEVR?");
|
|
|
|
const char * altNEVR = (prob->altNEVR ? prob->altNEVR : "? ?altNEVR?");
|
|
|
|
const char * str1 = (prob->str1 ? prob->str1 : N_("different"));
|
|
|
|
char * buf = NULL;
|
|
|
|
|
|
|
|
switch (prob->type) {
|
|
|
|
case RPMPROB_BADARCH:
|
2011-03-04 20:42:38 +08:00
|
|
|
rasprintf(&buf, _("package %s is intended for a %s architecture"),
|
2010-03-25 22:46:39 +08:00
|
|
|
pkgNEVR, str1);
|
|
|
|
break;
|
|
|
|
case RPMPROB_BADOS:
|
2011-03-04 20:42:38 +08:00
|
|
|
rasprintf(&buf, _("package %s is intended for a %s operating system"),
|
2010-03-25 22:46:39 +08:00
|
|
|
pkgNEVR, str1);
|
|
|
|
break;
|
|
|
|
case RPMPROB_PKG_INSTALLED:
|
2020-06-02 20:53:47 +08:00
|
|
|
if (prob->num1)
|
|
|
|
rasprintf(&buf, _("package %s is already installed"), pkgNEVR);
|
|
|
|
else
|
|
|
|
rasprintf(&buf, _("package %s is not installed"), pkgNEVR);
|
2010-03-25 22:46:39 +08:00
|
|
|
break;
|
|
|
|
case RPMPROB_BADRELOCATE:
|
2011-03-04 20:42:38 +08:00
|
|
|
rasprintf(&buf, _("path %s in package %s is not relocatable"),
|
2010-03-25 22:46:39 +08:00
|
|
|
str1, pkgNEVR);
|
|
|
|
break;
|
|
|
|
case RPMPROB_NEW_FILE_CONFLICT:
|
2011-03-04 20:42:38 +08:00
|
|
|
rasprintf(&buf,
|
2010-03-25 22:46:39 +08:00
|
|
|
_("file %s conflicts between attempted installs of %s and %s"),
|
|
|
|
str1, pkgNEVR, altNEVR);
|
|
|
|
break;
|
|
|
|
case RPMPROB_FILE_CONFLICT:
|
2011-03-04 20:42:38 +08:00
|
|
|
rasprintf(&buf,
|
2010-03-25 22:46:39 +08:00
|
|
|
_("file %s from install of %s conflicts with file from package %s"),
|
|
|
|
str1, pkgNEVR, altNEVR);
|
|
|
|
break;
|
|
|
|
case RPMPROB_OLDPACKAGE:
|
2011-03-04 20:42:38 +08:00
|
|
|
rasprintf(&buf,
|
2010-03-25 22:46:39 +08:00
|
|
|
_("package %s (which is newer than %s) is already installed"),
|
|
|
|
altNEVR, pkgNEVR);
|
|
|
|
break;
|
|
|
|
case RPMPROB_DISKSPACE:
|
2011-03-04 20:42:38 +08:00
|
|
|
rasprintf(&buf,
|
2019-10-04 15:55:00 +08:00
|
|
|
_("installing package %s needs %" PRIu64 "%cB more space on the %s filesystem"),
|
2010-03-25 22:46:39 +08:00
|
|
|
pkgNEVR,
|
|
|
|
prob->num1 > (1024*1024)
|
|
|
|
? (prob->num1 + 1024 * 1024 - 1) / (1024 * 1024)
|
|
|
|
: (prob->num1 + 1023) / 1024,
|
|
|
|
prob->num1 > (1024*1024) ? 'M' : 'K',
|
|
|
|
str1);
|
|
|
|
break;
|
|
|
|
case RPMPROB_DISKNODES:
|
2011-03-04 20:42:38 +08:00
|
|
|
rasprintf(&buf,
|
2019-10-04 15:55:00 +08:00
|
|
|
_("installing package %s needs %" PRIu64 " more inodes on the %s filesystem"),
|
2010-03-25 22:46:39 +08:00
|
|
|
pkgNEVR, prob->num1, str1);
|
|
|
|
break;
|
|
|
|
case RPMPROB_REQUIRES:
|
2011-03-04 20:42:38 +08:00
|
|
|
rasprintf(&buf, _("%s is needed by %s%s"),
|
|
|
|
prob->str1, (prob->num1 ? _("(installed) ") : ""), altNEVR);
|
2010-03-25 22:46:39 +08:00
|
|
|
break;
|
|
|
|
case RPMPROB_CONFLICT:
|
2011-03-04 20:42:38 +08:00
|
|
|
rasprintf(&buf, _("%s conflicts with %s%s"),
|
|
|
|
prob->str1, (prob->num1 ? _("(installed) ") : ""), altNEVR);
|
2010-03-25 22:46:39 +08:00
|
|
|
break;
|
|
|
|
case RPMPROB_OBSOLETES:
|
2011-03-04 20:42:38 +08:00
|
|
|
rasprintf(&buf, _("%s is obsoleted by %s%s"),
|
|
|
|
prob->str1, (prob->num1 ? _("(installed) ") : ""), altNEVR);
|
2010-03-25 22:46:39 +08:00
|
|
|
break;
|
2018-05-09 18:49:41 +08:00
|
|
|
case RPMPROB_VERIFY:
|
|
|
|
rasprintf(&buf, _("package %s does not verify: %s"),
|
|
|
|
pkgNEVR, prob->str1);
|
|
|
|
break;
|
2010-03-25 22:46:39 +08:00
|
|
|
default:
|
2011-03-04 20:42:38 +08:00
|
|
|
rasprintf(&buf,
|
2010-03-25 22:46:39 +08:00
|
|
|
_("unknown error %d encountered while manipulating package %s"),
|
|
|
|
prob->type, pkgNEVR);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return buf;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int cmpStr(const char *s1, const char *s2)
|
|
|
|
{
|
|
|
|
if (s1 == s2) return 0;
|
|
|
|
if (s1 && s2) return strcmp(s1, s2);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int rpmProblemCompare(rpmProblem ap, rpmProblem bp)
|
|
|
|
{
|
2010-03-26 13:09:47 +08:00
|
|
|
if (ap == bp)
|
|
|
|
return 0;
|
|
|
|
if (ap == NULL || bp == NULL)
|
|
|
|
return 1;
|
2010-03-25 22:46:39 +08:00
|
|
|
if (ap->type != bp->type)
|
|
|
|
return 1;
|
|
|
|
if (ap->key != bp->key)
|
|
|
|
return 1;
|
|
|
|
if (ap->num1 != bp->num1)
|
|
|
|
return 1;
|
|
|
|
if (cmpStr(ap->pkgNEVR, bp->pkgNEVR))
|
|
|
|
return 1;
|
|
|
|
if (cmpStr(ap->altNEVR, bp->altNEVR))
|
|
|
|
return 1;
|
|
|
|
if (cmpStr(ap->str1, bp->str1))
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|