mirror of
https://github.com/arduino/Arduino.git
synced 2024-11-29 10:24:12 +01:00
File.deleteOnExit is not recursive. Replaced by DeleteFilesOnShutdown shutdown hook. Fixes #2971
This commit is contained in:
parent
e7dc30dae4
commit
3465fcf97b
@ -32,6 +32,7 @@ import cc.arduino.contributions.packages.ContributionInstaller;
|
||||
import cc.arduino.contributions.packages.ContributionsIndexer;
|
||||
import cc.arduino.contributions.DownloadableContributionVersionComparator;
|
||||
import cc.arduino.contributions.packages.ui.ContributionManagerUI;
|
||||
import cc.arduino.files.DeleteFilesOnShutdown;
|
||||
import cc.arduino.packages.DiscoveryManager;
|
||||
import cc.arduino.utils.Progress;
|
||||
import cc.arduino.view.SplashScreenHelper;
|
||||
@ -127,6 +128,8 @@ public class Base {
|
||||
}
|
||||
|
||||
static public void guardedMain(String args[]) throws Exception {
|
||||
Runtime.getRuntime().addShutdownHook(new Thread(DeleteFilesOnShutdown.INSTANCE));
|
||||
|
||||
BaseNoGui.initLogger();
|
||||
|
||||
BaseNoGui.notifier = new GUIUserNotifier();
|
||||
@ -202,7 +205,7 @@ public class Base {
|
||||
|
||||
// Create a location for untitled sketches
|
||||
untitledFolder = createTempFolder("untitled");
|
||||
untitledFolder.deleteOnExit();
|
||||
DeleteFilesOnShutdown.add(untitledFolder);
|
||||
|
||||
new Base(args);
|
||||
}
|
||||
|
@ -1,5 +1,7 @@
|
||||
package processing.app;
|
||||
|
||||
import cc.arduino.files.DeleteFilesOnShutdown;
|
||||
|
||||
import static processing.app.I18n._;
|
||||
|
||||
import java.io.File;
|
||||
@ -33,19 +35,19 @@ class EditorConsoleStream extends OutputStream {
|
||||
// The files and folders are not deleted on exit because they may be
|
||||
// needed for debugging or bug reporting.
|
||||
tempFolder = Base.createTempFolder("console");
|
||||
tempFolder.deleteOnExit();
|
||||
DeleteFilesOnShutdown.add(tempFolder);
|
||||
try {
|
||||
String outFileName = Preferences.get("console.output.file");
|
||||
if (outFileName != null) {
|
||||
outFile = new File(tempFolder, outFileName);
|
||||
outFile.deleteOnExit();
|
||||
DeleteFilesOnShutdown.add(outFile);
|
||||
stdoutFile = new FileOutputStream(outFile);
|
||||
}
|
||||
|
||||
String errFileName = Preferences.get("console.error.file");
|
||||
if (errFileName != null) {
|
||||
errFile = new File(tempFolder, errFileName);
|
||||
errFile.deleteOnExit();
|
||||
DeleteFilesOnShutdown.add(errFile);
|
||||
stderrFile = new FileOutputStream(errFile);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
|
@ -6,6 +6,7 @@ import org.fest.swing.edt.GuiQuery;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import processing.app.helpers.ArduinoFrameFixture;
|
||||
import processing.app.helpers.FileUtils;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
@ -25,7 +26,6 @@ public abstract class AbstractGUITest {
|
||||
Theme.init();
|
||||
Base.getPlatform().setLookAndFeel();
|
||||
Base.untitledFolder = Base.createTempFolder("untitled");
|
||||
Base.untitledFolder.deleteOnExit();
|
||||
|
||||
window = GuiActionRunner.execute(new GuiQuery<ArduinoFrameFixture>() {
|
||||
@Override
|
||||
@ -38,6 +38,7 @@ public abstract class AbstractGUITest {
|
||||
@After
|
||||
public void stopTheIDE() {
|
||||
window.cleanUp();
|
||||
FileUtils.recursiveDelete(Base.untitledFolder);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,6 +1,8 @@
|
||||
package processing.app;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import processing.app.helpers.FileUtils;
|
||||
|
||||
public abstract class AbstractWithPreferencesTest {
|
||||
|
||||
@ -11,7 +13,11 @@ public abstract class AbstractWithPreferencesTest {
|
||||
Theme.init();
|
||||
|
||||
Base.untitledFolder = Base.createTempFolder("untitled");
|
||||
Base.untitledFolder.deleteOnExit();
|
||||
|
||||
}
|
||||
|
||||
@After
|
||||
public void cleanup() {
|
||||
FileUtils.recursiveDelete(Base.untitledFolder);
|
||||
}
|
||||
}
|
||||
|
42
arduino-core/src/cc/arduino/files/DeleteFilesOnShutdown.java
Normal file
42
arduino-core/src/cc/arduino/files/DeleteFilesOnShutdown.java
Normal file
@ -0,0 +1,42 @@
|
||||
package cc.arduino.files;
|
||||
|
||||
import processing.app.helpers.FileUtils;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
public class DeleteFilesOnShutdown implements Runnable {
|
||||
|
||||
public static final DeleteFilesOnShutdown INSTANCE = new DeleteFilesOnShutdown();
|
||||
|
||||
public static void add(File file) {
|
||||
INSTANCE.addFile(file);
|
||||
}
|
||||
|
||||
private final List<File> files;
|
||||
|
||||
public DeleteFilesOnShutdown() {
|
||||
this.files = new LinkedList<File>();
|
||||
}
|
||||
|
||||
public synchronized void addFile(File file) {
|
||||
this.files.add(file);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
List<File> copyOfFiles;
|
||||
synchronized (this) {
|
||||
copyOfFiles = new LinkedList<File>(files);
|
||||
}
|
||||
Collections.reverse(copyOfFiles);
|
||||
for (File file : copyOfFiles) {
|
||||
if (file.exists() && file.canWrite()) {
|
||||
FileUtils.recursiveDelete(file);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,11 +1,11 @@
|
||||
package processing.app;
|
||||
|
||||
import cc.arduino.contributions.libraries.LibrariesIndexer;
|
||||
import cc.arduino.files.DeleteFilesOnShutdown;
|
||||
import cc.arduino.packages.DiscoveryManager;
|
||||
import cc.arduino.packages.Uploader;
|
||||
import cc.arduino.contributions.packages.ContributedTool;
|
||||
import cc.arduino.contributions.packages.ContributionsIndexer;
|
||||
import cc.arduino.utils.ArchiveExtractor;
|
||||
import org.apache.commons.logging.impl.LogFactoryImpl;
|
||||
import org.apache.commons.logging.impl.NoOpLog;
|
||||
import processing.app.debug.Compiler;
|
||||
@ -133,7 +133,7 @@ public class BaseNoGui {
|
||||
//File folder = new File(getTempFolder(), "build");
|
||||
//if (!folder.exists()) folder.mkdirs();
|
||||
buildFolder = createTempFolder("build");
|
||||
buildFolder.deleteOnExit();
|
||||
DeleteFilesOnShutdown.add(buildFolder);
|
||||
}
|
||||
}
|
||||
return buildFolder;
|
||||
@ -703,6 +703,8 @@ public class BaseNoGui {
|
||||
if (args.length == 0)
|
||||
showError(_("No parameters"), _("No command line parameters found"), null);
|
||||
|
||||
Runtime.getRuntime().addShutdownHook(new Thread(DeleteFilesOnShutdown.INSTANCE));
|
||||
|
||||
initPlatform();
|
||||
|
||||
initPortableFolder();
|
||||
|
Loading…
Reference in New Issue
Block a user