-
Notifications
You must be signed in to change notification settings - Fork 3
/
repochecker.dpr
249 lines (233 loc) · 8.67 KB
/
repochecker.dpr
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
program repochecker;
uses
readtxt2,sysutils, contnrs, classes, process, util;
var
line : string;
currentpackage, currentversion, currentsourcepackage, currentsourceversion, currentstatus, currentbuiltusing :string;
sourcesandversions : tfphashlist;
procedure reset;
begin
currentpackage := '';
currentversion := '';
currentsourcepackage := '';
currentsourceversion := '';
currentstatus := '';
currentbuiltusing := '';
end;
procedure processpackage;
var
inbrackets : boolean;
dependency : string;
sourceandversion : string;
builtusingstringlist : tstringlist;
i : integer;
begin
if currentversion = '' then begin
writeln(erroutput,'package without version!');
halt;
end;
if currentsourcepackage = '' then currentsourcepackage := currentpackage;
if currentsourceversion = '' then currentsourceversion := currentversion;
sourceandversion := currentsourcepackage + ' ' +currentsourceversion;
//writeln(currentpackage);
//writeln(sourceandversion);
//writeln(erroutput,sourceandversion);
if sourcesandversions.findindexof(sourceandversion) < 0 then sourcesandversions.add(sourceandversion,strnew(pchar(currentpackage)));
if currentbuiltusing <> '' then begin
builtusingstringlist := tstringlist.create;
extractstrings([','],[' '],pchar(currentbuiltusing),builtusingstringlist);
for i := 0 to builtusingstringlist.count-1 do begin
sourceandversion := stringreplace(builtusingstringlist[i],' (= ',' ',[]);
setlength(sourceandversion,length(sourceandversion)-1);
//writeln(sourceandversion);
//writeln('!'+sourceandversion);
if sourcesandversions.findindexof(sourceandversion) < 0 then sourcesandversions.add(sourceandversion,strnew(pchar(currentpackage)));
end;
builtusingstringlist.free;
end;
end;
procedure processtext(t : treadtxt; stripinitialspace : boolean);
var
p : integer;
sourcelinecontent : string;
begin
reset;
repeat
line := t.readline;
if stripinitialspace and (length(line) > 0) then begin
if line[1] = ' ' then line := copy(line,2,maxlongint);
end;
//writeln(erroutput,line);
if stringstartis(line,'Package:') then begin
currentpackage := trim(copy(line,9,maxlongint));
end;
if stringstartis(line,'Version:') then begin
currentversion := trim(copy(line,9,maxlongint));
end;
if stringstartis(line,'Source:') then begin
sourcelinecontent := trim(copy(line,8,maxlongint));
p := pos('(',sourcelinecontent);
if p = 0 then begin
currentsourcepackage := sourcelinecontent;
end else begin
currentsourcepackage := trim(copy(sourcelinecontent,1,p-1));
currentsourceversion := copy(sourcelinecontent,p+1,255);
p := pos(')',currentsourceversion);
currentsourceversion := trim(copy(currentsourceversion,1,p-1));
end;
end;
if stringstartis(line,'Built-Using:') then begin
currentbuiltusing := trim(copy(line,13,maxlongint));
end;
if stringstartis(line,'Status:') then begin
currentstatus := trim(copy(line,8,maxlongint));
end;
if line = '' then begin
//end of block
if currentpackage <> '' then processpackage;
reset;
end;
until t.eof;
if currentpackage <> '' then processpackage;
end;
procedure processfile(filename:string);
var
t: treadtxt;
begin
//writeln(filename);
t := treadtxt.createf(filename);
processtext(t,false);
t.free;
end;
var
i: integer;
s1,s2,s3,s4 : tsearchrec;
findresult : longint;
param : string;
process : tprocess;
sourcepackage,version,dirname,filepath : string;
p : integer;
found : boolean;
exitstatus : integer;
t:treadtxt;
sl : tstringlist;
begin
writeln('checking that required sources are available');
writeln('phase 1: reading package lists');
sourcesandversions := tfphashlist.create;
findresult := findfirst('dists/*',faDirectory,s1);
while findresult = 0 do begin
if ((s1.attr and fadirectory) > 0) and (s1.name <> '.') and (s1.name <> '..') then begin
findresult := findfirst('dists/'+s1.name+'/*',faDirectory,s2);
while findresult = 0 do begin
if ((s2.attr and fadirectory) > 0) and (s2.name <> '.') and (s2.name <> '..') then begin
findresult := findfirst('dists/'+s1.name+'/'+s2.name+'/binary-*',faDirectory,s3);
while findresult = 0 do begin
if ((s3.attr and fadirectory) > 0) and (s3.name <> '.') and (s3.name <> '..') then begin
processfile('dists/'+s1.name+'/'+s2.name+'/'+s3.name+'/Packages');
end;
findresult := findnext(s3);
end;
findclose(s3);
findresult := findfirst('dists/'+s1.name+'/'+s2.name+'/debian-installer/binary-*',faDirectory,s3);
while findresult = 0 do begin
if ((s3.attr and fadirectory) > 0) and (s3.name <> '.') and (s3.name <> '..') then begin
processfile('dists/'+s1.name+'/'+s2.name+'/debian-installer/'+s3.name+'/Packages');
end;
findresult := findnext(s3);
end;
findclose(s3);
end;
findresult := findnext(s2);
end;
findclose(s2);
end;
findresult := findnext(s1);
end;
findclose(s1);
writeln('phase2: checking required source packages are in the pool');
exitstatus := 0;
for i := 0 to sourcesandversions.count - 1 do begin
line := sourcesandversions.nameofindex(i);
p := pos(' ',line);
sourcepackage := copy(line,1,p-1);
version := copy(line,p+1,maxlongint);
makesourcepackagepath(sourcepackage,version,dirname,filepath);
found := false;
findresult := findfirst('pool/*',faDirectory,s1);
while findresult = 0 do begin
if ((s1.attr and fadirectory) > 0) and (s1.name <> '.') and (s1.name <> '..') then begin
if fileexists('pool/'+s1.name+'/'+filepath) then found := true;
end;
findresult := findnext(s1);
end;
findclose(s1);
if not found then begin
writeln('failed to find ',filepath,' needed by package '+pchar(sourcesandversions.items[i]));
exitstatus := 1;
end;
end;
if exitstatus > 0 then begin
writeln('exiting with error due to sources not found');
halt(exitstatus);
end;
sl := tstringlist.create;
writeln('phase3: checking source packages are complete');
findresult := findfirst('pool/*',faDirectory,s1);
while findresult = 0 do begin
if ((s1.attr and fadirectory) > 0) and (s1.name <> '.') and (s1.name <> '..') then begin
findresult := findfirst('pool/'+s1.name+'/*',faDirectory,s2);
while findresult = 0 do begin
if ((s2.attr and fadirectory) > 0) and (s2.name <> '.') and (s2.name <> '..') then begin
findresult := findfirst('pool/'+s1.name+'/'+s2.name+'/*',faDirectory,s3);
while findresult = 0 do begin
if ((s3.attr and fadirectory) > 0) and (s3.name <> '.') and (s3.name <> '..') then begin
findresult := findfirst('pool/'+s1.name+'/'+s2.name+'/'+s3.name+'/*.dsc',faanyfile,s4);
while findresult = 0 do begin
//writeln('pool/'+s1.name+'/'+s2.name+'/'+s3.name+'/'+s4.name);
t := treadtxt.createf('pool/'+s1.name+'/'+s2.name+'/'+s3.name+'/'+s4.name);
line :=t.readline;
while trim(line) <> 'Files:' do begin
if t.eof then begin
writeln('broken dsc found, no files section');
halt(99);
end;
Line := t.readline;
end;
while not t.eof do begin
line := t.readline;
if length(line) =0 then break;
if line[1] <> ' ' then break;
//writeln(line);
sl.clear;
extractstrings([' '],[],pchar(line),sl);
//for i := 0 to sl.count-1 do begin
//writeln(sl[i]);
//end;
if not fileexists('pool/'+s1.name+'/'+s2.name+'/'+s3.name+'/'+sl[2]) then begin
writeln('pool/'+s1.name+'/'+s2.name+'/'+s3.name+'/'+sl[2]+' needed by '+'pool/'+s1.name+'/'+s2.name+'/'+s3.name+'/'+s4.name+' not found');
exitstatus := 2;
end;
end;
t.free;
//halt;
findresult := findnext(s4);
end;
findclose(s4);
end;
findresult := findnext(s3);
end;
findclose(s3);
end;
findresult := findnext(s2);
end;
findclose(s2);
end;
findresult := findnext(s1);
end;
findclose(s1);
if exitstatus > 0 then begin
writeln('exiting with error due to incomplete source package in pool');
halt(exitstatus);
end;
end.