Fix: really delete file

This commit is contained in:
Laurent Clouet
2024-02-28 11:31:23 +00:00
parent 23feca14d3
commit 4a9499d752
2 changed files with 23 additions and 4 deletions

View File

@@ -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);
}

View File

@@ -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;
}
}