From c0ac0e46403cca39ef09f05bf11ffcd5f66cc41b Mon Sep 17 00:00:00 2001 From: DaCoolX Date: Fri, 1 Oct 2021 16:00:46 +0200 Subject: [PATCH] Add debug log for not enough free space check --- src/com/sheepit/client/Server.java | 2 +- src/com/sheepit/client/Utils.java | 9 ++++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/com/sheepit/client/Server.java b/src/com/sheepit/client/Server.java index cd28438..11c2d14 100644 --- a/src/com/sheepit/client/Server.java +++ b/src/com/sheepit/client/Server.java @@ -462,7 +462,7 @@ public class Server extends Thread { return Error.Type.OK; } catch (Exception e) { - if (Utils.noFreeSpaceOnDisk(new File(destination_).getParent())) { + if (Utils.noFreeSpaceOnDisk(new File(destination_).getParent(), log)) { throw new FermeExceptionNoSpaceLeftOnDevice(); } diff --git a/src/com/sheepit/client/Utils.java b/src/com/sheepit/client/Utils.java index 12defd0..27ceb84 100644 --- a/src/com/sheepit/client/Utils.java +++ b/src/com/sheepit/client/Utils.java @@ -201,14 +201,17 @@ public class Utils { return output; } - public static boolean noFreeSpaceOnDisk(String destination_) { + public static boolean noFreeSpaceOnDisk(String destination_, Log log) { try { File file = new File(destination_); 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 + long space = file.getUsableSpace(); + if (space > 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 + long time = (long) (Math.random() * (100 - 40 + 1) + 40); //Wait between 40 and 100 milliseconds + log.debug("Utils::Not enough free disk space(" + space + ") encountered on try " + i + ", waiting " + time + "ms"); + Thread.sleep(time); } } return true;