static int isNewDep(rpmds *dsp, rpmds bds, Header h, rpmTagVal indextag, uint32_t index) { int isnew = 1; if (!indextag) { /* With normal deps, we can just merge and see if anything got added */ isnew = (rpmdsMerge(dsp, bds) > 0); } else { struct rpmtd_s idx; rpmds ads = *dsp; headerGet(h, indextag, &idx, HEADERGET_MINMEM); /* rpmdsFind/Merge() probably isn't realiable with triggers... */ rpmdsInit(ads); while (isnew && rpmdsNext(ads) >= 0) { if (!rstreq(rpmdsN(ads), rpmdsN(bds))) continue; if (!rstreq(rpmdsEVR(ads), rpmdsEVR(bds))) continue; if (rpmdsFlags(ads) != rpmdsFlags(bds)) continue; if (indextag && rpmtdSetIndex(&idx, rpmdsIx(ads)) >= 0 && rpmtdGetNumber(&idx) != index) continue; isnew = 0; } rpmtdFreeData(&idx); rpmdsMerge(dsp, bds); } return isnew; }
static int rpmds_compare(rpmdsObject * a, rpmdsObject * b) { char *aEVR = strdup(rpmdsEVR(a->ds)); const char *aE, *aV, *aR; char *bEVR = strdup(rpmdsEVR(b->ds)); const char *bE, *bV, *bR; int rc; /* XXX W2DO? should N be compared? */ rpmds_ParseEVR(aEVR, &aE, &aV, &aR); rpmds_ParseEVR(bEVR, &bE, &bV, &bR); rc = compare_values(aE, bE); if (!rc) { rc = compare_values(aV, bV); if (!rc) rc = compare_values(aR, bR); } free(aEVR); free(bEVR); return rc; }
static int rpmts_SolveCallback(rpmts ts, rpmds ds, const void * data) { struct rpmtsCallbackType_s * cbInfo = (struct rpmtsCallbackType_s *) data; PyObject * args, * result; int res = 1; if (cbInfo->tso == NULL) return res; if (cbInfo->cb == Py_None) return res; PyEval_RestoreThread(cbInfo->_save); args = Py_BuildValue("(Oissi)", cbInfo->tso, rpmdsTagN(ds), rpmdsN(ds), rpmdsEVR(ds), rpmdsFlags(ds)); result = PyEval_CallObject(cbInfo->cb, args); Py_DECREF(args); if (!result) { die(cbInfo->cb); } else { if (PyInt_Check(result)) res = PyInt_AsLong(result); Py_DECREF(result); } cbInfo->_save = PyEval_SaveThread(); return res; }
static VALUE rpmds_EVR_get(VALUE s) { rpmds ds = rpmds_ptr(s); if (_debug) fprintf(stderr, "==> %s(0x%lx) ptr %p\n", __FUNCTION__, s, ds); return rb_str_new2(rpmdsEVR(ds)); }
static int doFind(rpmds ds, const rpmds ods, unsigned int *he) { int comparison; const char *N, *ON = rpmdsN(ods); const char *EVR, *OEVR = rpmdsEVR(ods); rpmsenseFlags Flags, OFlags = rpmdsFlags(ods); int index, Oindex = rpmdsTi(ods); int rc = -1; /* assume not found */ if (ds == NULL || ods == NULL) return -1; unsigned int l = 0; unsigned int u = ds->Count; while (l < u) { ds->i = (l + u) / 2; N = rpmdsN(ds); EVR = rpmdsEVR(ds); Flags = rpmdsFlags(ds); index = rpmdsTi(ds); comparison = strcmp(ON, N); /* XXX rpm prior to 3.0.2 did not always supply EVR and Flags. */ if (comparison == 0 && OEVR && EVR) comparison = strcmp(OEVR, EVR); if (comparison == 0) comparison = OFlags - Flags; if (comparison == 0) comparison = Oindex - index; if (comparison < 0) u = ds->i; else if (comparison > 0) l = ds->i + 1; else { rc = ds->i; break; } } if (he) *he = u; return rc; }
static int haveTildeDep(Package pkg) { for (int i = 0; i < PACKAGE_NUM_DEPS; i++) { rpmds ds = rpmdsInit(pkg->dependencies[i]); while (rpmdsNext(ds) >= 0) { if (strchr(rpmdsEVR(ds), '~')) return 1; } } return 0; }
/* Add erase elements for obsoleted packages of same color (if any). */ static int addObsoleteErasures(rpmts ts, rpm_color_t tscolor, rpmte p) { rpmstrPool tspool = rpmtsPool(ts); rpmds obsoletes = rpmdsInit(rpmteDS(p, RPMTAG_OBSOLETENAME)); Header oh; int rc = 0; while (rpmdsNext(obsoletes) >= 0 && rc == 0) { const char * Name; rpmdbMatchIterator mi = NULL; if ((Name = rpmdsN(obsoletes)) == NULL) continue; /* XXX can't happen */ mi = rpmtsPrunedIterator(ts, RPMDBI_NAME, Name, 1); while((oh = rpmdbNextIterator(mi)) != NULL) { const char *oarch = headerGetString(oh, RPMTAG_ARCH); int match; /* avoid self-obsoleting packages */ if (rstreq(rpmteN(p), Name) && rstreq(rpmteA(p), oarch)) { char * ohNEVRA = headerGetAsString(oh, RPMTAG_NEVRA); rpmlog(RPMLOG_DEBUG, " Not obsoleting: %s\n", ohNEVRA); free(ohNEVRA); continue; } /* * Rpm prior to 3.0.3 does not have versioned obsoletes. * If no obsoletes version info is available, match all names. */ match = (rpmdsEVR(obsoletes) == NULL); if (!match) match = rpmdsMatches(tspool, oh, -1, obsoletes, 1, _rpmds_nopromote); if (match) { char * ohNEVRA = headerGetAsString(oh, RPMTAG_NEVRA); rpmlog(RPMLOG_DEBUG, " Obsoletes: %s\t\terases %s\n", rpmdsDNEVR(obsoletes)+2, ohNEVRA); free(ohNEVRA); if (removePackage(ts, oh, p)) { rc = 1; break; } } } rpmdbFreeIterator(mi); } return rc; }
char * rpmdsNewDNEVR(const char * dspfx, const rpmds ds) { const char * N = rpmdsN(ds); const char * EVR = rpmdsEVR(ds); rpmsenseFlags Flags = rpmdsFlags(ds); char * tbuf, * t; size_t nb; nb = 0; if (dspfx) nb += strlen(dspfx) + 1; if (N) nb += strlen(N); /* XXX rpm prior to 3.0.2 did not always supply EVR and Flags. */ if (Flags & RPMSENSE_SENSEMASK) { if (nb) nb++; if (Flags & RPMSENSE_LESS) nb++; if (Flags & RPMSENSE_GREATER) nb++; if (Flags & RPMSENSE_EQUAL) nb++; } /* XXX rpm prior to 3.0.2 did not always supply EVR and Flags. */ if (EVR && *EVR) { if (nb) nb++; nb += strlen(EVR); } t = tbuf = xmalloc(nb + 1); if (dspfx) { t = stpcpy(t, dspfx); *t++ = ' '; } if (N) t = stpcpy(t, N); /* XXX rpm prior to 3.0.2 did not always supply EVR and Flags. */ if (Flags & RPMSENSE_SENSEMASK) { if (t != tbuf) *t++ = ' '; if (Flags & RPMSENSE_LESS) *t++ = '<'; if (Flags & RPMSENSE_GREATER) *t++ = '>'; if (Flags & RPMSENSE_EQUAL) *t++ = '='; } /* XXX rpm prior to 3.0.2 did not always supply EVR and Flags. */ if (EVR && *EVR) { if (t != tbuf) *t++ = ' '; t = stpcpy(t, EVR); } *t = '\0'; return tbuf; }
int rpmdsPutToHeader(rpmds ds, Header h) { rpmTagVal tagN = rpmdsTagN(ds); rpmTagVal tagEVR = rpmdsTagEVR(ds); rpmTagVal tagF = rpmdsTagF(ds); rpmTagVal tagTi = rpmdsTagTi(ds); if (!tagN) return -1; rpmds pi = rpmdsInit(ds); while (rpmdsNext(pi) >= 0) { rpmsenseFlags flags = rpmdsFlags(pi); uint32_t index = rpmdsTi(pi); headerPutString(h, tagN, rpmdsN(pi)); headerPutString(h, tagEVR, rpmdsEVR(pi)); headerPutUint32(h, tagF, &flags, 1); if (tagTi != RPMTAG_NOT_FOUND) { headerPutUint32(h, tagTi, &index, 1); } } return 0; }
int rpmdsMerge(rpmds * dsp, rpmds ods) { rpmds ds; int save; int ocount; if (dsp == NULL || ods == NULL) return -1; ocount = rpmdsCount(*dsp); /* If not initialized yet, dup the 1st entry. */ if (*dsp == NULL) { save = ods->Count; ods->Count = 1; *dsp = rpmdsDup(ods); ods->Count = save; } ds = *dsp; if (ds == NULL) return -1; /* Ensure EVR and Flags exist */ if (ds->EVR == NULL) ds->EVR = xcalloc(ds->Count, sizeof(*ds->EVR)); if (ds->Flags == NULL) ds->Flags = xcalloc(ds->Count, sizeof(*ds->Flags)); if (ds->ti == NULL && ods->ti) { int i; ds->ti = xcalloc(ds->Count, sizeof(*ds->ti)); for (i = 0; i < ds->Count; i++) ds->ti[i] = -1; } /* * Add new entries. */ save = ods->i; ods = rpmdsInit(ods); while (rpmdsNext(ods) >= 0) { const char *OEVR; unsigned int u; /* * If this entry is already present, don't bother. */ if (doFind(ds, ods, &u) >= 0) continue; /* * Insert new entry. Ensure pool is unfrozen to allow additions. */ rpmstrPoolUnfreeze(ds->pool); ds->N = xrealloc(ds->N, (ds->Count+1) * sizeof(*ds->N)); if (u < ds->Count) { memmove(ds->N + u + 1, ds->N + u, (ds->Count - u) * sizeof(*ds->N)); } ds->N[u] = rpmstrPoolId(ds->pool, rpmdsN(ods), 1); ds->EVR = xrealloc(ds->EVR, (ds->Count+1) * sizeof(*ds->EVR)); if (u < ds->Count) { memmove(ds->EVR + u + 1, ds->EVR + u, (ds->Count - u) * sizeof(*ds->EVR)); } OEVR = rpmdsEVR(ods); ds->EVR[u] = rpmstrPoolId(ds->pool, OEVR ? OEVR : "", 1); ds->Flags = xrealloc(ds->Flags, (ds->Count+1) * sizeof(*ds->Flags)); if (u < ds->Count) { memmove(ds->Flags + u + 1, ds->Flags + u, (ds->Count - u) * sizeof(*ds->Flags)); } ds->Flags[u] = rpmdsFlags(ods); if (ds->ti || ods->ti) { ds->ti = xrealloc(ds->ti, (ds->Count+1) * sizeof(*ds->ti)); if (u < ds->Count) { memmove(ds->ti + u + 1, ds->ti + u, (ds->Count - u) * sizeof(*ds->ti)); } ds->ti[u] = rpmdsTi(ods); } ds->i = ds->Count; ds->Count++; } ods->i = save; return (ds->Count - ocount); }
static PyObject * rpmdsDep_EVR(rpmdsDepObject * s) { return PyString_FromString(rpmdsEVR(s->ds)); }