Merge branch 'fix/park-client-on-cachedir-deleted' into 'master'

Fix/park client on cachedir deleted

See merge request sheepitrenderfarm/client!362
This commit is contained in:
Sheepit Renderfarm
2025-01-21 10:38:29 +00:00
5 changed files with 72 additions and 18 deletions

View File

@@ -18,11 +18,14 @@
*/
package com.sheepit.client.network;
import com.sheepit.client.config.DirectoryManager;
import com.sheepit.client.datamodel.client.Error;
import com.sheepit.client.exception.SheepItExceptionCacheDirDeleted;
import com.sheepit.client.ui.Gui;
import com.sheepit.client.logger.Log;
import com.sheepit.client.utils.Utils;
import com.sheepit.client.exception.SheepItException;
import lombok.AllArgsConstructor;
import java.io.File;
import java.io.IOException;
@@ -33,28 +36,20 @@ import java.nio.file.Path;
import java.util.Random;
import java.util.concurrent.TimeUnit;
public class DownloadManager {
@AllArgsConstructor public class DownloadManager {
private static int maxDownloadFileAttempts = 5;
// global objects
private ServerRequest serverRequest;
private Gui gui;
private Log log;
private DirectoryManager directoryManager;
// task specific objects
private String local_target;
private String md5; // expected md5 of the file, for check purpose
private String remote; // remote url
public DownloadManager(ServerRequest serverRequest, Gui gui, Log log, String local_target, String md5, String remote) {
this.serverRequest = serverRequest;
this.gui = gui;
this.log = log;
this.local_target = local_target;
this.md5 = md5;
this.remote = remote;
}
public Error.Type download() throws SheepItException {
File local_path_file = new File(this.local_target);
@@ -175,7 +170,7 @@ public class DownloadManager {
return new File(this.local_target + ".partial").exists();
}
private void createLock() {
private void createLock() throws SheepItExceptionCacheDirDeleted {
try {
File file = new File(this.local_target + ".partial");
file.createNewFile();
@@ -193,6 +188,16 @@ public class DownloadManager {
this.log.error("DownloadManager::createLock checking path info " + test_path + " exists? " + (new File(test_path).exists() ? "yes" : "no") + " is writeable? " + (Files.isWritable(Path.of(test_path)) ? "yes" : "no"));
current_path = test_path;
}
File cache_dir = new File(this.local_target).getParentFile();
if (cache_dir.exists() == false) {
this.log.error("DownloadManager::createLock cache-dir has been deleted, it should not happen, park the client");
// it shouldn't happen, the client need a cache dir
// 2 solutions: re-create the cache dir or park the client.
// we don't know why the cache dir was deleted so -> park the client
throw new SheepItExceptionCacheDirDeleted();
}
}
}