mirror of
https://github.com/arduino/Arduino.git
synced 2025-02-08 02:54:24 +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:
parent
dde5668b27
commit
a8c7184c11
@ -56,11 +56,11 @@ public class DownloadableContributionsDownloader {
|
|||||||
stagingFolder = _stagingFolder;
|
stagingFolder = _stagingFolder;
|
||||||
}
|
}
|
||||||
|
|
||||||
public File download(DownloadableContribution contribution, Progress progress, final String statusText, ProgressListener progressListener) throws Exception {
|
public File download(DownloadableContribution contribution, Progress progress, final String statusText, ProgressListener progressListener, boolean allowCache) throws Exception {
|
||||||
return download(contribution, progress, statusText, progressListener, false);
|
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());
|
URL url = new URL(contribution.getUrl());
|
||||||
Path outputFile = Paths.get(stagingFolder.getAbsolutePath(), contribution.getArchiveFileName());
|
Path outputFile = Paths.get(stagingFolder.getAbsolutePath(), contribution.getArchiveFileName());
|
||||||
|
|
||||||
@ -75,7 +75,7 @@ public class DownloadableContributionsDownloader {
|
|||||||
while (true) {
|
while (true) {
|
||||||
// Need to download or resume downloading?
|
// Need to download or resume downloading?
|
||||||
if (!Files.isRegularFile(outputFile, LinkOption.NOFOLLOW_LINKS) || (Files.size(outputFile) < contribution.getSize())) {
|
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;
|
downloaded = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -121,11 +121,11 @@ public class DownloadableContributionsDownloader {
|
|||||||
return algo != null && !algo.isEmpty();
|
return algo != null && !algo.isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void download(URL url, File tmpFile, Progress progress, String statusText, ProgressListener progressListener) throws Exception {
|
public void download(URL url, File tmpFile, Progress progress, String statusText, ProgressListener progressListener, boolean allowCache) throws Exception {
|
||||||
download(url, tmpFile, progress, statusText, progressListener, false);
|
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);
|
FileDownloader downloader = new FileDownloader(url, tmpFile);
|
||||||
downloader.addObserver((o, arg) -> {
|
downloader.addObserver((o, arg) -> {
|
||||||
FileDownloader me = (FileDownloader) o;
|
FileDownloader me = (FileDownloader) o;
|
||||||
@ -139,7 +139,7 @@ public class DownloadableContributionsDownloader {
|
|||||||
progress.setProgress(me.getProgress());
|
progress.setProgress(me.getProgress());
|
||||||
progressListener.onProgress(progress);
|
progressListener.onProgress(progress);
|
||||||
});
|
});
|
||||||
downloader.download(noResume);
|
downloader.download(noResume, allowCache);
|
||||||
if (!downloader.isCompleted()) {
|
if (!downloader.isCompleted()) {
|
||||||
throw new Exception(format(tr("Error downloading {0}"), url), downloader.getError());
|
throw new Exception(format(tr("Error downloading {0}"), url), downloader.getError());
|
||||||
}
|
}
|
||||||
@ -157,7 +157,7 @@ public class DownloadableContributionsDownloader {
|
|||||||
File packageIndexTemp = File.createTempFile(indexFileName, ".tmp");
|
File packageIndexTemp = File.createTempFile(indexFileName, ".tmp");
|
||||||
try {
|
try {
|
||||||
// Download package index
|
// Download package index
|
||||||
download(packageIndexUrl, packageIndexTemp, progress, statusText, progressListener, true);
|
download(packageIndexUrl, packageIndexTemp, progress, statusText, progressListener, true, true);
|
||||||
|
|
||||||
if (verifyDomain(packageIndexUrl)) {
|
if (verifyDomain(packageIndexUrl)) {
|
||||||
URL signatureUrl = new URL(packageIndexUrl.toString() + ".sig");
|
URL signatureUrl = new URL(packageIndexUrl.toString() + ".sig");
|
||||||
|
@ -52,7 +52,7 @@ public class GZippedJsonDownloader {
|
|||||||
this.gzippedUrl = gzippedUrl;
|
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;
|
File gzipTmpFile = null;
|
||||||
try {
|
try {
|
||||||
String tmpFileName = FilenameUtils.getName(new URL(Constants.LIBRARY_INDEX_URL_GZ).getPath());
|
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
|
// remove eventual leftovers from previous downloads
|
||||||
Files.deleteIfExists(gzipTmpFile.toPath());
|
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);
|
decompress(gzipTmpFile, tmpFile);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
new JsonDownloader(downloader, url).download(tmpFile, progress, statusText, progressListener);
|
new JsonDownloader(downloader, url).download(tmpFile, progress, statusText, progressListener, allowCache);
|
||||||
} finally {
|
} finally {
|
||||||
if (gzipTmpFile != null) {
|
if (gzipTmpFile != null) {
|
||||||
Files.deleteIfExists(gzipTmpFile.toPath());
|
Files.deleteIfExists(gzipTmpFile.toPath());
|
||||||
|
@ -44,9 +44,9 @@ public class JsonDownloader {
|
|||||||
this.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 {
|
try {
|
||||||
downloader.download(url, tmpFile, progress, statusText, progressListener);
|
downloader.download(url, tmpFile, progress, statusText, progressListener, allowCache);
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
// Download interrupted... just exit
|
// Download interrupted... just exit
|
||||||
}
|
}
|
||||||
|
@ -77,7 +77,7 @@ public class LibraryInstaller {
|
|||||||
final String statusText = tr("Downloading libraries index...");
|
final String statusText = tr("Downloading libraries index...");
|
||||||
try {
|
try {
|
||||||
GZippedJsonDownloader gZippedJsonDownloader = new GZippedJsonDownloader(downloader, libraryURL, new URL(Constants.LIBRARY_INDEX_URL_GZ));
|
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) {
|
} catch (InterruptedException e) {
|
||||||
// Download interrupted... just exit
|
// Download interrupted... just exit
|
||||||
return;
|
return;
|
||||||
@ -118,7 +118,7 @@ public class LibraryInstaller {
|
|||||||
|
|
||||||
// Step 1: Download library
|
// Step 1: Download library
|
||||||
try {
|
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) {
|
} catch (InterruptedException e) {
|
||||||
// Download interrupted... just exit
|
// Download interrupted... just exit
|
||||||
return;
|
return;
|
||||||
|
@ -102,7 +102,7 @@ public class ContributionInstaller {
|
|||||||
// Download all
|
// Download all
|
||||||
try {
|
try {
|
||||||
// Download platform
|
// Download platform
|
||||||
downloader.download(contributedPlatform, progress, tr("Downloading boards definitions."), progressListener);
|
downloader.download(contributedPlatform, progress, tr("Downloading boards definitions."), progressListener, false);
|
||||||
progress.stepDone();
|
progress.stepDone();
|
||||||
|
|
||||||
// Download tools
|
// Download tools
|
||||||
@ -110,7 +110,7 @@ public class ContributionInstaller {
|
|||||||
for (ContributedTool tool : tools) {
|
for (ContributedTool tool : tools) {
|
||||||
String msg = format(tr("Downloading tools ({0}/{1})."), i, tools.size());
|
String msg = format(tr("Downloading tools ({0}/{1})."), i, tools.size());
|
||||||
i++;
|
i++;
|
||||||
downloader.download(tool.getDownloadableContribution(platform), progress, msg, progressListener);
|
downloader.download(tool.getDownloadableContribution(platform), progress, msg, progressListener, false);
|
||||||
progress.stepDone();
|
progress.stepDone();
|
||||||
}
|
}
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
|
@ -117,15 +117,12 @@ public class FileDownloader extends Observable {
|
|||||||
notifyObservers();
|
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())) {
|
if ("file".equals(downloadUrl.getProtocol())) {
|
||||||
saveLocalFile();
|
saveLocalFile();
|
||||||
} else {
|
} 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;
|
RandomAccessFile randomAccessOutputFile = null;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@ -220,9 +217,12 @@ public class FileDownloader extends Observable {
|
|||||||
}
|
}
|
||||||
// Set the cache whe it finish to download the file
|
// Set the cache whe it finish to download the file
|
||||||
IOUtils.closeQuietly(randomAccessOutputFile);
|
IOUtils.closeQuietly(randomAccessOutputFile);
|
||||||
if (fileCached.isPresent()) {
|
if (fileCached.isPresent() && allowCache) {
|
||||||
fileCached.get().updateCacheFile(outputFile);
|
fileCached.get().updateCacheFile(outputFile);
|
||||||
}
|
}
|
||||||
|
if (!allowCache) {
|
||||||
|
log.info("The file {} was not cached because allow cache is false", downloadUrl);
|
||||||
|
}
|
||||||
setStatus(Status.COMPLETE);
|
setStatus(Status.COMPLETE);
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
setStatus(Status.CANCELLED);
|
setStatus(Status.CANCELLED);
|
||||||
@ -232,12 +232,12 @@ public class FileDownloader extends Observable {
|
|||||||
} catch (SocketTimeoutException e) {
|
} catch (SocketTimeoutException e) {
|
||||||
setStatus(Status.CONNECTION_TIMEOUT_ERROR);
|
setStatus(Status.CONNECTION_TIMEOUT_ERROR);
|
||||||
setError(e);
|
setError(e);
|
||||||
log.error(e);
|
log.error("The request went in socket timeout", e);
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
setStatus(Status.ERROR);
|
setStatus(Status.ERROR);
|
||||||
setError(e);
|
setError(e);
|
||||||
log.error(e);
|
log.error("The request stop", e);
|
||||||
|
|
||||||
} finally {
|
} finally {
|
||||||
IOUtils.closeQuietly(randomAccessOutputFile);
|
IOUtils.closeQuietly(randomAccessOutputFile);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user