Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 14 additions & 5 deletions app/src/processing/app/Sketch.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import cc.arduino.Compiler;
import cc.arduino.CompilerProgressListener;
import cc.arduino.UploaderUtils;
import cc.arduino.files.DeleteFilesOnShutdown;
import cc.arduino.packages.Uploader;
import org.apache.commons.codec.digest.DigestUtils;
import processing.app.debug.RunnerException;
Expand Down Expand Up @@ -463,7 +462,7 @@ public void handleDeleteCode() throws IOException {

} else {
// delete the file
if (!current.getCode().deleteFile(BaseNoGui.getBuildFolder(data).toPath(), Paths.get(System.getProperty("java.io.tmpdir"), "arduino_" + DigestUtils.md5Hex(getMainFilePath())))) {
if (!current.getCode().deleteFile(BaseNoGui.getBuildFolder(data).toPath())) {
Base.showMessage(tr("Couldn't do it"),
I18n.format(tr("Could not delete \"{0}\"."), current.getCode().getFileName()));
return;
Expand Down Expand Up @@ -1100,17 +1099,27 @@ private String build(String buildPath, boolean verbose, boolean save) throws Run

CompilerProgressListener progressListener = editor.status::progressUpdate;

boolean deleteTemp = false;
String pathToSketch = data.getMainFilePath();
if (isModified()) {
// If any files are modified, make a copy of the sketch with the changes
// saved, so arduino-builder will see the modifications.
pathToSketch = saveSketchInTempFolder();
deleteTemp = true;
}

return new Compiler(pathToSketch, data, buildPath).build(progressListener, save);
try {
return new Compiler(pathToSketch, data, buildPath).build(progressListener,
save);
} finally {
// Make sure we clean up any temporary sketch copy
if (deleteTemp)
FileUtils.recursiveDelete(new File(pathToSketch).getParentFile());
}
}

private String saveSketchInTempFolder() throws IOException {
File tempFolder = FileUtils.createTempFolder("arduino_", DigestUtils.md5Hex(data.getMainFilePath()));
DeleteFilesOnShutdown.add(tempFolder);
File tempFolder = FileUtils.createTempFolder("arduino_modified_sketch_");
FileUtils.copy(getFolder(), tempFolder);

for (SketchCode sc : Stream.of(data.getCodes()).filter(SketchCode::isModified).collect(Collectors.toList())) {
Expand Down
7 changes: 3 additions & 4 deletions arduino-core/src/processing/app/SketchCode.java
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,13 @@ protected boolean fileReadOnly() {
}


protected boolean deleteFile(Path tempBuildFolder, Path tempUnsavedSketchPath) throws IOException {
protected boolean deleteFile(Path tempBuildFolder) throws IOException {
if (!file.delete()) {
return false;
}

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

for (Path folder : tempBuildFolders) {
if (!deleteCompiledFilesFrom(folder)) {
Expand Down