11 /*@access rpmDepSet @*/
14 * Enable noisy range comparison debugging message?
17 static int _noisy_range_comparison_debug_message = 0;
20 static int _ds_debug = 0;
22 rpmDepSet XrpmdsUnlink(rpmDepSet ds, const char * msg, const char * fn, unsigned ln)
24 if (ds == NULL) return NULL;
26 if (_ds_debug && msg != NULL)
27 fprintf(stderr, "--> ds %p -- %d %s at %s:%u\n", ds, ds->nrefs, msg, fn, ln);
33 rpmDepSet XrpmdsLink(rpmDepSet ds, const char * msg, const char * fn, unsigned ln)
35 if (ds == NULL) return NULL;
39 if (_ds_debug && msg != NULL)
40 fprintf(stderr, "--> ds %p ++ %d %s at %s:%u\n", ds, ds->nrefs, msg, fn, ln);
43 /*@-refcounttrans@*/ return ds; /*@=refcounttrans@*/
46 rpmDepSet dsFree(rpmDepSet ds)
48 HFD_t hfd = headerFreeData;
55 return rpmdsUnlink(ds, ds->Type);
59 fprintf(stderr, "*** ds %p\t%s[%d]\n", ds, ds->Type, ds->Count);
63 if (ds->tagN == RPMTAG_PROVIDENAME) {
64 tagEVR = RPMTAG_PROVIDEVERSION;
65 tagF = RPMTAG_PROVIDEFLAGS;
67 if (ds->tagN == RPMTAG_REQUIRENAME) {
68 tagEVR = RPMTAG_REQUIREVERSION;
69 tagF = RPMTAG_REQUIREFLAGS;
71 if (ds->tagN == RPMTAG_CONFLICTNAME) {
72 tagEVR = RPMTAG_CONFLICTVERSION;
73 tagF = RPMTAG_CONFLICTFLAGS;
75 if (ds->tagN == RPMTAG_OBSOLETENAME) {
76 tagEVR = RPMTAG_OBSOLETEVERSION;
77 tagF = RPMTAG_OBSOLETEFLAGS;
79 if (ds->tagN == RPMTAG_TRIGGERNAME) {
80 tagEVR = RPMTAG_TRIGGERVERSION;
81 tagF = RPMTAG_TRIGGERFLAGS;
87 ds->N = hfd(ds->N, ds->Nt);
88 ds->EVR = hfd(ds->EVR, ds->EVRt);
90 ds->Flags = (ds->h != NULL ? hfd(ds->Flags, ds->Ft) : _free(ds->Flags));
92 ds->h = headerFree(ds->h, ds->Type);
96 ds->DNEVR = _free(ds->DNEVR);
98 (void) rpmdsUnlink(ds, ds->Type);
99 /*@-refcounttrans -usereleased@*/
100 memset(ds, 0, sizeof(*ds)); /* XXX trash and burn */
102 /*@=refcounttrans =usereleased@*/
106 rpmDepSet dsNew(Header h, rpmTag tagN, int scareMem)
109 (scareMem ? (HGE_t) headerGetEntryMinMemory : (HGE_t) headerGetEntry);
117 if (tagN == RPMTAG_PROVIDENAME) {
119 tagEVR = RPMTAG_PROVIDEVERSION;
120 tagF = RPMTAG_PROVIDEFLAGS;
122 if (tagN == RPMTAG_REQUIRENAME) {
124 tagEVR = RPMTAG_REQUIREVERSION;
125 tagF = RPMTAG_REQUIREFLAGS;
127 if (tagN == RPMTAG_CONFLICTNAME) {
129 tagEVR = RPMTAG_CONFLICTVERSION;
130 tagF = RPMTAG_CONFLICTFLAGS;
132 if (tagN == RPMTAG_OBSOLETENAME) {
134 tagEVR = RPMTAG_OBSOLETEVERSION;
135 tagF = RPMTAG_OBSOLETEFLAGS;
137 if (tagN == RPMTAG_TRIGGERNAME) {
139 tagEVR = RPMTAG_TRIGGERVERSION;
140 tagF = RPMTAG_TRIGGERFLAGS;
145 if (hge(h, tagN, &Nt, (void **) &N, &Count)
146 && N != NULL && Count > 0)
150 ds = xcalloc(1, sizeof(*ds));
152 ds->h = (scareMem ? headerLink(h, ds->Type) : NULL);
160 xx = hge(h, tagEVR, &ds->EVRt, (void **) &ds->EVR, NULL);
161 xx = hge(h, tagF, &ds->Ft, (void **) &ds->Flags, NULL);
162 if (!scareMem && ds->Flags != NULL)
163 ds->Flags = memcpy(xmalloc(ds->Count * sizeof(*ds->Flags)),
164 ds->Flags, ds->Count * sizeof(*ds->Flags));
168 fprintf(stderr, "*** ds %p\t%s[%d]\n", ds, ds->Type, ds->Count);
175 /*@-nullstate@*/ /* FIX: ds->Flags may be NULL */
176 return rpmdsLink(ds, (ds ? ds->Type : NULL));
180 char * dsDNEVR(const char * dspfx, const rpmDepSet ds)
186 if (dspfx) nb += strlen(dspfx) + 1;
187 if (ds->N[ds->i]) nb += strlen(ds->N[ds->i]);
188 if (ds->Flags[ds->i] & RPMSENSE_SENSEMASK) {
190 if (ds->Flags[ds->i] & RPMSENSE_LESS) nb++;
191 if (ds->Flags[ds->i] & RPMSENSE_GREATER) nb++;
192 if (ds->Flags[ds->i] & RPMSENSE_EQUAL) nb++;
194 if (ds->EVR[ds->i] && *ds->EVR[ds->i]) {
196 nb += strlen(ds->EVR[ds->i]);
199 t = tbuf = xmalloc(nb + 1);
201 t = stpcpy(t, dspfx);
205 t = stpcpy(t, ds->N[ds->i]);
206 if (ds->Flags[ds->i] & RPMSENSE_SENSEMASK) {
207 if (t != tbuf) *t++ = ' ';
208 if (ds->Flags[ds->i] & RPMSENSE_LESS) *t++ = '<';
209 if (ds->Flags[ds->i] & RPMSENSE_GREATER) *t++ = '>';
210 if (ds->Flags[ds->i] & RPMSENSE_EQUAL) *t++ = '=';
212 if (ds->EVR[ds->i] && *ds->EVR[ds->i]) {
213 if (t != tbuf) *t++ = ' ';
214 t = stpcpy(t, ds->EVR[ds->i]);
220 rpmDepSet dsThis(Header h, rpmTag tagN, int_32 Flags)
222 HGE_t hge = (HGE_t) headerGetEntryMinMemory;
225 const char * n, * v, * r;
227 const char ** N, ** EVR;
231 if (tagN == RPMTAG_PROVIDENAME) {
234 if (tagN == RPMTAG_REQUIRENAME) {
237 if (tagN == RPMTAG_CONFLICTNAME) {
240 if (tagN == RPMTAG_OBSOLETENAME) {
243 if (tagN == RPMTAG_TRIGGERNAME) {
248 xx = headerNVR(h, &n, &v, &r);
250 xx = hge(h, RPMTAG_EPOCH, NULL, (void **)&ep, NULL);
252 t = xmalloc(sizeof(*N) + strlen(n) + 1);
253 N = (const char **) t;
258 t = xmalloc(sizeof(*EVR) +
259 (ep ? 20 : 0) + strlen(v) + strlen(r) + sizeof("-"));
260 EVR = (const char **) t;
264 sprintf(t, "%d:", *ep);
267 t = stpcpy( stpcpy( stpcpy( t, v), "-"), r);
269 ds = xcalloc(1, sizeof(*ds));
276 ds->Flags = xmalloc(sizeof(*ds->Flags)); ds->Flags[0] = Flags;
279 pre[0] = ds->Type[0];
281 /*@-nullstate@*/ /* LCL: ds->Type may be NULL ??? */
282 ds->DNEVR = dsDNEVR(pre, ds);
287 return rpmdsLink(ds, (ds ? ds->Type : NULL));
290 rpmDepSet dsSingle(rpmTag tagN, const char * N, const char * EVR, int_32 Flags)
295 if (tagN == RPMTAG_PROVIDENAME) {
298 if (tagN == RPMTAG_REQUIRENAME) {
301 if (tagN == RPMTAG_CONFLICTNAME) {
304 if (tagN == RPMTAG_OBSOLETENAME) {
307 if (tagN == RPMTAG_TRIGGERNAME) {
312 ds = xcalloc(1, sizeof(*ds));
318 ds->N = xmalloc(sizeof(*ds->N)); ds->N[0] = N;
319 ds->EVR = xmalloc(sizeof(*ds->EVR)); ds->EVR[0] = EVR;
321 ds->Flags = xmalloc(sizeof(*ds->Flags)); ds->Flags[0] = Flags;
326 ds->DNEVR = dsDNEVR(t, ds);
330 return rpmdsLink(ds, (ds ? ds->Type : NULL));
333 int dsiGetCount(rpmDepSet ds)
335 return (ds != NULL ? ds->Count : 0);
338 int dsiGetIx(rpmDepSet ds)
340 return (ds != NULL ? ds->i : -1);
343 int dsiSetIx(rpmDepSet ds, int ix)
354 const char * dsiGetDNEVR(rpmDepSet ds)
356 const char * DNEVR = NULL;
358 if (ds != NULL && ds->i >= 0 && ds->i < ds->Count) {
359 if (ds->DNEVR != NULL)
365 const char * dsiGetN(rpmDepSet ds)
367 const char * N = NULL;
369 if (ds != NULL && ds->i >= 0 && ds->i < ds->Count) {
376 const char * dsiGetEVR(rpmDepSet ds)
378 const char * EVR = NULL;
380 if (ds != NULL && ds->i >= 0 && ds->i < ds->Count) {
382 EVR = ds->EVR[ds->i];
387 int_32 dsiGetFlags(rpmDepSet ds)
391 if (ds != NULL && ds->i >= 0 && ds->i < ds->Count) {
392 if (ds->Flags != NULL)
393 Flags = ds->Flags[ds->i];
398 void dsiNotify(rpmDepSet ds, const char * where, int rc)
400 if (!(ds != NULL && ds->i >= 0 && ds->i < ds->Count))
402 if (!(ds->Type != NULL && ds->DNEVR != NULL))
405 rpmMessage(RPMMESS_DEBUG, "%9s: %-45s %-s %s\n", ds->Type,
406 (!strcmp(ds->DNEVR, "cached") ? ds->DNEVR : ds->DNEVR+2),
407 (rc ? _("NO ") : _("YES")),
408 (where != NULL ? where : ""));
411 int dsiNext(/*@null@*/ rpmDepSet ds)
416 if (ds != NULL && ++ds->i >= 0) {
417 if (ds->i < ds->Count) {
420 ds->DNEVR = _free(ds->DNEVR);
421 t[0] = ((ds->Type != NULL) ? ds->Type[0] : '\0');
424 ds->DNEVR = dsDNEVR(t, ds);
430 /*@-modfilesystem @*/
431 if (_ds_debug < 0 && i != -1)
432 fprintf(stderr, "*** ds %p\t%s[%d]: %s\n", ds, (ds->Type ? ds->Type : "?Type?"), i, (ds->DNEVR ? ds->DNEVR : "?DNEVR?"));
433 /*@=modfilesystem @*/
440 rpmDepSet dsiInit(/*@returned@*/ /*@null@*/ rpmDepSet ds)
451 * Split EVR into epoch, version, and release components.
452 * @param evr [epoch:]version[-release] string
453 * @retval *ep pointer to epoch
454 * @retval *vp pointer to version
455 * @retval *rp pointer to release
458 void parseEVR(char * evr,
459 /*@exposed@*/ /*@out@*/ const char ** ep,
460 /*@exposed@*/ /*@out@*/ const char ** vp,
461 /*@exposed@*/ /*@out@*/ const char ** rp)
462 /*@modifies *ep, *vp, *rp @*/
465 const char *version; /* assume only version is present */
470 while (*s && xisdigit(*s)) s++; /* s points to epoch terminator */
471 se = strrchr(s, '-'); /* se points to version terminator */
478 if (*epoch == '\0') epoch = "0";
481 epoch = NULL; /* XXX disable epoch compare if missing */
492 if (vp) *vp = version;
493 if (rp) *rp = release;
496 int dsCompare(const rpmDepSet A, const rpmDepSet B)
498 const char *aDepend = (A->DNEVR != NULL ? xstrdup(A->DNEVR+2) : "");
499 const char *bDepend = (B->DNEVR != NULL ? xstrdup(B->DNEVR+2) : "");
501 const char *aE, *aV, *aR, *bE, *bV, *bR;
505 /* Different names don't overlap. */
506 if (strcmp(A->N[A->i], B->N[B->i])) {
511 /* Same name. If either A or B is an existence test, always overlap. */
512 if (!((A->Flags[A->i] & RPMSENSE_SENSEMASK) && (B->Flags[B->i] & RPMSENSE_SENSEMASK))) {
517 /* If either EVR is non-existent or empty, always overlap. */
518 if (!(A->EVR[A->i] && *A->EVR[A->i] && B->EVR[B->i] && *B->EVR[B->i])) {
523 /* Both AEVR and BEVR exist. */
524 aEVR = xstrdup(A->EVR[A->i]);
525 parseEVR(aEVR, &aE, &aV, &aR);
526 bEVR = xstrdup(B->EVR[B->i]);
527 parseEVR(bEVR, &bE, &bV, &bR);
529 /* Compare {A,B} [epoch:]version[-release] */
531 if (aE && *aE && bE && *bE)
532 sense = rpmvercmp(aE, bE);
533 else if (aE && *aE && atol(aE) > 0) {
534 /* XXX legacy epoch-less requires/conflicts compatibility */
535 rpmMessage(RPMMESS_DEBUG, _("the \"B\" dependency needs an epoch (assuming same as \"A\")\n\tA %s\tB %s\n"),
538 } else if (bE && *bE && atol(bE) > 0)
542 sense = rpmvercmp(aV, bV);
543 if (sense == 0 && aR && *aR && bR && *bR) {
544 sense = rpmvercmp(aR, bR);
550 /* Detect overlap of {A,B} range. */
552 if (sense < 0 && ((A->Flags[A->i] & RPMSENSE_GREATER) || (B->Flags[B->i] & RPMSENSE_LESS))) {
554 } else if (sense > 0 && ((A->Flags[A->i] & RPMSENSE_LESS) || (B->Flags[B->i] & RPMSENSE_GREATER))) {
556 } else if (sense == 0 &&
557 (((A->Flags[A->i] & RPMSENSE_EQUAL) && (B->Flags[B->i] & RPMSENSE_EQUAL)) ||
558 ((A->Flags[A->i] & RPMSENSE_LESS) && (B->Flags[B->i] & RPMSENSE_LESS)) ||
559 ((A->Flags[A->i] & RPMSENSE_GREATER) && (B->Flags[B->i] & RPMSENSE_GREATER)))) {
564 if (_noisy_range_comparison_debug_message)
565 rpmMessage(RPMMESS_DEBUG, _(" %s A %s\tB %s\n"),
566 (result ? _("YES") : _("NO ")), aDepend, bDepend);
567 aDepend = _free(aDepend);
568 bDepend = _free(bDepend);
572 void dsProblem(rpmProblemSet tsprobs, const char * pkgNEVR, const rpmDepSet ds,
573 const fnpyKey * suggestedKeys)
575 const char * Name = dsiGetN(ds);
576 const char * DNEVR = dsiGetDNEVR(ds);
577 const char * EVR = dsiGetEVR(ds);
581 if (tsprobs == NULL) return;
584 if (Name == NULL) Name = "?N?";
585 if (EVR == NULL) EVR = "?EVR?";
586 if (DNEVR == NULL) DNEVR = "? ?N? ?OP? ?EVR?";
589 rpmMessage(RPMMESS_DEBUG, _("package %s has unsatisfied %s: %s\n"),
590 pkgNEVR, ds->Type, DNEVR+2);
592 type = (DNEVR[0] == 'C' && DNEVR[1] == ' ')
593 ? RPMPROB_CONFLICT : RPMPROB_REQUIRES;
594 key = (suggestedKeys ? suggestedKeys[0] : NULL);
595 rpmProblemSetAppend(tsprobs, type, pkgNEVR, key,
596 NULL, NULL, DNEVR, 0);
599 int rangeMatchesDepFlags (Header h, const rpmDepSet req)
602 rpmDepSet provides = NULL;
605 if (!(req->Flags[req->i] & RPMSENSE_SENSEMASK) || !req->EVR[req->i] || *req->EVR[req->i] == '\0')
608 /* Get provides information from header */
609 provides = dsiInit(dsNew(h, RPMTAG_PROVIDENAME, scareMem));
610 if (provides == NULL)
611 goto exit; /* XXX should never happen */
614 * Rpm prior to 3.0.3 did not have versioned provides.
615 * If no provides version info is available, match any/all requires
618 if (provides->EVR == NULL) {
624 if (provides != NULL)
625 while (dsiNext(provides) >= 0) {
627 /* Filter out provides that came along for the ride. */
628 if (strcmp(provides->N[provides->i], req->N[req->i]))
631 result = dsCompare(provides, req);
633 /* If this provide matches the require, we're done. */
639 provides = dsFree(provides);
644 int headerMatchesDepFlags(const Header h, const rpmDepSet req)
646 HGE_t hge = (HGE_t)headerGetEntryMinMemory;
647 const char * pkgN, * v, * r;
651 int_32 pkgFlags = RPMSENSE_EQUAL;
653 int rc = 1; /* XXX assume match as names should be the same already here */
655 if (!((req->Flags[req->i] & RPMSENSE_SENSEMASK) && req->EVR[req->i] && *req->EVR[req->i]))
658 /* Get package information from header */
659 (void) headerNVR(h, &pkgN, &v, &r);
661 pkgEVR = t = alloca(21 + strlen(v) + 1 + strlen(r) + 1);
663 if (hge(h, RPMTAG_EPOCH, NULL, (void **) &epoch, NULL)) {
664 sprintf(t, "%d:", *epoch);
668 (void) stpcpy( stpcpy( stpcpy(t, v) , "-") , r);
670 if ((pkg = dsSingle(RPMTAG_PROVIDENAME, pkgN, pkgEVR, pkgFlags)) != NULL) {
671 rc = dsCompare(pkg, req);