|
26 | 26 |
|
27 | 27 | import java.io.File;
|
28 | 28 | import java.io.IOException;
|
| 29 | +import java.nio.file.Files; |
| 30 | +import java.nio.file.Path; |
| 31 | +import java.nio.file.Paths; |
29 | 32 | import java.util.Arrays;
|
30 | 33 | import java.util.List;
|
| 34 | +import java.util.stream.Collectors; |
| 35 | +import java.util.stream.Stream; |
31 | 36 |
|
32 | 37 | import static processing.app.I18n.tr;
|
33 | 38 |
|
@@ -91,35 +96,39 @@ protected boolean fileReadOnly() {
|
91 | 96 | }
|
92 | 97 |
|
93 | 98 |
|
94 |
| - protected boolean deleteFile(File tempBuildFolder) { |
| 99 | + protected boolean deleteFile(File tempBuildFolder) throws IOException { |
95 | 100 | if (!file.delete()) {
|
96 | 101 | return false;
|
97 | 102 | }
|
98 | 103 |
|
99 |
| - if (!deleteCompiledFilesFrom(tempBuildFolder)) { |
100 |
| - return false; |
101 |
| - } |
| 104 | + List<Path> tempBuildFolders = Stream.of(tempBuildFolder.toPath(), Paths.get(tempBuildFolder.getAbsolutePath(), "sketch")) |
| 105 | + .filter(path -> Files.exists(path)) |
| 106 | + .collect(Collectors.toList()); |
102 | 107 |
|
103 |
| - if (!deleteCompiledFilesFrom(new File(tempBuildFolder, "sketch"))) { |
104 |
| - return false; |
| 108 | + for (Path folder : tempBuildFolders) { |
| 109 | + if (!deleteCompiledFilesFrom(folder)) { |
| 110 | + return false; |
| 111 | + } |
105 | 112 | }
|
106 | 113 |
|
107 | 114 | return true;
|
108 | 115 | }
|
109 | 116 |
|
110 |
| - private boolean deleteCompiledFilesFrom(File tempBuildFolder) { |
111 |
| - File[] compiledFiles = tempBuildFolder.listFiles(pathname -> { |
112 |
| - return pathname.getName().startsWith(getFileName()); |
113 |
| - }); |
114 |
| - for (File compiledFile : compiledFiles) { |
115 |
| - if (!compiledFile.delete()) { |
| 117 | + private boolean deleteCompiledFilesFrom(Path tempBuildFolder) throws IOException { |
| 118 | + List<Path> compiledFiles = Files.list(tempBuildFolder) |
| 119 | + .filter(pathname -> pathname.getFileName().toString().startsWith(getFileName())) |
| 120 | + .collect(Collectors.toList()); |
| 121 | + |
| 122 | + for (Path compiledFile : compiledFiles) { |
| 123 | + try { |
| 124 | + Files.delete(compiledFile); |
| 125 | + } catch (IOException e) { |
116 | 126 | return false;
|
117 | 127 | }
|
118 | 128 | }
|
119 | 129 | return true;
|
120 | 130 | }
|
121 | 131 |
|
122 |
| - |
123 | 132 | protected boolean renameTo(File what) {
|
124 | 133 | boolean success = file.renameTo(what);
|
125 | 134 | if (success) {
|
|
0 commit comments