From d8470e59f4f3cd66a7d050d28cd154ace92fb687 Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Thu, 11 Aug 2016 13:39:56 +0200 Subject: [PATCH] Mark built-in tools as readonly and do not remove them when uninstalling This covers a very convoluted use-case that may be reproduce this way: 1. Using an previous version of the IDE, a new AVR core is installed using the board manager. 2. The IDE is then updated so the core installed in 1. is now also the bundled one 3. The AVR core installed 1. is now removed using the board manager 4. The board manager will uninstall the (presumably) no longer used tools, from the built-in folder leaving, in fact, the IDE without the bundled tools that are supposed to be read-only. This commit fix this bug by actually making the built-in tool read-only --- .../packages/ContributionInstaller.java | 9 +++++++-- .../contributions/packages/ContributionsIndexer.java | 12 ++++++++---- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/arduino-core/src/cc/arduino/contributions/packages/ContributionInstaller.java b/arduino-core/src/cc/arduino/contributions/packages/ContributionInstaller.java index 47f895be6..28c3e0722 100644 --- a/arduino-core/src/cc/arduino/contributions/packages/ContributionInstaller.java +++ b/arduino-core/src/cc/arduino/contributions/packages/ContributionInstaller.java @@ -249,11 +249,16 @@ public class ContributionInstaller { // Check if the tools are no longer needed for (ContributedTool tool : contributedPlatform.getResolvedTools()) { - if (BaseNoGui.indexer.isContributedToolUsed(contributedPlatform, tool)) { + // Do not remove used tools + if (BaseNoGui.indexer.isContributedToolUsed(contributedPlatform, tool)) continue; - } + // Do not remove built-in tools DownloadableContribution toolContrib = tool.getDownloadableContribution(platform); + if (toolContrib.isReadOnly()) + continue; + + // Ok, delete the tool File destFolder = toolContrib.getInstalledFolder(); FileUtils.recursiveDelete(destFolder); toolContrib.setInstalled(false); diff --git a/arduino-core/src/cc/arduino/contributions/packages/ContributionsIndexer.java b/arduino-core/src/cc/arduino/contributions/packages/ContributionsIndexer.java index 13ed66a26..0e6d03794 100644 --- a/arduino-core/src/cc/arduino/contributions/packages/ContributionsIndexer.java +++ b/arduino-core/src/cc/arduino/contributions/packages/ContributionsIndexer.java @@ -233,7 +233,9 @@ public class ContributionsIndexer { PreferencesMap toolsVersion = new PreferencesMap(versionsFile).subTree(pack.getName()); for (String name : toolsVersion.keySet()) { String version = toolsVersion.get(name); - syncToolWithFilesystem(pack, toolFolder, name, version); + DownloadableContribution tool = syncToolWithFilesystem(pack, toolFolder, name, version); + if (tool != null) + tool.setReadOnly(true); } } } @@ -292,21 +294,23 @@ public class ContributionsIndexer { } } - private void syncToolWithFilesystem(ContributedPackage pack, File installationFolder, String toolName, String version) { + private DownloadableContribution syncToolWithFilesystem(ContributedPackage pack, File installationFolder, String toolName, String version) { ContributedTool tool = pack.findTool(toolName, version); if (tool == null) { tool = pack.findResolvedTool(toolName, version); } if (tool == null) { - return; + return null; } DownloadableContribution contrib = tool.getDownloadableContribution(platform); if (contrib == null) { System.err.println(tool + " seems to have no downloadable contributions for your operating system, but it is installed in\n" + installationFolder); - return; + return null; } contrib.setInstalled(true); contrib.setInstalledFolder(installationFolder); + contrib.setReadOnly(false); + return contrib; } private ContributedPlatform syncHardwareWithFilesystem(ContributedPackage pack, File installationFolder, String architecture, String version) {