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
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
|
/* This file is part of "reprepro"
* Copyright (C) 2009,2012,2013,2016 Bernhard R. Link
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02111-1301 USA
*/
#include <config.h>
#include <assert.h>
#include <limits.h>
#include <stdint.h>
#include <string.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#include "error.h"
#include "atoms.h"
#include "strlist.h"
#include "chunks.h"
#include "trackingt.h"
#include "tracking.h"
#include "globmatch.h"
#include "package.h"
#include "needbuild.h"
/* list all source packages in a distribution that needs buildd action
For each source package check:
- if tracking is enabled and there is a .log or .changes file
for the given arch -> SKIP
- if there is a binary package for the given architecture -> SKIP
- if the package's Architecture field excludes this arch -> SKIP
- if the package's Binary field only lists existing ones
(i.e. architecture all) -> SKIP
*/
static retvalue tracked_source_needs_build(architecture_t architecture, const char *sourcename, const char *sourceversion, const char *dscfilename, const struct strlist *binary, const struct trackedpackage *tp, bool printarch) {
bool found_binary[binary->count];
const char *archstring = atoms_architectures[architecture];
size_t archstringlen= strlen(archstring);
int i;
memset(found_binary, 0, sizeof(bool)*binary->count);
for (i = 0 ; i < tp->filekeys.count ; i++) {
enum filetype ft = tp->filetypes[i];
const char *fk = tp->filekeys.values[i];
if (ft == ft_XTRA_DATA)
continue;
if (ft == ft_ALL_BINARY) {
int j;
if (architecture == architecture_all) {
/* found an _all.deb, nothing to do */
return RET_NOTHING;
}
/* determine which binary files are arch all
packages: */
for (j = 0 ; j < binary->count ; j++) {
const char *b = binary->values[j];
size_t l = strlen(b);
if (strncmp(fk, b, l) == 0 &&
fk[l] == '_')
found_binary[j] = true;
}
continue;
}
if (ft == ft_ARCH_BINARY) {
const char *a = strrchr(fk, '_');
if (a == NULL)
continue;
a++;
if (strncmp(a, archstring, archstringlen) != 0 ||
a[archstringlen] != '.')
continue;
/* found an .deb with this architecture,
so nothing is to be done */
return RET_NOTHING;
}
if (ft == ft_LOG || ft == ft_BUILDINFO || ft == ft_CHANGES) {
const char *a = strrchr(fk, '_');
const char *e;
if (a == NULL)
continue;
a++;
while ((e = strchr(a, '+')) != NULL) {
if ((size_t)(e-a) != archstringlen) {
a = e+1;
continue;
}
if (memcmp(a, archstring, archstringlen) != 0){
a = e+1;
continue;
}
/* found something for this architecture */
return RET_NOTHING;
}
e = strchr(a, '.');
if (e == NULL)
continue;
if ((size_t)(e-a) != archstringlen) {
a = e+1;
continue;
}
if (memcmp(a, archstring, archstringlen) != 0){
a = e+1;
continue;
}
/* found something for this architecture */
return RET_NOTHING;
}
}
/* nothing for this architecture was found, check if is has any binary
packages that are lacking: */
for (i = 0 ; i < binary->count ; i++) {
if (!found_binary[i]) {
if (printarch)
printf("%s %s %s %s\n",
sourcename, sourceversion,
dscfilename, archstring);
else
printf("%s %s %s\n",
sourcename, sourceversion,
dscfilename);
return RET_OK;
}
}
/* all things listed in Binary already exists, nothing to do: */
return RET_NOTHING;
}
struct needbuild_data { architecture_t architecture;
trackingdb tracks;
/*@null@*/ const char *glob;
bool printarch;
};
static retvalue check_source_needs_build(struct package *package, void *data) {
struct target *target = package->target;
struct needbuild_data *d = data;
struct strlist binary, architectures, filekeys;
const char *dscfilename = NULL;
int i;
retvalue r;
if (d->glob != NULL && !globmatch(package->name, d->glob))
return RET_NOTHING;
r = package_getversion(package);
if (!RET_IS_OK(r))
return r;
r = chunk_getwordlist(package->control, "Architecture", &architectures);
if (RET_IS_OK(r)) {
bool skip = true;
const char *req = atoms_architectures[d->architecture];
const char *hyphen, *os;
size_t osl;
hyphen = strchr(req, '-');
if (hyphen == NULL) {
os = "linux";
osl = 5;
} else {
os = req;
osl = hyphen - req;
}
for (i = 0 ; i < architectures.count ; i++) {
const char *a = architectures.values[i];
if (strcmp(a, req) == 0) {
skip = false;
break;
}
/* "all" is not part of "any" or "*-any" */
if (d->architecture == architecture_all)
continue;
if (strcmp(a, "any") == 0) {
skip = false;
break;
}
size_t al = strlen(a);
if (al < 4 || memcmp(a + al - 4, "-any", 4) != 0)
continue;
if (al == osl + 4 && memcmp(a, os, osl) == 0) {
skip = false;
break;
}
}
strlist_done(&architectures);
if (skip) {
return RET_NOTHING;
}
}
r = chunk_getwordlist(package->control, "Binary", &binary);
if (!RET_IS_OK(r)) {
return r;
}
r = target->getfilekeys(package->control, &filekeys);
if (!RET_IS_OK(r)) {
strlist_done(&binary);
return r;
}
for (i = 0 ; i < filekeys.count ; i++) {
if (endswith(filekeys.values[i], ".dsc")) {
dscfilename = filekeys.values[i];
break;
}
}
if (dscfilename == NULL) {
fprintf(stderr,
"Warning: source package '%s' in '%s' without dsc file!\n",
package->name, target->identifier);
strlist_done(&binary);
strlist_done(&filekeys);
return RET_NOTHING;
}
if (d->tracks != NULL) {
struct trackedpackage *tp;
r = tracking_get(d->tracks, package->name, package->version, &tp);
if (RET_WAS_ERROR(r)) {
strlist_done(&binary);
strlist_done(&filekeys);
return r;
}
if (RET_IS_OK(r)) {
r = tracked_source_needs_build(
d->architecture, package->name,
package->version, dscfilename,
&binary, tp, d->printarch);
trackedpackage_free(tp);
strlist_done(&binary);
strlist_done(&filekeys);
return r;
}
fprintf(stderr,
"Warning: %s's tracking data of %s (%s) is out of date. Run retrack to repair!\n",
target->distribution->codename,
package->name, package->version);
}
// TODO: implement without tracking
strlist_done(&binary);
strlist_done(&filekeys);
return RET_NOTHING;
}
retvalue find_needs_build(struct distribution *distribution, architecture_t architecture, const struct atomlist *onlycomponents, const char *glob, bool printarch) {
retvalue result, r;
struct needbuild_data d;
d.architecture = architecture;
d.glob = glob;
d.printarch = printarch;
if (distribution->tracking == dt_NONE) {
fprintf(stderr,
"ERROR: '%s' has no source package Tracking enabled and\n"
"build-needing is currently only implemented for distributions where\n"
"this is enabled.\n"
"(i.e. you need to add e.g. Tracking: minimal in conf/distribution\n"
"and run retrack (and repeat running it after every update and pull.)\n",
distribution->codename);
return RET_ERROR;
}
if (distribution->tracking != dt_NONE) {
r = tracking_initialize(&d.tracks, distribution, true);
if (RET_WAS_ERROR(r))
return r;
if (r == RET_NOTHING)
d.tracks = NULL;
} else
d.tracks = NULL;
result = package_foreach_c(distribution,
onlycomponents, architecture_source, pt_dsc,
check_source_needs_build, &d);
r = tracking_done(d.tracks, distribution);
RET_ENDUPDATE(result, r);
return result;
}
|