|
26 | 26 | import cc.arduino.Compiler; |
27 | 27 | import cc.arduino.CompilerProgressListener; |
28 | 28 | import cc.arduino.UploaderUtils; |
29 | | -import cc.arduino.files.DeleteFilesOnShutdown; |
30 | 29 | import cc.arduino.packages.Uploader; |
31 | 30 | import org.apache.commons.codec.digest.DigestUtils; |
32 | 31 | import processing.app.debug.RunnerException; |
@@ -463,7 +462,7 @@ public void handleDeleteCode() throws IOException { |
463 | 462 |
|
464 | 463 | } else { |
465 | 464 | // delete the file |
466 | | - if (!current.getCode().deleteFile(BaseNoGui.getBuildFolder(data).toPath(), Paths.get(System.getProperty("java.io.tmpdir"), "arduino_" + DigestUtils.md5Hex(getMainFilePath())))) { |
| 465 | + if (!current.getCode().deleteFile(BaseNoGui.getBuildFolder(data).toPath())) { |
467 | 466 | Base.showMessage(tr("Couldn't do it"), |
468 | 467 | I18n.format(tr("Could not delete \"{0}\"."), current.getCode().getFileName())); |
469 | 468 | return; |
@@ -1100,17 +1099,27 @@ private String build(String buildPath, boolean verbose, boolean save) throws Run |
1100 | 1099 |
|
1101 | 1100 | CompilerProgressListener progressListener = editor.status::progressUpdate; |
1102 | 1101 |
|
| 1102 | + boolean deleteTemp = false; |
1103 | 1103 | String pathToSketch = data.getMainFilePath(); |
1104 | 1104 | if (isModified()) { |
| 1105 | + // If any files are modified, make a copy of the sketch with the changes |
| 1106 | + // saved, so arduino-builder will see the modifications. |
1105 | 1107 | pathToSketch = saveSketchInTempFolder(); |
| 1108 | + deleteTemp = true; |
1106 | 1109 | } |
1107 | 1110 |
|
1108 | | - return new Compiler(pathToSketch, data, buildPath).build(progressListener, save); |
| 1111 | + try { |
| 1112 | + return new Compiler(pathToSketch, data, buildPath).build(progressListener, |
| 1113 | + save); |
| 1114 | + } finally { |
| 1115 | + // Make sure we clean up any temporary sketch copy |
| 1116 | + if (deleteTemp) |
| 1117 | + FileUtils.recursiveDelete(new File(pathToSketch).getParentFile()); |
| 1118 | + } |
1109 | 1119 | } |
1110 | 1120 |
|
1111 | 1121 | private String saveSketchInTempFolder() throws IOException { |
1112 | 1122 | File tempFolder = FileUtils.createTempFolder("arduino_", DigestUtils.md5Hex(data.getMainFilePath())); |
1113 | | - DeleteFilesOnShutdown.add(tempFolder); |
1114 | 1123 | FileUtils.copy(getFolder(), tempFolder); |
1115 | 1124 |
|
1116 | 1125 | for (SketchCode sc : Stream.of(data.getCodes()).filter(SketchCode::isModified).collect(Collectors.toList())) { |
|
0 commit comments