checks for upgrades to old versions of packages and gives an appropriate
authorewt <devnull@localhost>
Sun, 25 Feb 1996 22:11:00 +0000 (22:11 +0000)
committerewt <devnull@localhost>
Sun, 25 Feb 1996 22:11:00 +0000 (22:11 +0000)
error

CVS patchset: 421
CVS date: 1996/02/25 22:11:00

lib/install.c

index 18aaf2f..e251d9d 100644 (file)
@@ -52,6 +52,8 @@ static int instHandleSharedFiles(rpmdb db, int ignoreOffset, char ** fileList,
 static int fileCompare(const void * one, const void * two);
 static int installSources(char * prefix, int fd, char ** specFilePtr);
 static int markReplacedFiles(rpmdb db, struct replacedFile * replList);
+static int ensureOlder(rpmdb db, char * name, char * newVersion, 
+                      char * newRelease, int dbOffset);
 
 /* 0 success */
 /* 1 bad magic */
@@ -166,8 +168,13 @@ int rpmInstallPackage(char * prefix, rpmdb db, int fd, int flags,
        if (!rc) {
            intptr = oldVersions = alloca((matches.count + 1) * sizeof(int));
            for (i = 0; i < matches.count; i++) {
-               if (matches.recs[i].recOffset != otherOffset)
+               if (matches.recs[i].recOffset != otherOffset) {
+                   if (!(flags & INSTALL_UPGRADETOOLD)) 
+                       if (ensureOlder(db, name, version, release, 
+                                       matches.recs[i].recOffset)) 
+                           return 1;
                    *intptr++ = matches.recs[i].recOffset;
+               }
            }
            *intptr++ = 0;
        }
@@ -1080,3 +1087,38 @@ static int markReplacedFiles(rpmdb db, struct replacedFile * replList) {
 
     return 0;
 }
+
+static int ensureOlder(rpmdb db, char * name, char * newVersion, 
+                      char * newRelease, int dbOffset) {
+    Header h;
+    char * oldVersion, * oldRelease;
+    int rc, result;
+    int type, count;
+
+    h = rpmdbGetRecord(db, dbOffset);
+    if (!h) return 1;
+
+    getEntry(h, RPMTAG_VERSION, &type, (void **) &oldVersion, &count);
+    getEntry(h, RPMTAG_RELEASE, &type, (void **) &oldRelease, &count);
+
+    result = vercmp(oldVersion, newVersion);
+    if (result < 0)
+       rc = 0;
+    else if (result > 0) 
+       rc = 1;
+    else {
+       result = vercmp(oldRelease, newRelease);
+       if (result < 0)
+           rc = 0;
+       else
+           rc = 1;
+    }
+
+    if (rc) 
+       error(RPMERR_OLDPACKAGE, "package %s-%s-%s (which is newer) is already"
+               " installed", name, oldVersion, oldRelease);
+
+    freeHeader(h);
+
+    return rc;
+}