diff --git a/src/com/sheepit/client/Client.java b/src/com/sheepit/client/Client.java index d0bf1e3..2f4535d 100644 --- a/src/com/sheepit/client/Client.java +++ b/src/com/sheepit/client/Client.java @@ -577,15 +577,15 @@ public class Client { return Error.Type.OK; } - protected int downloadSceneFile(Job ajob_) { + protected int downloadSceneFile(Job ajob_) throws FermeExceptionNoSpaceLeftOnDevice { return this.downloadFile(ajob_, ajob_.getSceneArchivePath(), ajob_.getSceneMD5(), String.format("%s?type=job&job=%s&revision=%s", this.server.getPage("download-archive"), ajob_.getId(), ajob_.getRevision()), "project"); } - protected int downloadExecutable(Job ajob) { + protected int downloadExecutable(Job ajob) throws FermeExceptionNoSpaceLeftOnDevice { return this.downloadFile(ajob, ajob.getRendererArchivePath(), ajob.getRenderMd5(), String.format("%s?type=binary&job=%s", this.server.getPage("download-archive"), ajob.getId()), "renderer"); } - private int downloadFile(Job ajob, String local_path, String md5_server, String url, String download_type) { + private int downloadFile(Job ajob, String local_path, String md5_server, String url, String download_type) throws FermeExceptionNoSpaceLeftOnDevice { File local_path_file = new File(local_path); String update_ui = "Downloading " + download_type + " %s %%"; diff --git a/src/com/sheepit/client/Server.java b/src/com/sheepit/client/Server.java index 72159c9..f5dabb0 100644 --- a/src/com/sheepit/client/Server.java +++ b/src/com/sheepit/client/Server.java @@ -77,6 +77,7 @@ import com.sheepit.client.Error.ServerCode; import com.sheepit.client.exception.FermeException; import com.sheepit.client.exception.FermeExceptionNoRightToRender; import com.sheepit.client.exception.FermeExceptionNoSession; +import com.sheepit.client.exception.FermeExceptionNoSpaceLeftOnDevice; import com.sheepit.client.exception.FermeExceptionServerInMaintenance; import com.sheepit.client.exception.FermeExceptionServerOverloaded; import com.sheepit.client.exception.FermeExceptionSessionDisabled; @@ -536,7 +537,7 @@ public class Server extends Thread implements HostnameVerifier, X509TrustManager return connection; } - public int HTTPGetFile(String url_, String destination_, Gui gui_, String status_) { + public int HTTPGetFile(String url_, String destination_, Gui gui_, String status_) throws FermeExceptionNoSpaceLeftOnDevice { // the destination_ parent directory must exist try { HttpURLConnection httpCon = this.HTTPRequest(url_); @@ -570,6 +571,10 @@ public class Server extends Thread implements HostnameVerifier, X509TrustManager return 0; } catch (Exception e) { + if (Utils.noFreeSpaceOnDisk(destination_)) { + throw new FermeExceptionNoSpaceLeftOnDevice(); + } + StringWriter sw = new StringWriter(); e.printStackTrace(new PrintWriter(sw)); this.log.error("Server::HTTPGetFile exception " + e + " stacktrace " + sw.toString()); diff --git a/src/com/sheepit/client/Utils.java b/src/com/sheepit/client/Utils.java index 1a03efa..5e0e12e 100644 --- a/src/com/sheepit/client/Utils.java +++ b/src/com/sheepit/client/Utils.java @@ -80,10 +80,10 @@ public class Utils { fos.close(); } catch (IOException e) { - File f = new File(jiniHomeParentDirName_); - if (f.getUsableSpace() == 0) { + if (noFreeSpaceOnDisk(jiniHomeParentDirName_)) { throw new FermeExceptionNoSpaceLeftOnDevice(); } + Log logger = Log.getInstance(null); // might not print the log since the config is null logger.error("Utils::unzipFileIntoDirectory(" + zipFileName_ + "," + jiniHomeParentDirName_ + ") exception " + e); return -3; @@ -239,4 +239,15 @@ public class Utils { } return output; } + + public static boolean noFreeSpaceOnDisk(String destination_) { + try { + File file = new File(destination_); + return (file.getUsableSpace() < 512 * 1024); // at least the same amount as Server.HTTPGetFile + } + catch (SecurityException e) { + } + + return false; + } }