mirror of
https://github.com/arduino/Arduino.git
synced 2024-11-29 10:24:12 +01:00
Fixed a crashed when user attempted to delete a tab of a not yet compiled sketch. Fixes #3913
This commit is contained in:
parent
9af0eee338
commit
417857ee45
@ -26,8 +26,13 @@ import processing.app.helpers.FileUtils;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import static processing.app.I18n.tr;
|
||||
|
||||
@ -91,35 +96,39 @@ public class SketchCode {
|
||||
}
|
||||
|
||||
|
||||
protected boolean deleteFile(File tempBuildFolder) {
|
||||
protected boolean deleteFile(File tempBuildFolder) throws IOException {
|
||||
if (!file.delete()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!deleteCompiledFilesFrom(tempBuildFolder)) {
|
||||
return false;
|
||||
}
|
||||
List<Path> tempBuildFolders = Stream.of(tempBuildFolder.toPath(), Paths.get(tempBuildFolder.getAbsolutePath(), "sketch"))
|
||||
.filter(path -> Files.exists(path))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
if (!deleteCompiledFilesFrom(new File(tempBuildFolder, "sketch"))) {
|
||||
return false;
|
||||
for (Path folder : tempBuildFolders) {
|
||||
if (!deleteCompiledFilesFrom(folder)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean deleteCompiledFilesFrom(File tempBuildFolder) {
|
||||
File[] compiledFiles = tempBuildFolder.listFiles(pathname -> {
|
||||
return pathname.getName().startsWith(getFileName());
|
||||
});
|
||||
for (File compiledFile : compiledFiles) {
|
||||
if (!compiledFile.delete()) {
|
||||
private boolean deleteCompiledFilesFrom(Path tempBuildFolder) throws IOException {
|
||||
List<Path> compiledFiles = Files.list(tempBuildFolder)
|
||||
.filter(pathname -> pathname.getFileName().toString().startsWith(getFileName()))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
for (Path compiledFile : compiledFiles) {
|
||||
try {
|
||||
Files.delete(compiledFile);
|
||||
} catch (IOException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
protected boolean renameTo(File what) {
|
||||
boolean success = file.renameTo(what);
|
||||
if (success) {
|
||||
|
Loading…
Reference in New Issue
Block a user