diff --git a/arduino-core/src/cc/arduino/contributions/DownloadableContributionsDownloader.java b/arduino-core/src/cc/arduino/contributions/DownloadableContributionsDownloader.java index 170c5c6da6d..b4b7d5ca354 100644 --- a/arduino-core/src/cc/arduino/contributions/DownloadableContributionsDownloader.java +++ b/arduino-core/src/cc/arduino/contributions/DownloadableContributionsDownloader.java @@ -56,11 +56,11 @@ public DownloadableContributionsDownloader(File _stagingFolder) { 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 File download(DownloadableContribution contribution, Progress progress, f 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 @@ private boolean hasChecksum(DownloadableContribution contribution) { 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 void download(URL url, File tmpFile, Progress progress, String statusText 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 void downloadIndexAndSignature(MultiStepProgress progress, URL packageInd 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 010a0a86353..8a717dcf26c 100644 --- a/arduino-core/src/cc/arduino/contributions/GZippedJsonDownloader.java +++ b/arduino-core/src/cc/arduino/contributions/GZippedJsonDownloader.java @@ -52,7 +52,7 @@ public GZippedJsonDownloader(DownloadableContributionsDownloader downloader, URL 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 void download(File tmpFile, Progress progress, String statusText, Progres // 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 88f9e7783f1..5b932d08064 100644 --- a/arduino-core/src/cc/arduino/contributions/JsonDownloader.java +++ b/arduino-core/src/cc/arduino/contributions/JsonDownloader.java @@ -44,9 +44,9 @@ public JsonDownloader(DownloadableContributionsDownloader downloader, URL url) { 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 a9722c2cacf..cbab19c896c 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 synchronized void updateIndex(ProgressListener progressListener) throws E 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 synchronized void install(ContributedLibrary lib, Optional install(ContributedPlatform contributedPlatform // 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 synchronized List install(ContributedPlatform contributedPlatform 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 0b5f14aec51..f78e1e1d53e 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 void setStatus(Status status) { 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 @@ private void saveLocalFile() { } } - private void downloadFile(boolean noResume) throws InterruptedException { + private void downloadFile(boolean noResume, boolean allowCache) throws InterruptedException { RandomAccessFile randomAccessOutputFile = null; try { @@ -220,9 +217,12 @@ private void downloadFile(boolean noResume) throws InterruptedException { } // 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 @@ private void downloadFile(boolean noResume) throws InterruptedException { } 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);