From dff80a94cc80be4aa9e6a71ca271c8640fcea323 Mon Sep 17 00:00:00 2001 From: jbj Date: Sun, 28 Mar 2004 14:57:53 +0000 Subject: [PATCH] - use package build time as EVR comparison tie breaker. CVS patchset: 7201 CVS date: 2004/03/28 14:57:53 --- CHANGES | 5 +++++ lib/psm.c | 30 ++++++++++++++++++++++++------ lib/rpmds.c | 27 +++++++++++++++++++++++++++ lib/rpmds.h | 17 +++++++++++++++++ python/rpmds-py.c | 11 +++++++++++ 5 files changed, 84 insertions(+), 6 deletions(-) diff --git a/CHANGES b/CHANGES index 41b3dc3..053a7b3 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,8 @@ +4.3.1 -> 4.4: + - use package build time as EVR comparison tie breaker. + +4.3 -> 4.3.1: + 4.2.2 -> 4.3: - upgrade to zlib-1.2.beta7. - fix: short option help missing string terminator. diff --git a/lib/psm.c b/lib/psm.c index c521d11..7e6ef2d 100644 --- a/lib/psm.c +++ b/lib/psm.c @@ -62,7 +62,8 @@ int rpmVersionCompare(Header first, Header second) { const char * one, * two; int_32 * epochOne, * epochTwo; - int rc; + int_32 * btOne, * btTwo; + int rc = 0; if (!headerGetEntry(first, RPMTAG_EPOCH, NULL, (void **) &epochOne, NULL)) epochOne = NULL; @@ -70,17 +71,19 @@ int rpmVersionCompare(Header first, Header second) epochTwo = NULL; if (epochOne != NULL && epochTwo == NULL) - return 1; + rc = 1; else if (epochOne == NULL && epochTwo != NULL) - return -1; + rc = -1; else if (epochOne != NULL && epochTwo != NULL) { /*@-boundsread@*/ if (*epochOne < *epochTwo) - return -1; + rc = -1; else if (*epochOne > *epochTwo) - return 1; + rc = 1; /*@=boundsread@*/ } + if (rc) + return rc; rc = headerGetEntry(first, RPMTAG_VERSION, NULL, (void **) &one, NULL); rc = headerGetEntry(second, RPMTAG_VERSION, NULL, (void **) &two, NULL); @@ -92,7 +95,22 @@ int rpmVersionCompare(Header first, Header second) rc = headerGetEntry(first, RPMTAG_RELEASE, NULL, (void **) &one, NULL); rc = headerGetEntry(second, RPMTAG_RELEASE, NULL, (void **) &two, NULL); - return rpmvercmp(one, two); + rc = rpmvercmp(one, two); + if (rc) + return rc; + + if (!headerGetEntry(first, RPMTAG_BUILDTIME, NULL, (void **) &btOne, NULL)) + btOne = NULL; + if (!headerGetEntry(second, RPMTAG_BUILDTIME, NULL, (void **) &btTwo, NULL)) + btTwo = NULL; + + if (btOne != NULL && btTwo != NULL && *btOne > 0 && *btTwo > 0) { +/*@-boundsread@*/ + rc = (*btOne < *btTwo ? -1 : (*btOne == *btTwo ? 0 : -1)); +/*@=boundsread@*/ + } + + return rc; } /** diff --git a/lib/rpmds.c b/lib/rpmds.c index 2677e20..1c8dc44 100644 --- a/lib/rpmds.c +++ b/lib/rpmds.c @@ -118,6 +118,8 @@ rpmds rpmdsNew(Header h, rpmTag tagN, int scareMem) { HGE_t hge = (scareMem ? (HGE_t) headerGetEntryMinMemory : (HGE_t) headerGetEntry); + rpmTag tagBT = RPMTAG_BUILDTIME; + int_32 BTt, * BTp; rpmTag tagEVR, tagF; rpmds ds = NULL; const char * Type; @@ -175,6 +177,8 @@ rpmds rpmdsNew(Header h, rpmTag tagN, int scareMem) if (!scareMem && ds->Flags != NULL) ds->Flags = memcpy(xmalloc(ds->Count * sizeof(*ds->Flags)), ds->Flags, ds->Count * sizeof(*ds->Flags)); + xx = hge(h, tagBT, &BTt, (void **) &BTp, NULL); + ds->BT = (xx && BTp != NULL && BTt == RPM_INT32_TYPE ? *BTp : 0); /*@=boundsread@*/ ds->Color = xcalloc(Count, sizeof(*ds->Color)); ds->Refs = xcalloc(Count, sizeof(*ds->Refs)); @@ -347,6 +351,9 @@ rpmds rpmdsSingle(rpmTag tagN, const char * N, const char * EVR, int_32 Flags) ds->h = NULL; ds->Type = Type; ds->tagN = tagN; + { time_t now = time(NULL); + ds->BT = now; + } ds->Count = 1; /*@-assignexpose@*/ /*@-boundswrite@*/ @@ -452,6 +459,24 @@ rpmTag rpmdsTagN(const rpmds ds) return tagN; } +time_t rpmdsBT(const rpmds ds) +{ + time_t BT = 0; + if (ds != NULL && ds->BT > 0) + BT = ds->BT; + return BT; +} + +time_t rpmdsSetBT(const rpmds ds, time_t BT) +{ + time_t oBT = 0; + if (ds != NULL) { + oBT = ds->BT; + ds->BT = BT; + } + return oBT; +} + int rpmdsNoPromote(const rpmds ds) { int nopromote = 0; @@ -879,6 +904,8 @@ int rpmdsCompare(const rpmds A, const rpmds B) sense = rpmvercmp(aV, bV); if (sense == 0 && aR && *aR && bR && *bR) { sense = rpmvercmp(aR, bR); + if (sense == 0 && A->BT > 0 && B->BT > 0) + sense = (A->BT < B->BT ? -1 : (A->BT == B->BT ? 0 : -1)); } } /*@=boundsread@*/ diff --git a/lib/rpmds.h b/lib/rpmds.h index 9a027f0..eddcd32 100644 --- a/lib/rpmds.h +++ b/lib/rpmds.h @@ -43,6 +43,7 @@ struct rpmds_s { uint_32 * Color; /*!< Bit(s) calculated from file color(s). */ /*@only@*/ /*@null@*/ int_32 * Refs; /*!< No. of file refs. */ + int_32 BT; /*!< Package build time tie breaker. */ rpmTag tagN; /*!< Header tag. */ rpmTagType Nt, EVRt, Ft; /*!< Tag data types. */ int_32 Count; /*!< No. of elements */ @@ -217,6 +218,22 @@ rpmTag rpmdsTagN(/*@null@*/ const rpmds ds) /*@*/; /** + * Return dependency build time. + * @param ds dependency set + * @return dependency build time, 0 on invalid + */ +time_t rpmdsBT(/*@null@*/ const rpmds ds) + /*@*/; + +/** + * Set dependency build time. + * @param ds dependency set + * @return dependency build time, 0 on invalid + */ +time_t rpmdsSetBuildtime(/*@null@*/ const rpmds ds, time_t BT) + /*@modifies ds @*/; + +/** * Return current "Don't promote Epoch:" flag. * * This flag controls for Epoch: promotion when a dependency set is diff --git a/python/rpmds-py.c b/python/rpmds-py.c index 46bd8d7..f4ac5f0 100644 --- a/python/rpmds-py.c +++ b/python/rpmds-py.c @@ -129,6 +129,15 @@ rpmds_Flags(rpmdsObject * s, PyObject * args) /*@null@*/ static PyObject * +rpmds_BT(rpmdsObject * s, PyObject * args) + /*@*/ +{ + if (!PyArg_ParseTuple(args, ":BT")) return NULL; + return Py_BuildValue("i", (int) rpmdsBT(s->ds)); +} + +/*@null@*/ +static PyObject * rpmds_TagN(rpmdsObject * s, PyObject * args) /*@*/ { @@ -338,6 +347,8 @@ static struct PyMethodDef rpmds_methods[] = { "ds.EVR -> EVR - Return current EVR.\n" }, {"Flags", (PyCFunction)rpmds_Flags, METH_VARARGS, "ds.Flags -> Flags - Return current Flags.\n" }, + {"BT", (PyCFunction)rpmds_BT, METH_VARARGS, + "ds.BT -> BT - Return build time.\n" }, {"TagN", (PyCFunction)rpmds_TagN, METH_VARARGS, "ds.TagN -> TagN - Return current TagN.\n" }, {"Color", (PyCFunction)rpmds_Color, METH_VARARGS, -- 2.7.4