Add multiple tries for a failed free space check

as a workaround for the infamous "returns 0 sometimes on busy disk" java bug
This commit is contained in:
DaCool
2021-08-21 21:53:11 +00:00
parent a7d6742751
commit 3f718676a0

View File

@@ -204,9 +204,16 @@ public class Utils {
public static boolean noFreeSpaceOnDisk(String destination_) { public static boolean noFreeSpaceOnDisk(String destination_) {
try { try {
File file = new File(destination_); File file = new File(destination_);
return (file.getUsableSpace() < 512 * 1024); // at least the same amount as Server.HTTPGetFile for (int i = 0; i < 3; i++) { //We poll repeatedly because getUsableSpace() might just return 0 on busy disk IO
if (file.getUsableSpace() > 512 * 1024) { // at least the same amount as Server.HTTPGetFile
return false; // If we are not "full", we are done, no need for additional polling
} else if (i < 2) {
Thread.sleep((long) (Math.random() * (100 - 40 + 1) + 40)); //Wait between 40 and 100 milliseconds
} }
catch (SecurityException e) { }
return true;
}
catch (SecurityException | InterruptedException e) {
} }
return false; return false;