From: ewt Date: Tue, 16 Sep 1997 23:16:21 +0000 (+0000) Subject: added install/dep time support for obsoletes tag X-Git-Tag: tznext/4.11.0.1.tizen20130304~10131 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=d4803c088c1e115dfbb21e9d2c312bef8af2decb;p=tools%2Flibrpm-tizen.git added install/dep time support for obsoletes tag CVS patchset: 1829 CVS date: 1997/09/16 23:16:21 --- diff --git a/CHANGES b/CHANGES index c61f813..ef2f47f 100644 --- a/CHANGES +++ b/CHANGES @@ -1,7 +1,9 @@ 2.4.7 -> 2.4.8: - added noarch build compatibilities for ppc, m68k - fixed some minor typos (Florian La Roche) - - added Obsoletes: tag + - added Obsoletes: tag, an upgrade removes packages which + have been obsoleted + - updated rpmdepUpgradePackage() to deal with obsoletes tag 2.4.6 -> 2.4.7: - had some wrong month lengths in changelog date parsing diff --git a/Makefile.inc.in b/Makefile.inc.in index 2829483..d211cfb 100644 --- a/Makefile.inc.in +++ b/Makefile.inc.in @@ -18,6 +18,6 @@ CFLAGS = @CFLAGS@ @INCPATH@ $(WARNINGS) $(OPTS) -I$(topdir) \ -DVERSION=\"$(VERSION)\" LDFLAGS = @LDFLAGS@ -Llib -Lbuild -Lmisc -L$(topdir)/lib \ -L$(topdir)/build -L$(topdir)/misc -VERSION = 2.4.7 +VERSION = 2.4.8 CC = @CC@ diff --git a/lib/depends.c b/lib/depends.c index 19587bb..453659c 100644 --- a/lib/depends.c +++ b/lib/depends.c @@ -253,13 +253,14 @@ void rpmdepUpgradePackage(rpmDependencies rpmdep, Header h, void * key) { /* this is an install followed by uninstalls */ dbiIndexSet matches; char * name; - int count, type, i; + int count, i, j; + char ** obsoletes; alAddPackage(&rpmdep->addedPackages, h, key); if (!rpmdep->db) return; - headerGetEntry(h, RPMTAG_NAME, &type, (void *) &name, &count); + headerGetEntry(h, RPMTAG_NAME, NULL, (void *) &name, &count); if (!rpmdbFindPackage(rpmdep->db, name, &matches)) { for (i = 0; i < matches.count; i++) { @@ -268,6 +269,21 @@ void rpmdepUpgradePackage(rpmDependencies rpmdep, Header h, void * key) { dbiFreeIndexRecord(matches); } + + if (headerGetEntry(h, RPMTAG_OBSOLETES, NULL, (void *) &obsoletes, + &count)) { + for (j = 0; j < count; j++) { + if (!rpmdbFindPackage(rpmdep->db, obsoletes[j], &matches)) { + for (i = 0; i < matches.count; i++) { + rpmdepRemovePackage(rpmdep, matches.recs[i].recOffset); + } + + dbiFreeIndexRecord(matches); + } + } + + free(obsoletes); + } } void rpmdepAddPackage(rpmDependencies rpmdep, Header h, void * key) { diff --git a/lib/install.c b/lib/install.c index e49c74f..7635e00 100644 --- a/lib/install.c +++ b/lib/install.c @@ -213,8 +213,9 @@ int rpmInstallPackage(char * rootdir, rpmdb db, int fd, char * location, struct replacedFile * replacedList = NULL; char * defaultPrefix; dbiIndexSet matches; - int * oldVersions; - int * intptr; + int * toRemove = NULL; + int toRemoveAlloced = 1; + int * intptr = NULL; char * archivePrefix, * tmpPath; int scriptArg; int hasOthers = 0; @@ -224,13 +225,11 @@ int rpmInstallPackage(char * rootdir, rpmdb db, int fd, char * location, int freeFileMem = 0; char * currDir = NULL, * tmpptr; int currDirLen; + char ** obsoletes; if (flags & RPMINSTALL_JUSTDB) flags |= RPMINSTALL_NOSCRIPTS; - oldVersions = alloca(sizeof(int)); - *oldVersions = 0; - rc = rpmReadPackageHeader(fd, &h, &isSource, &major, &minor); if (rc) return rc; @@ -314,15 +313,6 @@ int rpmInstallPackage(char * rootdir, rpmdb db, int fd, char * location, rpmMessage(RPMMESS_DEBUG, "package: %s-%s-%s files test = %d\n", name, version, release, flags & RPMINSTALL_TEST); - rc = rpmdbFindPackage(db, name, &matches); - if (rc == -1) return 2; - if (rc) { - scriptArg = 1; - } else { - hasOthers = 1; - scriptArg = matches.count + 1; - } - /* This canonicalizes the root */ if (rootdir && rootdir[rootLength] == '/') { char * newRootdir; @@ -334,7 +324,16 @@ int rpmInstallPackage(char * rootdir, rpmdb db, int fd, char * location, rootdir = newRootdir; } - if (flags & RPMINSTALL_UPGRADE && hasOthers) { + rc = rpmdbFindPackage(db, name, &matches); + if (rc == -1) return 2; + if (rc) { + scriptArg = 1; + } else { + hasOthers = 1; + scriptArg = matches.count + 1; + } + + if (flags & RPMINSTALL_UPGRADE) { /* We need to get a list of all old version of this package. We let this install procede normally then, but: @@ -345,10 +344,13 @@ int rpmInstallPackage(char * rootdir, rpmdb db, int fd, char * location, Note if the version being installed is already installed, we don't put that in the list -- that situation is handled normally. + + We also need to handle packages which were made oboslete. */ - if (!rc) { - intptr = oldVersions = alloca((matches.count + 1) * sizeof(int)); + if (hasOthers) { + toRemoveAlloced = matches.count + 1; + intptr = toRemove = malloc(toRemoveAlloced * sizeof(int)); for (i = 0; i < matches.count; i++) { if (matches.recs[i].recOffset != otherOffset) { if (!(flags & RPMINSTALL_UPGRADETOOLD)) @@ -360,12 +362,45 @@ int rpmInstallPackage(char * rootdir, rpmdb db, int fd, char * location, *intptr++ = matches.recs[i].recOffset; } } - *intptr++ = 0; + + dbiFreeIndexRecord(matches); } - } - if (hasOthers) + if (!(flags & RPMINSTALL_KEEPOBSOLETE) && + headerGetEntry(h, RPMTAG_OBSOLETES, NULL, (void **) &obsoletes, + &count)) { + for (i = 0; i < count; i++) { + rc = rpmdbFindPackage(db, obsoletes[i], &matches); + if (rc == -1) return 2; + if (rc == 1) continue; /* no matches */ + + rpmMessage(RPMMESS_DEBUG, "package %s is now obsolete and will" + "be removed\n", obsoletes[i]); + + toRemoveAlloced += matches.count; + j = toRemove ? intptr - toRemove : 0; + toRemove = realloc(toRemove, toRemoveAlloced * sizeof(int)); + intptr = toRemove + j; + + for (j = 0; j < count; j++) + *intptr++ = matches.recs[j].recOffset; + + dbiFreeIndexRecord(matches); + } + + free(obsoletes); + } + + *intptr++ = 0; + + /* this means we don't have to free the list */ + intptr = alloca(toRemoveAlloced * sizeof(int)); + memcpy(intptr, toRemove, toRemoveAlloced * sizeof(int)); + free(toRemove); + toRemove = intptr; + } else if (hasOthers) { dbiFreeIndexRecord(matches); + } if (rootdir) { currDirLen = 50; @@ -449,7 +484,7 @@ int rpmInstallPackage(char * rootdir, rpmdb db, int fd, char * location, } rc = instHandleSharedFiles(db, otherOffset, files, fileCount, - oldVersions, &replacedList, flags); + toRemove, &replacedList, flags); if (rc) { if (rootdir) { @@ -642,7 +677,7 @@ int rpmInstallPackage(char * rootdir, rpmdb db, int fd, char * location, if (flags & RPMINSTALL_UPGRADE) { rpmMessage(RPMMESS_DEBUG, "removing old versions of package\n"); - intptr = oldVersions; + intptr = toRemove; while (*intptr) { rpmRemovePackage(rootdir, db, *intptr, 0); intptr++; diff --git a/lib/rpmlib.h b/lib/rpmlib.h index 41bd361..af46da5 100644 --- a/lib/rpmlib.h +++ b/lib/rpmlib.h @@ -134,6 +134,7 @@ extern const struct headerSprintfExtension rpmHeaderFormats[]; #define RPMINSTALL_NOOS (1 << 8) #define RPMINSTALL_ALLFILES (1 << 9) #define RPMINSTALL_JUSTDB (1 << 10) +#define RPMINSTALL_KEEPOBSOLETE (1 << 11) #define RPMUNINSTALL_TEST (1 << 0) #define RPMUNINSTALL_NOSCRIPTS (1 << 1) diff --git a/rpm.spec b/rpm.spec index 1d55ea5..6691e03 100644 --- a/rpm.spec +++ b/rpm.spec @@ -1,6 +1,6 @@ Summary: Red Hat Package Manager Name: rpm -%define version 2.4.7 +%define version 2.4.8 Version: %{version} Release: 1 Group: Utilities/System