Skip to content

Commit a8c7184

Browse files
author
Mattia Bertorello
committed
Do not cache the core or the library because are too big
and will be downloaded only one time
1 parent dde5668 commit a8c7184

File tree

6 files changed

+27
-27
lines changed

6 files changed

+27
-27
lines changed

Diff for: arduino-core/src/cc/arduino/contributions/DownloadableContributionsDownloader.java

+9-9
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,11 @@ public DownloadableContributionsDownloader(File _stagingFolder) {
5656
stagingFolder = _stagingFolder;
5757
}
5858

59-
public File download(DownloadableContribution contribution, Progress progress, final String statusText, ProgressListener progressListener) throws Exception {
60-
return download(contribution, progress, statusText, progressListener, false);
59+
public File download(DownloadableContribution contribution, Progress progress, final String statusText, ProgressListener progressListener, boolean allowCache) throws Exception {
60+
return download(contribution, progress, statusText, progressListener, false, allowCache);
6161
}
6262

63-
public File download(DownloadableContribution contribution, Progress progress, final String statusText, ProgressListener progressListener, boolean noResume) throws Exception {
63+
public File download(DownloadableContribution contribution, Progress progress, final String statusText, ProgressListener progressListener, boolean noResume, boolean allowCache) throws Exception {
6464
URL url = new URL(contribution.getUrl());
6565
Path outputFile = Paths.get(stagingFolder.getAbsolutePath(), contribution.getArchiveFileName());
6666

@@ -75,7 +75,7 @@ public File download(DownloadableContribution contribution, Progress progress, f
7575
while (true) {
7676
// Need to download or resume downloading?
7777
if (!Files.isRegularFile(outputFile, LinkOption.NOFOLLOW_LINKS) || (Files.size(outputFile) < contribution.getSize())) {
78-
download(url, outputFile.toFile(), progress, statusText, progressListener, noResume);
78+
download(url, outputFile.toFile(), progress, statusText, progressListener, noResume, allowCache);
7979
downloaded = true;
8080
}
8181

@@ -121,11 +121,11 @@ private boolean hasChecksum(DownloadableContribution contribution) {
121121
return algo != null && !algo.isEmpty();
122122
}
123123

124-
public void download(URL url, File tmpFile, Progress progress, String statusText, ProgressListener progressListener) throws Exception {
125-
download(url, tmpFile, progress, statusText, progressListener, false);
124+
public void download(URL url, File tmpFile, Progress progress, String statusText, ProgressListener progressListener, boolean allowCache) throws Exception {
125+
download(url, tmpFile, progress, statusText, progressListener, false, allowCache);
126126
}
127127

128-
public void download(URL url, File tmpFile, Progress progress, String statusText, ProgressListener progressListener, boolean noResume) throws Exception {
128+
public void download(URL url, File tmpFile, Progress progress, String statusText, ProgressListener progressListener, boolean noResume, boolean allowCache) throws Exception {
129129
FileDownloader downloader = new FileDownloader(url, tmpFile);
130130
downloader.addObserver((o, arg) -> {
131131
FileDownloader me = (FileDownloader) o;
@@ -139,7 +139,7 @@ public void download(URL url, File tmpFile, Progress progress, String statusText
139139
progress.setProgress(me.getProgress());
140140
progressListener.onProgress(progress);
141141
});
142-
downloader.download(noResume);
142+
downloader.download(noResume, allowCache);
143143
if (!downloader.isCompleted()) {
144144
throw new Exception(format(tr("Error downloading {0}"), url), downloader.getError());
145145
}
@@ -157,7 +157,7 @@ public void downloadIndexAndSignature(MultiStepProgress progress, URL packageInd
157157
File packageIndexTemp = File.createTempFile(indexFileName, ".tmp");
158158
try {
159159
// Download package index
160-
download(packageIndexUrl, packageIndexTemp, progress, statusText, progressListener, true);
160+
download(packageIndexUrl, packageIndexTemp, progress, statusText, progressListener, true, true);
161161

162162
if (verifyDomain(packageIndexUrl)) {
163163
URL signatureUrl = new URL(packageIndexUrl.toString() + ".sig");

Diff for: arduino-core/src/cc/arduino/contributions/GZippedJsonDownloader.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -52,18 +52,18 @@ public GZippedJsonDownloader(DownloadableContributionsDownloader downloader, URL
5252
this.gzippedUrl = gzippedUrl;
5353
}
5454

55-
public void download(File tmpFile, Progress progress, String statusText, ProgressListener progressListener) throws Exception {
55+
public void download(File tmpFile, Progress progress, String statusText, ProgressListener progressListener, boolean allowCache) throws Exception {
5656
File gzipTmpFile = null;
5757
try {
5858
String tmpFileName = FilenameUtils.getName(new URL(Constants.LIBRARY_INDEX_URL_GZ).getPath());
5959
gzipTmpFile = File.createTempFile(tmpFileName, GzipUtils.getCompressedFilename(tmpFile.getName()));
6060
// remove eventual leftovers from previous downloads
6161
Files.deleteIfExists(gzipTmpFile.toPath());
6262

63-
new JsonDownloader(downloader, gzippedUrl).download(gzipTmpFile, progress, statusText, progressListener);
63+
new JsonDownloader(downloader, gzippedUrl).download(gzipTmpFile, progress, statusText, progressListener, allowCache);
6464
decompress(gzipTmpFile, tmpFile);
6565
} catch (Exception e) {
66-
new JsonDownloader(downloader, url).download(tmpFile, progress, statusText, progressListener);
66+
new JsonDownloader(downloader, url).download(tmpFile, progress, statusText, progressListener, allowCache);
6767
} finally {
6868
if (gzipTmpFile != null) {
6969
Files.deleteIfExists(gzipTmpFile.toPath());

Diff for: arduino-core/src/cc/arduino/contributions/JsonDownloader.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@ public JsonDownloader(DownloadableContributionsDownloader downloader, URL url) {
4444
this.url = url;
4545
}
4646

47-
public void download(File tmpFile, Progress progress, String statusText, ProgressListener progressListener) throws Exception {
47+
public void download(File tmpFile, Progress progress, String statusText, ProgressListener progressListener, boolean allowCache) throws Exception {
4848
try {
49-
downloader.download(url, tmpFile, progress, statusText, progressListener);
49+
downloader.download(url, tmpFile, progress, statusText, progressListener, allowCache);
5050
} catch (InterruptedException e) {
5151
// Download interrupted... just exit
5252
}

Diff for: arduino-core/src/cc/arduino/contributions/libraries/LibraryInstaller.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public synchronized void updateIndex(ProgressListener progressListener) throws E
7777
final String statusText = tr("Downloading libraries index...");
7878
try {
7979
GZippedJsonDownloader gZippedJsonDownloader = new GZippedJsonDownloader(downloader, libraryURL, new URL(Constants.LIBRARY_INDEX_URL_GZ));
80-
gZippedJsonDownloader.download(libraryIndexTemp, progress, statusText, progressListener);
80+
gZippedJsonDownloader.download(libraryIndexTemp, progress, statusText, progressListener, true);
8181
} catch (InterruptedException e) {
8282
// Download interrupted... just exit
8383
return;
@@ -118,7 +118,7 @@ public synchronized void install(ContributedLibrary lib, Optional<ContributedLib
118118

119119
// Step 1: Download library
120120
try {
121-
downloader.download(lib, progress, I18n.format(tr("Downloading library: {0}"), lib.getName()), progressListener);
121+
downloader.download(lib, progress, I18n.format(tr("Downloading library: {0}"), lib.getName()), progressListener, false);
122122
} catch (InterruptedException e) {
123123
// Download interrupted... just exit
124124
return;

Diff for: arduino-core/src/cc/arduino/contributions/packages/ContributionInstaller.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -102,15 +102,15 @@ public synchronized List<String> install(ContributedPlatform contributedPlatform
102102
// Download all
103103
try {
104104
// Download platform
105-
downloader.download(contributedPlatform, progress, tr("Downloading boards definitions."), progressListener);
105+
downloader.download(contributedPlatform, progress, tr("Downloading boards definitions."), progressListener, false);
106106
progress.stepDone();
107107

108108
// Download tools
109109
int i = 1;
110110
for (ContributedTool tool : tools) {
111111
String msg = format(tr("Downloading tools ({0}/{1})."), i, tools.size());
112112
i++;
113-
downloader.download(tool.getDownloadableContribution(platform), progress, msg, progressListener);
113+
downloader.download(tool.getDownloadableContribution(platform), progress, msg, progressListener, false);
114114
progress.stepDone();
115115
}
116116
} catch (InterruptedException e) {

Diff for: arduino-core/src/cc/arduino/utils/network/FileDownloader.java

+9-9
Original file line numberDiff line numberDiff line change
@@ -117,15 +117,12 @@ public void setStatus(Status status) {
117117
notifyObservers();
118118
}
119119

120-
public void download() throws InterruptedException {
121-
download(false);
122-
}
123120

124-
public void download(boolean noResume) throws InterruptedException {
121+
public void download(boolean noResume, boolean allowCache) throws InterruptedException {
125122
if ("file".equals(downloadUrl.getProtocol())) {
126123
saveLocalFile();
127124
} else {
128-
downloadFile(noResume);
125+
downloadFile(noResume, allowCache);
129126
}
130127
}
131128

@@ -139,7 +136,7 @@ private void saveLocalFile() {
139136
}
140137
}
141138

142-
private void downloadFile(boolean noResume) throws InterruptedException {
139+
private void downloadFile(boolean noResume, boolean allowCache) throws InterruptedException {
143140
RandomAccessFile randomAccessOutputFile = null;
144141

145142
try {
@@ -220,9 +217,12 @@ private void downloadFile(boolean noResume) throws InterruptedException {
220217
}
221218
// Set the cache whe it finish to download the file
222219
IOUtils.closeQuietly(randomAccessOutputFile);
223-
if (fileCached.isPresent()) {
220+
if (fileCached.isPresent() && allowCache) {
224221
fileCached.get().updateCacheFile(outputFile);
225222
}
223+
if (!allowCache) {
224+
log.info("The file {} was not cached because allow cache is false", downloadUrl);
225+
}
226226
setStatus(Status.COMPLETE);
227227
} catch (InterruptedException e) {
228228
setStatus(Status.CANCELLED);
@@ -232,12 +232,12 @@ private void downloadFile(boolean noResume) throws InterruptedException {
232232
} catch (SocketTimeoutException e) {
233233
setStatus(Status.CONNECTION_TIMEOUT_ERROR);
234234
setError(e);
235-
log.error(e);
235+
log.error("The request went in socket timeout", e);
236236

237237
} catch (Exception e) {
238238
setStatus(Status.ERROR);
239239
setError(e);
240-
log.error(e);
240+
log.error("The request stop", e);
241241

242242
} finally {
243243
IOUtils.closeQuietly(randomAccessOutputFile);

0 commit comments

Comments
 (0)