diff --git a/arduino-core/src/cc/arduino/contributions/DownloadableContributionsDownloader.java b/arduino-core/src/cc/arduino/contributions/DownloadableContributionsDownloader.java index 170c5c6da..b4b7d5ca3 100644 --- a/arduino-core/src/cc/arduino/contributions/DownloadableContributionsDownloader.java +++ b/arduino-core/src/cc/arduino/contributions/DownloadableContributionsDownloader.java @@ -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"); diff --git a/arduino-core/src/cc/arduino/contributions/GZippedJsonDownloader.java b/arduino-core/src/cc/arduino/contributions/GZippedJsonDownloader.java index 010a0a863..8a717dcf2 100644 --- a/arduino-core/src/cc/arduino/contributions/GZippedJsonDownloader.java +++ b/arduino-core/src/cc/arduino/contributions/GZippedJsonDownloader.java @@ -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()); diff --git a/arduino-core/src/cc/arduino/contributions/JsonDownloader.java b/arduino-core/src/cc/arduino/contributions/JsonDownloader.java index 88f9e7783..5b932d080 100644 --- a/arduino-core/src/cc/arduino/contributions/JsonDownloader.java +++ b/arduino-core/src/cc/arduino/contributions/JsonDownloader.java @@ -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 } diff --git a/arduino-core/src/cc/arduino/contributions/libraries/LibraryInstaller.java b/arduino-core/src/cc/arduino/contributions/libraries/LibraryInstaller.java index a9722c2ca..cbab19c89 100644 --- a/arduino-core/src/cc/arduino/contributions/libraries/LibraryInstaller.java +++ b/arduino-core/src/cc/arduino/contributions/libraries/LibraryInstaller.java @@ -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; diff --git a/arduino-core/src/cc/arduino/contributions/packages/ContributionInstaller.java b/arduino-core/src/cc/arduino/contributions/packages/ContributionInstaller.java index a8bf08f09..ddcfeea57 100644 --- a/arduino-core/src/cc/arduino/contributions/packages/ContributionInstaller.java +++ b/arduino-core/src/cc/arduino/contributions/packages/ContributionInstaller.java @@ -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) { diff --git a/arduino-core/src/cc/arduino/utils/network/FileDownloader.java b/arduino-core/src/cc/arduino/utils/network/FileDownloader.java index 0b5f14aec..f78e1e1d5 100644 --- a/arduino-core/src/cc/arduino/utils/network/FileDownloader.java +++ b/arduino-core/src/cc/arduino/utils/network/FileDownloader.java @@ -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);