Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 9e5dc5c

Browse files
committed
2 parents dd95dd6 + 7949e7e commit 9e5dc5c

File tree

2 files changed

+17
-9
lines changed

2 files changed

+17
-9
lines changed

‎app/src/processing/app/Sketch.java‎

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
import cc.arduino.Compiler;
2727
import cc.arduino.CompilerProgressListener;
2828
import cc.arduino.UploaderUtils;
29-
import cc.arduino.files.DeleteFilesOnShutdown;
3029
import cc.arduino.packages.Uploader;
3130
import org.apache.commons.codec.digest.DigestUtils;
3231
import processing.app.debug.RunnerException;
@@ -463,7 +462,7 @@ public void handleDeleteCode() throws IOException {
463462

464463
} else {
465464
// 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())) {
467466
Base.showMessage(tr("Couldn't do it"),
468467
I18n.format(tr("Could not delete \"{0}\"."), current.getCode().getFileName()));
469468
return;
@@ -1100,17 +1099,27 @@ private String build(String buildPath, boolean verbose, boolean save) throws Run
11001099

11011100
CompilerProgressListener progressListener = editor.status::progressUpdate;
11021101

1102+
boolean deleteTemp = false;
11031103
String pathToSketch = data.getMainFilePath();
11041104
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.
11051107
pathToSketch = saveSketchInTempFolder();
1108+
deleteTemp = true;
11061109
}
11071110

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+
}
11091119
}
11101120

11111121
private String saveSketchInTempFolder() throws IOException {
1112-
File tempFolder = FileUtils.createTempFolder("arduino_", DigestUtils.md5Hex(data.getMainFilePath()));
1113-
DeleteFilesOnShutdown.add(tempFolder);
1122+
File tempFolder = FileUtils.createTempFolder("arduino_modified_sketch_");
11141123
FileUtils.copy(getFolder(), tempFolder);
11151124

11161125
for (SketchCode sc : Stream.of(data.getCodes()).filter(SketchCode::isModified).collect(Collectors.toList())) {

‎arduino-core/src/processing/app/SketchCode.java‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,14 +91,13 @@ protected boolean fileReadOnly() {
9191
}
9292

9393

94-
protected boolean deleteFile(Path tempBuildFolder, PathtempUnsavedSketchPath) throws IOException {
94+
protected boolean deleteFile(Path tempBuildFolder) throws IOException {
9595
if (!file.delete()) {
9696
return false;
9797
}
9898

99-
List<Path> tempBuildFolders = Stream.of(tempBuildFolder, tempBuildFolder.resolve("sketch"), tempUnsavedSketchPath)
100-
.filter(path -> Files.exists(path))
101-
.collect(Collectors.toList());
99+
List<Path> tempBuildFolders = Stream.of(tempBuildFolder, tempBuildFolder.resolve("sketch"))
100+
.filter(path -> Files.exists(path)).collect(Collectors.toList());
102101

103102
for (Path folder : tempBuildFolders) {
104103
if (!deleteCompiledFilesFrom(folder)) {

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /