Skip to content

Commit 4cf77cd

Browse files
author
Federico Fissore
committed
If previously downloaded package_index.json is older than the bundled one, the bundled one wins
1 parent 2f31b8a commit 4cf77cd

File tree

1 file changed

+14
-16
lines changed

1 file changed

+14
-16
lines changed

arduino-core/src/processing/app/BaseNoGui.java

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
package processing.app;
22

33
import cc.arduino.contributions.libraries.LibrariesIndexer;
4+
import cc.arduino.contributions.packages.ContributedTool;
5+
import cc.arduino.contributions.packages.ContributionsIndexer;
46
import cc.arduino.files.DeleteFilesOnShutdown;
57
import cc.arduino.packages.DiscoveryManager;
68
import cc.arduino.packages.Uploader;
7-
import cc.arduino.contributions.packages.ContributedTool;
8-
import cc.arduino.contributions.packages.ContributionsIndexer;
99
import org.apache.commons.logging.impl.LogFactoryImpl;
1010
import org.apache.commons.logging.impl.NoOpLog;
1111
import processing.app.debug.Compiler;
@@ -578,21 +578,19 @@ static public void initLogger() {
578578
static public void initPackages() throws Exception {
579579
indexer = new ContributionsIndexer(BaseNoGui.getSettingsFolder());
580580
File indexFile = indexer.getIndexFile();
581-
if (!indexFile.isFile()) {
582-
File defaultPackageJsonFile = new File(getContentFile("dist"), "package_index.json");
583-
if (defaultPackageJsonFile.isFile()) {
584-
FileUtils.copyFile(defaultPackageJsonFile, indexFile);
585-
} else {
586-
// Otherwise create an empty packages index
587-
FileOutputStream out = null;
588-
try {
589-
out = new FileOutputStream(indexFile);
590-
out.write("{ \"packages\" : [ ] }".getBytes());
581+
File defaultPackageJsonFile = new File(getContentFile("dist"), "package_index.json");
582+
if (!indexFile.isFile() || (defaultPackageJsonFile.isFile() && defaultPackageJsonFile.lastModified() > indexFile.lastModified())) {
583+
FileUtils.copyFile(defaultPackageJsonFile, indexFile);
584+
} else if (!indexFile.isFile()) {
585+
// Otherwise create an empty packages index
586+
FileOutputStream out = null;
587+
try {
588+
out = new FileOutputStream(indexFile);
589+
out.write("{ \"packages\" : [ ] }".getBytes());
590+
out.close();
591+
} finally {
592+
if (out != null) {
591593
out.close();
592-
} finally {
593-
if (out != null) {
594-
out.close();
595-
}
596594
}
597595
}
598596
}

0 commit comments

Comments
 (0)