1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
|
/** \ingroup rpmbuild
* \file build/reqprov.c
* Add dependency tags to package header(s).
*/
#include "system.h"
#include <rpm/header.h>
#include <rpm/rpmstring.h>
#include "build/rpmbuild_misc.h"
#include "debug.h"
static int isNewDep(Header h, rpmTag nametag,
const char *N, const char *EVR, rpmsenseFlags Flags,
rpmTag indextag, uint32_t index)
{
int new = 1;
struct rpmtd_s idx;
rpmds ads = rpmdsNew(h, nametag, 0);
rpmds bds = rpmdsSingle(nametag, N, EVR, Flags);
if (indextag) {
headerGet(h, indextag, &idx, HEADERGET_MINMEM);
}
/* XXX there's no guarantee the ds is sorted here so rpmdsFind() wont do */
rpmdsInit(ads);
while (new && 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;
new = 0;
}
if (indextag) {
rpmtdFreeData(&idx);
}
rpmdsFree(ads);
rpmdsFree(bds);
return new;
}
int addReqProv(Header h, rpmTag tagN,
const char * N, const char * EVR, rpmsenseFlags Flags,
uint32_t index)
{
rpmTag versiontag = 0;
rpmTag flagtag = 0;
rpmTag indextag = 0;
rpmsenseFlags extra = RPMSENSE_ANY;
switch (tagN) {
case RPMTAG_PROVIDENAME:
versiontag = RPMTAG_PROVIDEVERSION;
flagtag = RPMTAG_PROVIDEFLAGS;
extra = Flags & RPMSENSE_FIND_PROVIDES;
break;
case RPMTAG_OBSOLETENAME:
versiontag = RPMTAG_OBSOLETEVERSION;
flagtag = RPMTAG_OBSOLETEFLAGS;
break;
case RPMTAG_CONFLICTNAME:
versiontag = RPMTAG_CONFLICTVERSION;
flagtag = RPMTAG_CONFLICTFLAGS;
break;
case RPMTAG_TRIGGERNAME:
versiontag = RPMTAG_TRIGGERVERSION;
flagtag = RPMTAG_TRIGGERFLAGS;
indextag = RPMTAG_TRIGGERINDEX;
extra = Flags & RPMSENSE_TRIGGER;
break;
case RPMTAG_REQUIRENAME:
default:
tagN = RPMTAG_REQUIRENAME;
versiontag = RPMTAG_REQUIREVERSION;
flagtag = RPMTAG_REQUIREFLAGS;
extra = Flags & _ALL_REQUIRES_MASK;
}
/* rpmlib() dependency sanity: only requires permitted, ensure sense bit */
if (rstreqn(N, "rpmlib(", sizeof("rpmlib(")-1)) {
if (tagN != RPMTAG_REQUIRENAME) return 1;
extra |= RPMSENSE_RPMLIB;
}
Flags = (Flags & RPMSENSE_SENSEMASK) | extra;
if (EVR == NULL)
EVR = "";
/* Avoid adding duplicate dependencies. */
if (isNewDep(h, tagN, N, EVR, Flags, indextag, index)) {
headerPutString(h, tagN, N);
headerPutString(h, versiontag, EVR);
headerPutUint32(h, flagtag, &Flags, 1);
if (indextag) {
headerPutUint32(h, indextag, &index, 1);
}
}
return 0;
}
int rpmlibNeedsFeature(Header h, const char * feature, const char * featureEVR)
{
char *reqname = NULL;
int res;
rasprintf(&reqname, "rpmlib(%s)", feature);
res = addReqProv(h, RPMTAG_REQUIRENAME, reqname, featureEVR,
RPMSENSE_RPMLIB|(RPMSENSE_LESS|RPMSENSE_EQUAL), 0);
free(reqname);
return res;
}
|