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
This commit is contained in:
Cristian Maglie 2016-08-11 13:39:56 +02:00
parent b1f9164c4c
commit d8470e59f4
2 changed files with 15 additions and 6 deletions

View File

@ -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);

View File

@ -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) {