Fix: really delete file
This commit is contained in:
@@ -1012,13 +1012,11 @@ import okhttp3.HttpUrl;
|
||||
}
|
||||
|
||||
// we can remove the frame file
|
||||
File frame = new File(ajob.getOutputImagePath());
|
||||
frame.delete();
|
||||
Utils.deleteFile(new File(ajob.getOutputImagePath()));
|
||||
ajob.setOutputImagePath(null);
|
||||
|
||||
if (ajob.getPreviewImagePath() != null) {
|
||||
frame = new File(ajob.getPreviewImagePath());
|
||||
frame.delete();
|
||||
Utils.deleteFile(new File(ajob.getPreviewImagePath()));
|
||||
ajob.setPreviewImagePath(null);
|
||||
}
|
||||
|
||||
|
||||
@@ -376,4 +376,25 @@ public class Utils {
|
||||
|
||||
return String.format("%.2f%s", (bytes / divider), suffix);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sometimes on Windows, delete of file return false for no obvious reason.
|
||||
* Wait a bit and try again
|
||||
*/
|
||||
public static boolean deleteFile(File file) {
|
||||
if (file.delete() == false) {
|
||||
// maybe the system was busy
|
||||
try {
|
||||
Thread.sleep(4000);
|
||||
}
|
||||
catch (InterruptedException e) {
|
||||
}
|
||||
System.gc();
|
||||
if (file.delete() == false) {
|
||||
file.deleteOnExit(); // nothing more can be done...
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user