Introduce FSHealthCheck to run after a possibly-filesystem related error.

This commit is contained in:
DaCool
2023-01-06 14:43:14 +00:00
committed by Sheepit Renderfarm
parent 68ad00334e
commit 9eed45ef6e
3 changed files with 101 additions and 1 deletions

View File

@@ -26,10 +26,12 @@ import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.LinkedList;
import java.util.List;
import java.util.ListIterator;
import com.sheepit.client.hardware.cpu.CPU;
import com.sheepit.client.hardware.gpu.GPUDevice;
@@ -330,6 +332,65 @@ import lombok.Data;
return files_local;
}
/**
* Runs through all SheepIt related directories and checks if files and folders are all readable, writeable
* and in case of directories, checks if the contents can be listed and if usable space is enough.
* Only logs instances where something was detected, otherwise is it will only print "FilesystemHealthCheck started"
* @return an ArrayList of Strings containing all of the logs of the FSHealth check
*/
public ArrayList<String> filesystemHealthCheck() {
ArrayList<String> logs = new ArrayList<>();
String f = "FSHealth: ";
logs.add(f + "FilesystemHealthCheck started");
ArrayList<File> dirsToCheck = new ArrayList<>();
ArrayList<File> dirsChecked = new ArrayList<>();
dirsToCheck.add(workingDirectory.getAbsoluteFile());
if (sharedDownloadsDirectory != null && dirsToCheck.contains(sharedDownloadsDirectory.getAbsoluteFile()) == false) {
dirsToCheck.add(sharedDownloadsDirectory.getAbsoluteFile());
}
if (storageDirectory != null && dirsToCheck.contains(storageDirectory.getAbsoluteFile()) == false) {
dirsToCheck.add(storageDirectory.getAbsoluteFile());
}
ListIterator<File> dirs = dirsToCheck.listIterator();
while (dirs.hasNext()) {
File dir = dirs.next();
dirs.remove();
dirsChecked.add(dir);
File[] fileList = dir.listFiles();
if (fileList == null) {
logs.add(f + "File list of " + dir + " is null");
}
else {
for (File file : fileList) {
file = file.getAbsoluteFile();
//logs.add(f + file);
boolean canRead = file.canRead();
boolean canWrite = file.canWrite();
boolean isDir = file.isDirectory();
if (canRead == false) {
logs.add(f + "Can't read from " + file);
}
if (canWrite == false) {
logs.add(f + "Can't write to " + file);
}
if (canRead && canWrite && isDir) {
if (dirsChecked.contains(file)) {
logs.add(f + "Dir " + file + " already checked. Loop detected");
}
else {
dirs.add(file);
}
long usableSpace = file.getUsableSpace();
if (usableSpace < 512 * 1024) {
logs.add(f + "Usable space is " + usableSpace + " for " + file);
}
}
}
}
}
return logs;
}
private static String getJarVersion() {
String versionPath = "/VERSION";
String version = "6.0.0";