Merge branch 'fix/cache-dir' into 'master'

Fix: store the .zip and .wool on the same directory

See merge request sheepitrenderfarm/client!339
This commit is contained in:
Sheepit Renderfarm
2024-10-31 13:30:37 +00:00
4 changed files with 20 additions and 29 deletions

View File

@@ -44,6 +44,8 @@ import lombok.Data;
*/
@AllArgsConstructor
@Data public class Configuration {
public static final String WORKING_DIRNAME = "sheepit";
public static final String WOOL_CACHE_DIRNAME = "sheepit_wool_cache";
public static final String jarVersion = getJarVersion();
@@ -55,9 +57,8 @@ import lombok.Data;
private String logDirectory;
private File workingDirectory;
private File sharedDownloadsDirectory;
private File storageDirectory; // for permanent storage (binary archive)
private File woolCacheDirectory; // store all the chunks (and binary for now)
private boolean userHasSpecifiedACacheDir;
private String static_exeDirName;
private String login;
private String password;
private String proxy;
@@ -91,7 +92,6 @@ import lombok.Data;
this.password = password_;
this.proxy = null;
this.hostname = this.getDefaultHostname();
this.static_exeDirName = "exe";
this.maxUploadingJob = 1;
this.nbCores = -1; // ie not set
this.maxAllowedMemory = -1; // ie not set
@@ -103,7 +103,7 @@ import lombok.Data;
this.detectGPUs = true;
this.workingDirectory = null;
this.sharedDownloadsDirectory = null;
this.storageDirectory = null;
this.woolCacheDirectory = null;
this.setCacheDir(cache_dir_);
this.printLog = false;
this.debugLevel = false;
@@ -132,9 +132,8 @@ import lombok.Data;
c + "logDir: " + (logDirectory == null ? "NULL" : logDirectory) + n +
c + "workingDirectory: " + workingDirectory + n +
c + "sharedDownloadsDirectory: " + sharedDownloadsDirectory + n +
c + "storageDirectory: " + storageDirectory + n +
c + "woolCacheDirectory: " + woolCacheDirectory + n +
c + "userHasSpecifiedACacheDir: " + userHasSpecifiedACacheDir + n +
c + "static_exeDirName: " + static_exeDirName + n +
c + "login: " + login + n +
c + "proxy: " + proxy + n +
c + "maxUploadingJob: " + maxUploadingJob + n +
@@ -201,8 +200,8 @@ import lombok.Data;
// since there is no working directory and the client will be working in the system temp directory,
// we can also set up a 'permanent' directory for immutable files (like renderer binary)
this.storageDirectory = new File(this.workingDirectory.getParent() + File.separator + "sheepit_binary_cache");
this.storageDirectory.mkdir();
this.woolCacheDirectory = new File(this.workingDirectory.getParent() + File.separator + WOOL_CACHE_DIRNAME);
this.woolCacheDirectory.mkdir();
}
catch (IOException e) {
e.printStackTrace();
@@ -210,10 +209,10 @@ import lombok.Data;
}
else {
this.userHasSpecifiedACacheDir = true;
this.workingDirectory = new File(cache_dir_.getAbsolutePath() + File.separator + "sheepit");
this.storageDirectory = new File(cache_dir_.getAbsolutePath() + File.separator + "sheepit_binary_cache");
this.workingDirectory = new File(cache_dir_.getAbsolutePath() + File.separator + WORKING_DIRNAME);
this.woolCacheDirectory = new File(cache_dir_.getAbsolutePath() + File.separator + WOOL_CACHE_DIRNAME);
this.workingDirectory.mkdirs();
this.storageDirectory.mkdirs();
this.woolCacheDirectory.mkdirs();
}
if (this.sharedDownloadsDirectory != null) {
@@ -225,19 +224,12 @@ import lombok.Data;
}
}
/**
* @return the storage directory or the working directory if the former is not defined
*/
public File getStorageDir() {
return this.storageDirectory == null ? this.workingDirectory : this.storageDirectory;
}
/**
* @return the user specified cache directory or null if it hasn't been specified
*/
public File getCacheDirForSettings() {
// when the user has a cache directory specified,
// a "sheepit" and "sheepit_binary_cache" directory is to be automatically created
// a "sheepit" and "wool_cache" directory is to be automatically created
return this.userHasSpecifiedACacheDir == false ? null : this.workingDirectory.getParentFile();
}
@@ -258,7 +250,7 @@ import lombok.Data;
*/
public void cleanWorkingDirectory() {
this.cleanDirectory(this.workingDirectory);
this.cleanDirectory(this.storageDirectory);
this.cleanDirectory(this.woolCacheDirectory);
}
/**
@@ -329,8 +321,8 @@ import lombok.Data;
files.addAll(Arrays.asList(filesInDirectory));
}
}
if (this.storageDirectory != null) {
File[] filesInDirectory = this.storageDirectory.listFiles();
if (this.woolCacheDirectory != null) {
File[] filesInDirectory = this.woolCacheDirectory.listFiles();
if (filesInDirectory != null) {
files.addAll(Arrays.asList(filesInDirectory));
}
@@ -379,8 +371,8 @@ import lombok.Data;
if (sharedDownloadsDirectory != null && dirsToCheck.contains(sharedDownloadsDirectory.getAbsoluteFile()) == false) {
dirsToCheck.add(sharedDownloadsDirectory.getAbsoluteFile());
}
if (storageDirectory != null && dirsToCheck.contains(storageDirectory.getAbsoluteFile()) == false) {
dirsToCheck.add(storageDirectory.getAbsoluteFile());
if (woolCacheDirectory != null && dirsToCheck.contains(woolCacheDirectory.getAbsoluteFile()) == false) {
dirsToCheck.add(woolCacheDirectory.getAbsoluteFile());
}
ListIterator<File> dirs = dirsToCheck.listIterator();
while (dirs.hasNext()) {

View File

@@ -44,7 +44,7 @@ public class DirectoryManager {
}
public String getCachePathFor(Chunk chunk) {
return configuration.getWorkingDirectory().getAbsolutePath() + File.separator + chunk.getId() + ".wool";
return configuration.getWoolCacheDirectory().getAbsolutePath() + File.separator + chunk.getId() + ".wool";
}
public String getSharedPathFor(Chunk chunk) {
@@ -52,7 +52,7 @@ public class DirectoryManager {
}
public String getCacheBinaryPathFor(Job job) {
return configuration.getStorageDir().getAbsolutePath() + File.separator + job.getRendererMD5() + ".zip";
return configuration.getWoolCacheDirectory().getAbsolutePath() + File.separator + job.getRendererMD5() + ".zip";
}
public String getSharedBinaryPathFor(Job job) {

View File

@@ -719,8 +719,7 @@ public class Server extends Thread {
for (FileMD5 fileMD5 : fileMD5s) {
if ("delete".equals(fileMD5.getAction()) && fileMD5.getMd5() != null && fileMD5.getMd5().isEmpty() == false) {
List<String> paths = new ArrayList<>();
paths.add(this.user_config.getStorageDirectory().getAbsolutePath() + File.separator + fileMD5.getMd5()); //also delete in binary cache
paths.add(this.user_config.getWorkingDirectory().getAbsolutePath() + File.separator + fileMD5.getMd5());
paths.add(this.user_config.getWoolCacheDirectory().getAbsolutePath() + File.separator + fileMD5.getMd5());
// If we are using a shared downloads directory, then delete the file from the shared downloads directory as well :)
if (this.user_config.getSharedDownloadsDirectory() != null) {

View File

@@ -704,7 +704,7 @@ public class Settings implements Activity {
config.setTheme(themeOptionsGroup.getSelection().getActionCommand());
if (cacheDir != null) {
File fromConfig = config.getStorageDir();
File fromConfig = config.getWorkingDirectory();
if (fromConfig != null && fromConfig.getAbsolutePath().equals(cacheDir.getAbsolutePath()) == false) {
config.setCacheDir(cacheDir);
}