mirror of
https://github.com/esp8266/Arduino.git
synced 2025-06-17 22:23:10 +03:00
File.deleteOnExit is not recursive. Replaced by DeleteFilesOnShutdown shutdown hook. Fixes #2971
This commit is contained in:
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user