forked from NetBSDfr/pkgin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pkg_check.c
240 lines (202 loc) · 6.65 KB
/
pkg_check.c
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
/* $Id: pkg_check.c,v 1.7 2012/07/15 17:36:34 imilh Exp $ */
/*
* Copyright (c) 2009, 2010, 2011, 2012, 2013 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Emile "iMil" Heitor <imil@NetBSD.org> .
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
*/
#include "pkgin.h"
/* find required files (REQUIRES) from PROVIDES or filename */
int
pkg_met_reqs(Plisthead *impacthead)
{
int met_reqs = 1;
Pkglist *pimpact, *requires;
Plistnumbered *requireshead = NULL;
struct stat sb;
#ifdef CHECK_PROVIDES
int foundreq;
Pkglist *impactprov = NULL, *provides = NULL;
Plistnumbered *l_provideshead = NULL, *r_provideshead = NULL;
l_provideshead = rec_pkglist(LOCAL_PROVIDES);
#endif
/* first, parse impact list */
SLIST_FOREACH(pimpact, impacthead, next) {
/* retreive requires list for package */
if ((requireshead = rec_pkglist(GET_REQUIRES_QUERY,
pimpact->full)) == NULL)
/* empty requires list (very unlikely) */
continue;
/* parse requires list */
SLIST_FOREACH(requires, requireshead->P_Plisthead, next) {
#ifdef CHECK_PROVIDES
foundreq = 0;
#endif
/* for performance sake, first check basesys */
if ((strncmp(requires->full, LOCALBASE,
strlen(LOCALBASE) - 1)) != 0) {
if (stat(requires->full, &sb) < 0) {
printf(MSG_REQT_NOT_PRESENT,
requires->full, pimpact->full);
/*
* mark as DONOTHING,
* requirement missing
*/
pimpact->action = UNMET_REQ;
met_reqs = 0;
}
/* was a basysfile, no need to check PROVIDES */
continue;
}
/*
* FIXME: the code below actually works, but there's no
* point losing performances when some REQUIRES do not
* match PROVIDES in pkg_summary(5). This is a known
* issue and will hopefuly be fixed.
*/
#ifndef CHECK_PROVIDES
continue;
#else
/* search what local packages provide */
SLIST_FOREACH(provides, l_provideshead->P_Plisthead,
next) {
if (strncmp(provides->full,
requires->full,
strlen(requires->full)) == 0) {
foundreq = 1;
/* found, no need to go further*/
break;
} /* match */
} /* SLIST_FOREACH LOCAL_PROVIDES */
/*
* REQUIRES was not found on local packages,
* try impact list
*/
if (!foundreq) {
/* re-parse impact list to retreive PROVIDES */
SLIST_FOREACH(impactprov, impacthead, next) {
if ((r_provideshead =
rec_pkglist(GET_PROVIDES_QUERY,
impactprov->full)) == NULL)
continue;
/*
* then parse provides list for
* every package
*/
SLIST_FOREACH(provides,
r_provideshead->P_Plisthead, next) {
if (strncmp(provides->full,
requires->full,
strlen(requires->full)) == 0) {
foundreq = 1;
/*
* found, no need to
* go further return
* to impactprov list
*/
break;
} /* match */
}
free_pkglist(&r_provideshead->P_Plisthead, LIST);
free(r_provideshead);
if (foundreq)
/* exit impactprov list loop */
break;
} /* SLIST_NEXT impactprov */
} /* if (!foundreq) LOCAL_PROVIDES -> impact list */
/* FIXME: BIG FAT DISCLAIMER
* as of 04/2009, some packages described in pkg_summary
* have unmet REQUIRES. This is a known bug that makes
* the PROVIDES untrustable and some packages
* uninstallable. foundreq is forced to 1 for now for
* every REQUIRES matching LOCALBASE, which is hardcoded
* to "/usr/pkg"
*/
if (!foundreq) {
printf(MSG_REQT_NOT_PRESENT_DEPS,
requires->full);
foundreq = 1;
}
#endif
} /* SLIST_FOREACH requires */
free_pkglist(&requireshead->P_Plisthead, LIST);
free(requireshead);
} /* 1st impact SLIST_FOREACH */
#ifdef CHECK_PROVIDES
free_pkglist(&l_provideshead->P_Plisthead, LIST);
free(l_provideshead);
#endif
return met_reqs;
}
/* check for conflicts and if needed files are present */
int
pkg_has_conflicts(Pkglist *pimpact)
{
int has_conflicts = 0;
char *conflict_pkg, query[BUFSIZ];
Pkglist *conflicts; /* SLIST conflicts pointer */
Plistnumbered *conflictshead;
/* conflicts list */
if ((conflictshead = rec_pkglist(LOCAL_CONFLICTS)) == NULL)
return 0;
/* check conflicts */
SLIST_FOREACH(conflicts, conflictshead->P_Plisthead, next) {
if (pkg_match(conflicts->full, pimpact->full)) {
/* got a conflict, retrieve conflicting local package */
snprintf(query, BUFSIZ,
GET_CONFLICT_QUERY, conflicts->full);
XMALLOC(conflict_pkg, BUFSIZ * sizeof(char));
if (pkgindb_doquery(query,
pdb_get_value, conflict_pkg) == PDB_OK)
printf(MSG_CONFLICT_PKG,
pimpact->full, conflict_pkg);
XFREE(conflict_pkg);
has_conflicts = 1;
} /* match conflict */
} /* SLIST_FOREACH conflicts */
free_pkglist(&conflictshead->P_Plisthead, LIST);
free(conflictshead);
return has_conflicts;
}
void
show_prov_req(const char *query, const char *pkgname)
{
const char *out[] = { "provided", "required" };
const char *say;
char *fullpkgname;
Plistnumbered *plisthead;
Pkglist *plist;
if ((fullpkgname = unique_pkg(pkgname, REMOTE_PKG)) == NULL)
errx(EXIT_FAILURE, MSG_PKG_NOT_AVAIL, pkgname);
say = ( query == GET_PROVIDES_QUERY ) ? out[0] : out[1];
if ((plisthead = rec_pkglist(query, fullpkgname)) == NULL) {
printf(MSG_NO_PROV_REQ, say, fullpkgname);
exit(EXIT_SUCCESS);
}
printf(MSG_FILES_PROV_REQ, say, fullpkgname);
SLIST_FOREACH(plist, plisthead->P_Plisthead, next)
printf("\t%s\n", plist->full);
}