Main Page   Modules   Compound List   File List   Compound Members   File Members   Related Pages  

lib/problems.c

Go to the documentation of this file.
00001 
00005 #include "system.h"
00006 
00007 #include <rpmlib.h>
00008 
00009 #include "depends.h"
00010 #include "misc.h"
00011 #include "debug.h"
00012 
00013 /*@access rpmProblemSet@*/
00014 /*@access rpmProblem@*/
00015 
00016 /* XXX FIXME: merge into problems */
00017 /* XXX used in verify.c rpmlibprov.c */
00018 void printDepFlags(FILE * fp, const char * version, int flags)
00019 {
00020     if (flags)
00021         fprintf(fp, " ");
00022 
00023     if (flags & RPMSENSE_LESS) 
00024         fprintf(fp, "<");
00025     if (flags & RPMSENSE_GREATER)
00026         fprintf(fp, ">");
00027     if (flags & RPMSENSE_EQUAL)
00028         fprintf(fp, "=");
00029 
00030     if (flags)
00031         fprintf(fp, " %s", version);
00032 }
00033 
00034 static int sameProblem(struct rpmDependencyConflict * ap,
00035                        struct rpmDependencyConflict * bp)
00036 {
00037 
00038     if (ap->sense != bp->sense)
00039         return 1;
00040 
00041     if (ap->byName && bp->byName && strcmp(ap->byName, bp->byName))
00042         return 1;
00043     if (ap->byVersion && bp->byVersion && strcmp(ap->byVersion, bp->byVersion))
00044         return 1;
00045     if (ap->byRelease && bp->byRelease && strcmp(ap->byRelease, bp->byRelease))
00046         return 1;
00047 
00048     if (ap->needsName && bp->needsName && strcmp(ap->needsName, bp->needsName))
00049         return 1;
00050     if (ap->needsVersion && bp->needsVersion && strcmp(ap->needsVersion, bp->needsVersion))
00051         return 1;
00052     if (ap->needsFlags && bp->needsFlags && ap->needsFlags != bp->needsFlags)
00053         return 1;
00054 
00055     return 0;
00056 }
00057 
00058 /* XXX FIXME: merge into problems */
00059 void printDepProblems(FILE * fp, struct rpmDependencyConflict * conflicts,
00060                              int numConflicts)
00061 {
00062     int i;
00063 
00064     for (i = 0; i < numConflicts; i++) {
00065         int j;
00066 
00067         /* Filter already displayed problems. */
00068         for (j = 0; j < i; j++) {
00069             if (!sameProblem(conflicts + i, conflicts + j))
00070                 break;
00071         }
00072         if (j < i)
00073             continue;
00074 
00075         fprintf(fp, "\t%s", conflicts[i].needsName);
00076         if (conflicts[i].needsFlags)
00077             printDepFlags(fp, conflicts[i].needsVersion, 
00078                           conflicts[i].needsFlags);
00079 
00080         if (conflicts[i].sense == RPMDEP_SENSE_REQUIRES) 
00081             fprintf(fp, _(" is needed by %s-%s-%s\n"), conflicts[i].byName, 
00082                     conflicts[i].byVersion, conflicts[i].byRelease);
00083         else
00084             fprintf(fp, _(" conflicts with %s-%s-%s\n"), conflicts[i].byName, 
00085                     conflicts[i].byVersion, conflicts[i].byRelease);
00086     }
00087 }
00088 
00089 const char * rpmProblemString(rpmProblem prob) /*@*/
00090 {
00091     int nb =    (prob->pkgNEVR ? strlen(prob->pkgNEVR) : 0) +
00092                 (prob->str1 ? strlen(prob->str1) : 0) +
00093                 (prob->altNEVR ? strlen(prob->altNEVR) : 0) +
00094                 100;
00095     char * buf = xmalloc(nb+1);
00096 
00097     switch (prob->type) {
00098     case RPMPROB_BADARCH:
00099         snprintf(buf, nb, _("package %s is for a different architecture"),
00100                 prob->pkgNEVR);
00101         break;
00102     case RPMPROB_BADOS:
00103         snprintf(buf, nb, _("package %s is for a different operating system"),
00104                 prob->pkgNEVR);
00105         break;
00106     case RPMPROB_PKG_INSTALLED:
00107         snprintf(buf, nb, _("package %s is already installed"),
00108                 prob->pkgNEVR);
00109         break;
00110     case RPMPROB_BADRELOCATE:
00111         snprintf(buf, nb, _("path %s in package %s is not relocateable"),
00112                 prob->str1, prob->pkgNEVR);
00113         break;
00114     case RPMPROB_NEW_FILE_CONFLICT:
00115         snprintf(buf, nb,
00116                 _("file %s conflicts between attempted installs of %s and %s"),
00117                 prob->str1, prob->pkgNEVR, prob->altNEVR);
00118         break;
00119     case RPMPROB_FILE_CONFLICT:
00120         snprintf(buf, nb,
00121             _("file %s from install of %s conflicts with file from package %s"),
00122                 prob->str1, prob->pkgNEVR, prob->altNEVR);
00123         break;
00124     case RPMPROB_OLDPACKAGE:
00125         snprintf(buf, nb,
00126                 _("package %s (which is newer than %s) is already installed"),
00127                 prob->altNEVR, prob->pkgNEVR);
00128         break;
00129     case RPMPROB_DISKSPACE:
00130         snprintf(buf, nb,
00131             _("installing package %s needs %ld%cb on the %s filesystem"),
00132                 prob->pkgNEVR,
00133                 prob->ulong1 > (1024*1024)
00134                     ? (prob->ulong1 + 1024 * 1024 - 1) / (1024 * 1024)
00135                     : (prob->ulong1 + 1023) / 1024,
00136                 prob->ulong1 > (1024*1024) ? 'M' : 'K',
00137                 prob->str1);
00138         break;
00139     case RPMPROB_DISKNODES:
00140         snprintf(buf, nb,
00141             _("installing package %s needs %ld inodes on the %s filesystem"),
00142                 prob->pkgNEVR, (long)prob->ulong1, prob->str1);
00143         break;
00144     case RPMPROB_BADPRETRANS:
00145         snprintf(buf, nb,
00146                 _("package %s pre-transaction syscall(s): %s failed: %s"),
00147                 prob->pkgNEVR, prob->str1, strerror(prob->ulong1));
00148         break;
00149     case RPMPROB_REQUIRES:
00150     case RPMPROB_CONFLICT:
00151     default:
00152         snprintf(buf, nb,
00153                 _("unknown error %d encountered while manipulating package %s"),
00154                 prob->type, prob->pkgNEVR);
00155         break;
00156     }
00157 
00158     buf[nb] = '\0';
00159     return buf;
00160 }
00161 
00162 void rpmProblemPrint(FILE *fp, rpmProblem prob)
00163 {
00164     const char *msg = rpmProblemString(prob);
00165     fprintf(fp, "%s\n", msg);
00166     free((void *)msg);
00167 }
00168 
00169 void rpmProblemSetPrint(FILE *fp, rpmProblemSet probs)
00170 {
00171     int i;
00172 
00173     if (probs == NULL)
00174         return;
00175 
00176     if (fp == NULL)
00177         fp = stderr;
00178 
00179     for (i = 0; i < probs->numProblems; i++) {
00180         rpmProblem myprob = probs->probs + i;
00181         if (!myprob->ignoreProblem)
00182             rpmProblemPrint(fp, myprob);
00183     }
00184 }

Generated at Mon May 21 08:53:39 2001 for rpm by doxygen1.2.6 written by Dimitri van Heesch, © 1997-2001