1
0
mirror of https://github.com/arduino/Arduino.git synced 2025-01-31 20:52:13 +01:00

Do not cache the core or the library because are too big

and will be downloaded only one time
This commit is contained in:
Mattia Bertorello 2019-07-11 15:01:41 +02:00
parent dde5668b27
commit a8c7184c11
No known key found for this signature in database
GPG Key ID: CE1FB2BE91770F24
6 changed files with 27 additions and 27 deletions

View File

@ -56,11 +56,11 @@ public class DownloadableContributionsDownloader {
stagingFolder = _stagingFolder;
}
public File download(DownloadableContribution contribution, Progress progress, final String statusText, ProgressListener progressListener) throws Exception {
return download(contribution, progress, statusText, progressListener, false);
public File download(DownloadableContribution contribution, Progress progress, final String statusText, ProgressListener progressListener, boolean allowCache) throws Exception {
return download(contribution, progress, statusText, progressListener, false, allowCache);
}
public File download(DownloadableContribution contribution, Progress progress, final String statusText, ProgressListener progressListener, boolean noResume) throws Exception {
public File download(DownloadableContribution contribution, Progress progress, final String statusText, ProgressListener progressListener, boolean noResume, boolean allowCache) throws Exception {
URL url = new URL(contribution.getUrl());
Path outputFile = Paths.get(stagingFolder.getAbsolutePath(), contribution.getArchiveFileName());
@ -75,7 +75,7 @@ public class DownloadableContributionsDownloader {
while (true) {
// Need to download or resume downloading?
if (!Files.isRegularFile(outputFile, LinkOption.NOFOLLOW_LINKS) || (Files.size(outputFile) < contribution.getSize())) {
download(url, outputFile.toFile(), progress, statusText, progressListener, noResume);
download(url, outputFile.toFile(), progress, statusText, progressListener, noResume, allowCache);
downloaded = true;
}
@ -121,11 +121,11 @@ public class DownloadableContributionsDownloader {
return algo != null && !algo.isEmpty();
}
public void download(URL url, File tmpFile, Progress progress, String statusText, ProgressListener progressListener) throws Exception {
download(url, tmpFile, progress, statusText, progressListener, false);
public void download(URL url, File tmpFile, Progress progress, String statusText, ProgressListener progressListener, boolean allowCache) throws Exception {
download(url, tmpFile, progress, statusText, progressListener, false, allowCache);
}
public void download(URL url, File tmpFile, Progress progress, String statusText, ProgressListener progressListener, boolean noResume) throws Exception {
public void download(URL url, File tmpFile, Progress progress, String statusText, ProgressListener progressListener, boolean noResume, boolean allowCache) throws Exception {
FileDownloader downloader = new FileDownloader(url, tmpFile);
downloader.addObserver((o, arg) -> {
FileDownloader me = (FileDownloader) o;
@ -139,7 +139,7 @@ public class DownloadableContributionsDownloader {
progress.setProgress(me.getProgress());
progressListener.onProgress(progress);
});
downloader.download(noResume);
downloader.download(noResume, allowCache);
if (!downloader.isCompleted()) {
throw new Exception(format(tr("Error downloading {0}"), url), downloader.getError());
}
@ -157,7 +157,7 @@ public class DownloadableContributionsDownloader {
File packageIndexTemp = File.createTempFile(indexFileName, ".tmp");
try {
// Download package index
download(packageIndexUrl, packageIndexTemp, progress, statusText, progressListener, true);
download(packageIndexUrl, packageIndexTemp, progress, statusText, progressListener, true, true);
if (verifyDomain(packageIndexUrl)) {
URL signatureUrl = new URL(packageIndexUrl.toString() + ".sig");

View File

@ -52,7 +52,7 @@ public class GZippedJsonDownloader {
this.gzippedUrl = gzippedUrl;
}
public void download(File tmpFile, Progress progress, String statusText, ProgressListener progressListener) throws Exception {
public void download(File tmpFile, Progress progress, String statusText, ProgressListener progressListener, boolean allowCache) throws Exception {
File gzipTmpFile = null;
try {
String tmpFileName = FilenameUtils.getName(new URL(Constants.LIBRARY_INDEX_URL_GZ).getPath());
@ -60,10 +60,10 @@ public class GZippedJsonDownloader {
// remove eventual leftovers from previous downloads
Files.deleteIfExists(gzipTmpFile.toPath());
new JsonDownloader(downloader, gzippedUrl).download(gzipTmpFile, progress, statusText, progressListener);
new JsonDownloader(downloader, gzippedUrl).download(gzipTmpFile, progress, statusText, progressListener, allowCache);
decompress(gzipTmpFile, tmpFile);
} catch (Exception e) {
new JsonDownloader(downloader, url).download(tmpFile, progress, statusText, progressListener);
new JsonDownloader(downloader, url).download(tmpFile, progress, statusText, progressListener, allowCache);
} finally {
if (gzipTmpFile != null) {
Files.deleteIfExists(gzipTmpFile.toPath());

View File

@ -44,9 +44,9 @@ public class JsonDownloader {
this.url = url;
}
public void download(File tmpFile, Progress progress, String statusText, ProgressListener progressListener) throws Exception {
public void download(File tmpFile, Progress progress, String statusText, ProgressListener progressListener, boolean allowCache) throws Exception {
try {
downloader.download(url, tmpFile, progress, statusText, progressListener);
downloader.download(url, tmpFile, progress, statusText, progressListener, allowCache);
} catch (InterruptedException e) {
// Download interrupted... just exit
}

View File

@ -77,7 +77,7 @@ public class LibraryInstaller {
final String statusText = tr("Downloading libraries index...");
try {
GZippedJsonDownloader gZippedJsonDownloader = new GZippedJsonDownloader(downloader, libraryURL, new URL(Constants.LIBRARY_INDEX_URL_GZ));
gZippedJsonDownloader.download(libraryIndexTemp, progress, statusText, progressListener);
gZippedJsonDownloader.download(libraryIndexTemp, progress, statusText, progressListener, true);
} catch (InterruptedException e) {
// Download interrupted... just exit
return;
@ -118,7 +118,7 @@ public class LibraryInstaller {
// Step 1: Download library
try {
downloader.download(lib, progress, I18n.format(tr("Downloading library: {0}"), lib.getName()), progressListener);
downloader.download(lib, progress, I18n.format(tr("Downloading library: {0}"), lib.getName()), progressListener, false);
} catch (InterruptedException e) {
// Download interrupted... just exit
return;

View File

@ -102,7 +102,7 @@ public class ContributionInstaller {
// Download all
try {
// Download platform
downloader.download(contributedPlatform, progress, tr("Downloading boards definitions."), progressListener);
downloader.download(contributedPlatform, progress, tr("Downloading boards definitions."), progressListener, false);
progress.stepDone();
// Download tools
@ -110,7 +110,7 @@ public class ContributionInstaller {
for (ContributedTool tool : tools) {
String msg = format(tr("Downloading tools ({0}/{1})."), i, tools.size());
i++;
downloader.download(tool.getDownloadableContribution(platform), progress, msg, progressListener);
downloader.download(tool.getDownloadableContribution(platform), progress, msg, progressListener, false);
progress.stepDone();
}
} catch (InterruptedException e) {

View File

@ -117,15 +117,12 @@ public class FileDownloader extends Observable {
notifyObservers();
}
public void download() throws InterruptedException {
download(false);
}
public void download(boolean noResume) throws InterruptedException {
public void download(boolean noResume, boolean allowCache) throws InterruptedException {
if ("file".equals(downloadUrl.getProtocol())) {
saveLocalFile();
} else {
downloadFile(noResume);
downloadFile(noResume, allowCache);
}
}
@ -139,7 +136,7 @@ public class FileDownloader extends Observable {
}
}
private void downloadFile(boolean noResume) throws InterruptedException {
private void downloadFile(boolean noResume, boolean allowCache) throws InterruptedException {
RandomAccessFile randomAccessOutputFile = null;
try {
@ -220,9 +217,12 @@ public class FileDownloader extends Observable {
}
// Set the cache whe it finish to download the file
IOUtils.closeQuietly(randomAccessOutputFile);
if (fileCached.isPresent()) {
if (fileCached.isPresent() && allowCache) {
fileCached.get().updateCacheFile(outputFile);
}
if (!allowCache) {
log.info("The file {} was not cached because allow cache is false", downloadUrl);
}
setStatus(Status.COMPLETE);
} catch (InterruptedException e) {
setStatus(Status.CANCELLED);
@ -232,12 +232,12 @@ public class FileDownloader extends Observable {
} catch (SocketTimeoutException e) {
setStatus(Status.CONNECTION_TIMEOUT_ERROR);
setError(e);
log.error(e);
log.error("The request went in socket timeout", e);
} catch (Exception e) {
setStatus(Status.ERROR);
setError(e);
log.error(e);
log.error("The request stop", e);
} finally {
IOUtils.closeQuietly(randomAccessOutputFile);