41
41
import java .io .File ;
42
42
import java .net .URL ;
43
43
import java .nio .file .*;
44
- import java .util .List ;
45
- import java .util .stream .Collectors ;
44
+ import java .util .Collection ;
46
45
47
46
import static processing .app .I18n .format ;
48
47
import static processing .app .I18n .tr ;
@@ -145,15 +144,13 @@ public void download(URL url, File tmpFile, Progress progress, String statusText
145
144
}
146
145
}
147
146
148
- public void downloadIndexAndSignature (MultiStepProgress progress , List < String > downloadedFilesAccumulator , String packageIndexUrlString , ProgressListener progressListener , SignatureVerifier signatureVerifier ) throws Exception {
147
+ public void downloadIndexAndSignature (MultiStepProgress progress , URL packageIndexUrl , ProgressListener progressListener , SignatureVerifier signatureVerifier ) throws Exception {
149
148
150
149
// Extract the file name from the url
151
- URL packageIndexUrl = new URL (packageIndexUrlString );
152
150
String [] urlPathParts = packageIndexUrl .getFile ().split ("/" );
153
151
File packageIndex = BaseNoGui .indexer .getIndexFile (urlPathParts [urlPathParts .length - 1 ]);
154
152
155
153
final String statusText = tr ("Downloading platforms index..." );
156
- downloadedFilesAccumulator .add (packageIndex .getName ());
157
154
158
155
// Create temp files
159
156
File packageIndexTemp = File .createTempFile (packageIndexUrl .getPath (), ".tmp" );
@@ -164,18 +161,15 @@ public void downloadIndexAndSignature(MultiStepProgress progress, List<String> d
164
161
if (verifyDomain (packageIndexUrl )) {
165
162
URL signatureUrl = new URL (packageIndexUrl .toString () + ".sig" );
166
163
167
- if (checkSignature (progress , downloadedFilesAccumulator , signatureUrl , progressListener , signatureVerifier , statusText , packageIndexTemp )) {
164
+ if (checkSignature (progress , signatureUrl , progressListener , signatureVerifier , statusText , packageIndexTemp )) {
168
165
Files .move (packageIndexTemp .toPath (), packageIndex .toPath (), StandardCopyOption .REPLACE_EXISTING );
169
- } else {
170
- downloadedFilesAccumulator .remove (packageIndex .getName ());
171
166
}
172
167
} else {
173
168
// Move the package index to the destination when the signature is not necessary
174
169
Files .move (packageIndexTemp .toPath (), packageIndex .toPath (), StandardCopyOption .REPLACE_EXISTING );
175
- log .info ("The domain is not selected to verify the signature. packageIndex: {}" , packageIndexUrl );
170
+ log .info ("The domain is not selected to verify the signature. will be copied into this path {}, packageIndex url : {}" , packageIndex , packageIndexUrl );
176
171
}
177
172
} catch (Exception e ) {
178
- downloadedFilesAccumulator .remove (packageIndex .getName ());
179
173
throw e ;
180
174
} finally {
181
175
// Delete useless temp file
@@ -184,12 +178,8 @@ public void downloadIndexAndSignature(MultiStepProgress progress, List<String> d
184
178
}
185
179
186
180
public boolean verifyDomain (URL url ) {
187
- final List <String > domain = PreferencesData .
188
- getCollection ("http.signature_verify_domains" )
189
- .stream ()
190
- // Remove empty strings from the collection
191
- .filter ((v ) -> !v .trim ().isEmpty ())
192
- .collect (Collectors .toList ());
181
+ final Collection <String > domain = PreferencesData .
182
+ getCollection ("http.signature_verify_domains" );
193
183
if (domain .size () == 0 ) {
194
184
// Default domain
195
185
domain .add ("downloads.arduino.cc" );
@@ -202,7 +192,7 @@ public boolean verifyDomain(URL url) {
202
192
}
203
193
}
204
194
205
- public boolean checkSignature (MultiStepProgress progress , List < String > downloadedFilesAccumulator , URL signatureUrl , ProgressListener progressListener , SignatureVerifier signatureVerifier , String statusText , File fileToVerify ) throws Exception {
195
+ public boolean checkSignature (MultiStepProgress progress , URL signatureUrl , ProgressListener progressListener , SignatureVerifier signatureVerifier , String statusText , File fileToVerify ) throws Exception {
206
196
207
197
File packageIndexSignatureTemp = File .createTempFile (signatureUrl .getPath (), ".tmp" );
208
198
// Signature file name
@@ -219,7 +209,6 @@ public boolean checkSignature(MultiStepProgress progress, List<String> downloade
219
209
log .info ("Signature verified. url={}, signature url={}, file to verify={}, signature file={}" , signatureUrl , signatureUrl , fileToVerify , packageIndexSignatureTemp );
220
210
// Move if the signature is ok
221
211
Files .move (packageIndexSignatureTemp .toPath (), packageIndexSignature .toPath (), StandardCopyOption .REPLACE_EXISTING );
222
- downloadedFilesAccumulator .add (packageIndexSignature .getName ());
223
212
} else {
224
213
log .error ("{} file signature verification failed. File ignored." , signatureUrl );
225
214
System .err .println (format (tr ("{0} file signature verification failed. File ignored." ), signatureUrl .toString ()));
0 commit comments