add versions to prereq.
authorjbj <devnull@localhost>
Tue, 24 Aug 1999 22:26:55 +0000 (22:26 +0000)
committerjbj <devnull@localhost>
Tue, 24 Aug 1999 22:26:55 +0000 (22:26 +0000)
add syntax sensitive implict prereq on rpm-3.0.3.

CVS patchset: 3253
CVS date: 1999/08/24 22:26:55

CHANGES
build/parseReqs.c
build/reqprov.c
lib/depends.c
lib/rpmchecksig.c
po/rpm.pot
rpm.spec

diff --git a/CHANGES b/CHANGES
index 0b60236..4637a28 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -36,6 +36,8 @@
        - fix: segfault with "--sign" w/o supplying files (#4651).
        - add headerWrite return code and check for errors.
        - update python bindings from anaconda.
+       - add versions to prereq.
+       - add syntax sensitive implict prereq on rpm-3.0.3.
 
 3.0.1 -> 3.0.2
        - eliminate armv4 entries from rpmrc (Andrew E. Mileski).
index 0fc7022..8f63b78 100644 (file)
@@ -139,10 +139,19 @@ int parseRCPOT(Spec spec, Package pkg, const char *field, int tag, int index)
            switch(tag) {
            case RPMTAG_BUILDPREREQ:
            case RPMTAG_PREREQ:
+           case RPMTAG_PROVIDES:
+           case RPMTAG_OBSOLETES:
+#if 0
                rpmError(RPMERR_BADSPEC,
                         _("line %d: Version not permitted: %s"),
                         spec->lineNum, spec->line);
                return RPMERR_BADSPEC;
+#else
+               /* Add prereq on rpm version that implements versioning */
+               addReqProv(spec, h,
+                       RPMSENSE_PREREQ|(RPMSENSE_GREATER|RPMSENSE_EQUAL),
+                       "rpm", "3.0.3", index);
+#endif
                break;
            default:
                break;
index 00ce825..846c8f3 100644 (file)
@@ -8,9 +8,6 @@ int addReqProv(Spec spec, Header h,
               int flag, const char *name, const char *version, int index)
 {
     const char **names;
-    const char **versions = NULL;
-    int *flags = NULL;
-    int *indexes = NULL;
     int nametag = 0;
     int versiontag = 0;
     int flagtag = 0;
@@ -52,34 +49,39 @@ int addReqProv(Spec spec, Header h,
        version = "";
     }
     
+    /* Check for duplicate dependencies. */
     if (headerGetEntry(h, nametag, NULL, (void **) &names, &len)) {
+       const char **versions = NULL;
+       int *flags = NULL;
+       int *indexes = NULL;
+
        if (flagtag) {
-           headerGetEntry(h, versiontag, NULL,
-                          (void **) &versions, NULL);
+           headerGetEntry(h, versiontag, NULL, (void **) &versions, NULL);
            headerGetEntry(h, flagtag, NULL, (void **) &flags, NULL);
        }
        if (indextag) {
-           headerGetEntry(h, indextag, NULL,
-                          (void **) &indexes, NULL);
+           headerGetEntry(h, indextag, NULL, (void **) &indexes, NULL);
        }
-       while (len) {
+       while (len > 0) {
            len--;
-           if (!strcmp(names[len], name)) {
-               if (!flagtag ||
-                   (!strcmp(versions[len], version) && flags[len] == flag)) {
-                   if (!indextag || (index == indexes[len])) {
-                       /* The same */
-                       FREE(names);
-                       FREE(versions);
-                       return 0;
-                   }
-               }
-           }
+           if (strcmp(names[len], name))
+               continue;
+           if (flagtag && versions != NULL &&
+                       (strcmp(versions[len], version) || flags[len] != flag))
+               continue;
+           if (indextag && indexes != NULL && indexes[len] != index)
+               continue;
+
+           /* This is a duplicate dependency. */
+           break;
        }
        FREE(names);
        FREE(versions);
+       if (len >= 0)
+           return 0;
     }
 
+    /* Add this dependency. */
     headerAddOrAppendEntry(h, nametag, RPM_STRING_ARRAY_TYPE, &name, 1);
     if (flagtag) {
        headerAddOrAppendEntry(h, versiontag,
index 7047c09..35668a4 100644 (file)
@@ -227,6 +227,48 @@ static void parseEVR(char *evr, const char **ep, const char **vp, const char **r
 
 typedef int (*dbrecMatch_t) (Header h, const char *reqName, const char * reqInfo, int reqFlags);
 
+/* Provide the rpm version in case nothing else does. */
+static int rpmMatchesDepFlags(const char *reqName, const char * reqInfo, int reqFlags)
+{
+    static const char *name = PACKAGE;
+    static const char *epoch = "0";
+    static const char *version = VERSION;
+    static const char *release = NULL;
+    const char * reqEpoch = NULL;
+    const char * reqVersion = NULL;
+    const char * reqRelease = NULL;
+    char *Revr;
+    int result;
+    int sense;
+
+    if (strcmp(name, reqName)) return 0;
+
+    /* Parse requires version into components */
+    Revr = strdup(reqInfo);
+    parseEVR(Revr, &reqEpoch, &reqVersion, &reqRelease);
+
+    /* Compare {package,requires} [epoch:]version[-release] */
+    sense = ((reqEpoch != NULL) ? rpmvercmp(epoch, reqEpoch) : 0);
+    if (sense == 0) {
+       sense = rpmvercmp(version, reqVersion);
+       if (sense == 0 && reqRelease && *reqRelease) {
+           sense = rpmvercmp(release, reqRelease);
+       }
+    }
+    if (Revr) free(Revr);
+
+    result = 0;
+    if ((reqFlags & RPMSENSE_LESS) && sense < 0) {
+       result = 1;
+    } else if ((reqFlags & RPMSENSE_EQUAL) && sense == 0) {
+       result = 1;
+    } else if ((reqFlags & RPMSENSE_GREATER) && sense > 0) {
+       result = 1;
+    }
+
+    return result;
+}
+
 static int rangeMatchesDepFlags (Header h, const char *reqName, const char * reqInfo, int reqFlags)
 {
     char ** provides;
@@ -502,11 +544,11 @@ int rpmtransAddPackage(rpmTransactionSet rpmdep, Header h, FD_t fd,
     }
 
     if (headerGetEntry(h, RPMTAG_OBSOLETENAME, NULL, (void **) &obsoletes, &count)) {
-       const char **obsoletesVersion, *obsV;
-       int *obsoletesFlags, obsF;
+       const char **obsoletesVersion;
+       int *obsoletesFlags;
 
-       headerGetEntry(h, RPMTAG_OBSOLETEFLAGS, NULL, (void **) &obsoletesFlags, NULL);
        headerGetEntry(h, RPMTAG_OBSOLETEVERSION, NULL, (void **) &obsoletesVersion, NULL);
+       headerGetEntry(h, RPMTAG_OBSOLETEFLAGS, NULL, (void **) &obsoletesFlags, NULL);
 
        for (j = 0; j < count; j++) {
            if (rpmdbFindPackage(rpmdep->db, obsoletes[j], &matches))
@@ -518,10 +560,14 @@ int rpmtransAddPackage(rpmTransactionSet rpmdep, Header h, FD_t fd,
                        sizeof(int), intcmp))
                    continue;
                        
-               obsV = obsoletesVersion ? obsoletesVersion[j] : "";
-               obsF = obsoletesFlags ? obsoletesFlags[j] : 0;
-               if (dbrecMatchesDepFlags(rpmdep, recOffset,
-                     obsoletes[j], obsV, obsF, headerMatchesDepFlags)) {
+               /*
+                * Rpm prior to 3.0.3 does not have versioned obsoletes.
+                * If no obsoletes version info is available, match all names.
+                */
+               if (obsoletesVersion == NULL ||
+                   dbrecMatchesDepFlags(rpmdep, recOffset,
+                     obsoletes[j], obsoletesVersion[j], obsoletesFlags[j],
+                     headerMatchesDepFlags)) {
                        removePackage(rpmdep, recOffset, alNum);
                }
            }
@@ -677,6 +723,13 @@ static int unsatisfiedDepend(rpmTransactionSet rpmdep, const char * reqName,
            dbiFreeIndexRecord(matches);
            if (i < dbiIndexSetCount(matches)) return 0;
        }
+
+       /*
+        * New features in rpm spec files add implicit dependencies.
+        * Provide implicit rpm version in last ditch effort to satisfy.
+        */
+       if (rpmMatchesDepFlags(reqName, reqVersion, reqFlags))
+           return 0;
     }
 
     if (suggestion) 
@@ -706,8 +759,7 @@ static int checkPackageDeps(rpmTransactionSet rpmdep, struct problemsSet * psp,
        headerGetEntry(h, RPMTAG_REQUIREFLAGS, &type, (void **) &requireFlags, 
                 &requiresCount);
        headerGetEntry(h, RPMTAG_REQUIREVERSION, &type, 
-                       (void **) &requiresVersion, 
-                &requiresCount);
+               (void **) &requiresVersion, &requiresCount);
     }
 
     if (!headerGetEntry(h, RPMTAG_CONFLICTNAME, &type, (void **) &conflicts,
@@ -715,10 +767,9 @@ static int checkPackageDeps(rpmTransactionSet rpmdep, struct problemsSet * psp,
        conflictsCount = 0;
     } else {
        headerGetEntry(h, RPMTAG_CONFLICTFLAGS, &type, 
-                       (void **) &conflictsFlags, &conflictsCount);
+               (void **) &conflictsFlags, &conflictsCount);
        headerGetEntry(h, RPMTAG_CONFLICTVERSION, &type,
-                       (void **) &conflictsVersion, 
-                &conflictsCount);
+               (void **) &conflictsVersion, &conflictsCount);
     }
 
     for (i = 0; i < requiresCount && !ourrc; i++) {
@@ -886,15 +937,17 @@ static int addOrderedPack(rpmTransactionSet rpmdep,
                        int * selected, int selectionClass,
                        int satisfyDepends, const char ** errorStack)
 {
-    const char ** requires, ** requiresVersion;
+    const char ** requires;
+    const char ** requiresVersion;
     int_32 * requireFlags;
     int requiresCount;
     int matchNum;
     int packageNum = package - rpmdep->addedPackages.list;
-    int i, rc;
+    int i;
     struct availablePackage * match;
     char * errorString;
     const char ** stack;
+    int rc = 0;
 
     *errorStack++ = package->name;
 
@@ -928,35 +981,28 @@ static int addOrderedPack(rpmTransactionSet rpmdep,
        headerGetEntry(package->h, RPMTAG_REQUIREVERSION, NULL, 
                        (void **) &requiresVersion, NULL);
 
-       for (i = 0; i < requiresCount; i++) {
-           if (satisfyDepends || (requireFlags[i] & RPMSENSE_PREREQ)) {
-               match = alSatisfiesDepend(&rpmdep->addedPackages,
-                                         requires[i], requiresVersion[i],
-                                         requireFlags[i]);
-               /* broken dependencies don't concern us */
-               if (!match) continue;
+       for (i = 0; rc == 0 && i < requiresCount; i++) {
+           if (!(satisfyDepends || (requireFlags[i] & RPMSENSE_PREREQ)))
+               continue;
+           match = alSatisfiesDepend(&rpmdep->addedPackages,
+                         requires[i], requiresVersion[i], requireFlags[i]);
+           /* broken dependencies don't concern us */
+           if (!match) continue;
                
-               /* let this package satisfy its own predependencies */
-               if (match == package) continue;
+           /* let this package satisfy its own predependencies */
+           if (match == package) continue;
 
-               /* the package has already been selected */
-               matchNum = match - rpmdep->addedPackages.list;
-               if (selected[matchNum] == -1 ||
-                   selected[matchNum] == selectionClass)
-                   continue;
+           /* the package has already been selected */
+           matchNum = match - rpmdep->addedPackages.list;
+           if(selected[matchNum] == -1 || selected[matchNum] == selectionClass)
+               continue;
                
-               if (requireFlags[i] & RPMSENSE_PREREQ)
-                   rc = addOrderedPack(rpmdep, match, ordering, orderNumPtr,
-                                       selected, selectionClass + 1, 1,
-                                       errorStack);
-               else
-                   rc = addOrderedPack(rpmdep, match, ordering, orderNumPtr,
-                                       selected, selectionClass, 1,
-                                       errorStack);
-
-               /* FIXME: I suspect we should free things here */
-               if (rc) return 1;
-           }
+           if (requireFlags[i] & RPMSENSE_PREREQ)
+               rc = addOrderedPack(rpmdep, match, ordering, orderNumPtr,
+                               selected, selectionClass + 1, 1, errorStack);
+           else
+               rc = addOrderedPack(rpmdep, match, ordering, orderNumPtr,
+                               selected, selectionClass, 1, errorStack);
        }
 
        free(requires);
@@ -964,10 +1010,12 @@ static int addOrderedPack(rpmTransactionSet rpmdep,
     }
 
     /* whew -- add this package */
-    ordering[(*orderNumPtr)++] = packageNum;
-    selected[packageNum] = -1;
+    if (rc == 0) {
+       ordering[(*orderNumPtr)++] = packageNum;
+       selected[packageNum] = -1;
+    }
 
-    return 0;
+    return rc;
 }
 
 static int orderListIndexCmp(const void * one, const void * two)
index dd11243..ce1d890 100644 (file)
@@ -9,7 +9,7 @@
 
 #include "rpmlead.h"
 #include "signature.h"
-#include "misc.h"      /* XXX fpor makeTempFile() */
+#include "misc.h"      /* XXX for makeTempFile() */
 
 int rpmReSign(int add, char *passPhrase, const char **argv)
 {
index 5542586..ce15f70 100644 (file)
@@ -6,7 +6,7 @@
 msgid ""
 msgstr ""
 "Project-Id-Version: PACKAGE VERSION\n"
-"POT-Creation-Date: 1999-08-24 11:10-0400\n"
+"POT-Creation-Date: 1999-08-24 16:47-0400\n"
 "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
 "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
 "Language-Team: LANGUAGE <LL@li.org>\n"
@@ -1816,12 +1816,12 @@ msgstr ""
 msgid "line %d: Versioned file name not permitted: %s"
 msgstr ""
 
-#: ../build/parseReqs.c:143
+#: ../build/parseReqs.c:146
 #, c-format
 msgid "line %d: Version not permitted: %s"
 msgstr ""
 
-#: ../build/parseReqs.c:163
+#: ../build/parseReqs.c:172
 #, c-format
 msgid "line %d: Version required: %s"
 msgstr ""
@@ -1980,31 +1980,31 @@ msgstr ""
 msgid "error removing record %s into %s"
 msgstr ""
 
-#: ../lib/depends.c:377
+#: ../lib/depends.c:419
 msgid "dbrecMatchesDepFlags() failed to read header"
 msgstr ""
 
-#: ../lib/depends.c:607
+#: ../lib/depends.c:653
 #, c-format
 msgid "dependencies: looking for %s\n"
 msgstr ""
 
-#: ../lib/depends.c:732
+#: ../lib/depends.c:783
 #, c-format
 msgid "package %s require not satisfied: %s\n"
 msgstr ""
 
-#: ../lib/depends.c:771
+#: ../lib/depends.c:822
 #, c-format
 msgid "package %s conflicts: %s\n"
 msgstr ""
 
-#: ../lib/depends.c:824 ../lib/depends.c:1127
+#: ../lib/depends.c:875 ../lib/depends.c:1175
 #, c-format
 msgid "cannot read header at %d for dependency check"
 msgstr ""
 
-#: ../lib/depends.c:916
+#: ../lib/depends.c:969
 #, c-format
 msgid "loop in prerequisite chain: %s"
 msgstr ""
index 41d5ea8..93cddf0 100644 (file)
--- a/rpm.spec
+++ b/rpm.spec
@@ -2,7 +2,7 @@ Summary: The Red Hat package management system.
 Name: rpm
 %define version 3.0.3
 Version: %{version}
-Release: 0.18
+Release: 0.19
 Group: System Environment/Base
 Source: ftp://ftp.rpm.org/pub/rpm/dist/rpm-3.0.x/rpm-%{version}.tar.gz
 Copyright: GPL