Skip to content

Commit d8470e5

Browse files
committed
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
1 parent b1f9164 commit d8470e5

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

arduino-core/src/cc/arduino/contributions/packages/ContributionInstaller.java

+7-2
Original file line numberDiff line numberDiff line change
@@ -249,11 +249,16 @@ public synchronized List<String> remove(ContributedPlatform contributedPlatform)
249249

250250
// Check if the tools are no longer needed
251251
for (ContributedTool tool : contributedPlatform.getResolvedTools()) {
252-
if (BaseNoGui.indexer.isContributedToolUsed(contributedPlatform, tool)) {
252+
// Do not remove used tools
253+
if (BaseNoGui.indexer.isContributedToolUsed(contributedPlatform, tool))
253254
continue;
254-
}
255255

256+
// Do not remove built-in tools
256257
DownloadableContribution toolContrib = tool.getDownloadableContribution(platform);
258+
if (toolContrib.isReadOnly())
259+
continue;
260+
261+
// Ok, delete the tool
257262
File destFolder = toolContrib.getInstalledFolder();
258263
FileUtils.recursiveDelete(destFolder);
259264
toolContrib.setInstalled(false);

arduino-core/src/cc/arduino/contributions/packages/ContributionsIndexer.java

+8-4
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,9 @@ private void syncBuiltInHardware() throws IOException {
233233
PreferencesMap toolsVersion = new PreferencesMap(versionsFile).subTree(pack.getName());
234234
for (String name : toolsVersion.keySet()) {
235235
String version = toolsVersion.get(name);
236-
syncToolWithFilesystem(pack, toolFolder, name, version);
236+
DownloadableContribution tool = syncToolWithFilesystem(pack, toolFolder, name, version);
237+
if (tool != null)
238+
tool.setReadOnly(true);
237239
}
238240
}
239241
}
@@ -292,21 +294,23 @@ private void syncPackageWithFilesystem(ContributedPackage pack, File root) {
292294
}
293295
}
294296

295-
private void syncToolWithFilesystem(ContributedPackage pack, File installationFolder, String toolName, String version) {
297+
private DownloadableContribution syncToolWithFilesystem(ContributedPackage pack, File installationFolder, String toolName, String version) {
296298
ContributedTool tool = pack.findTool(toolName, version);
297299
if (tool == null) {
298300
tool = pack.findResolvedTool(toolName, version);
299301
}
300302
if (tool == null) {
301-
return;
303+
return null;
302304
}
303305
DownloadableContribution contrib = tool.getDownloadableContribution(platform);
304306
if (contrib == null) {
305307
System.err.println(tool + " seems to have no downloadable contributions for your operating system, but it is installed in\n" + installationFolder);
306-
return;
308+
return null;
307309
}
308310
contrib.setInstalled(true);
309311
contrib.setInstalledFolder(installationFolder);
312+
contrib.setReadOnly(false);
313+
return contrib;
310314
}
311315

312316
private ContributedPlatform syncHardwareWithFilesystem(ContributedPackage pack, File installationFolder, String architecture, String version) {

0 commit comments

Comments
 (0)