forked from Qortal/qortal
Improved cache clearing process and logging.
This commit is contained in:
parent
85c61c1bc1
commit
6e91157dcf
@ -1,5 +1,7 @@
|
||||
package org.qortal.arbitrary;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.qortal.arbitrary.ArbitraryDataFile.ResourceIdType;
|
||||
import org.qortal.arbitrary.misc.Service;
|
||||
import org.qortal.controller.arbitrary.ArbitraryDataBuildManager;
|
||||
@ -25,6 +27,8 @@ import static org.qortal.data.arbitrary.ArbitraryResourceStatus.Status;
|
||||
|
||||
public class ArbitraryDataResource {
|
||||
|
||||
private static final Logger LOGGER = LogManager.getLogger(ArbitraryDataResource.class);
|
||||
|
||||
protected final String resourceId;
|
||||
protected final ResourceIdType resourceIdType;
|
||||
protected final Service service;
|
||||
@ -124,7 +128,10 @@ public class ArbitraryDataResource {
|
||||
String identifier = this.identifier != null ? this.identifier : "default";
|
||||
Path cachePath = Paths.get(baseDir, "reader", this.resourceIdType.toString(), this.resourceId, this.service.toString(), identifier);
|
||||
if (cachePath.toFile().exists()) {
|
||||
FilesystemUtils.safeDeleteDirectory(cachePath, true);
|
||||
boolean success = FilesystemUtils.safeDeleteDirectory(cachePath, true);
|
||||
if (success) {
|
||||
LOGGER.info("Cleared cache for resource {}", this.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -242,7 +242,7 @@ public class ArbitraryDataFileListManager {
|
||||
return ArbitraryDataFileManager.getInstance().fetchDataFilesFromPeersForSignature(signature);
|
||||
}
|
||||
|
||||
LOGGER.debug("Skipping file list request for signature {} due to rate limit", signature58);
|
||||
LOGGER.trace("Skipping file list request for signature {} due to rate limit", signature58);
|
||||
return false;
|
||||
}
|
||||
this.addToSignatureRequests(signature58, true, false);
|
||||
|
@ -338,7 +338,7 @@ public class ArbitraryDataManager extends Thread {
|
||||
ArbitraryDataResource resource =
|
||||
new ArbitraryDataResource(resourceId, ArbitraryDataFile.ResourceIdType.NAME, service, identifier);
|
||||
String key = resource.getUniqueKey();
|
||||
LOGGER.info("Clearing cache for {}...", resource);
|
||||
LOGGER.trace("Clearing cache for {}...", resource);
|
||||
|
||||
if (this.arbitraryDataCachedResources.containsKey(key)) {
|
||||
this.arbitraryDataCachedResources.remove(key);
|
||||
|
@ -150,17 +150,24 @@ public class FilesystemUtils {
|
||||
}
|
||||
}
|
||||
|
||||
public static void safeDeleteDirectory(Path path, boolean cleanup) throws IOException {
|
||||
public static boolean safeDeleteDirectory(Path path, boolean cleanup) throws IOException {
|
||||
boolean success = false;
|
||||
|
||||
// Delete path, if it exists in our data/temp directory
|
||||
if (FilesystemUtils.pathInsideDataOrTempPath(path)) {
|
||||
File directory = new File(path.toString());
|
||||
FileUtils.deleteDirectory(directory);
|
||||
if (Files.exists(path)) {
|
||||
File directory = new File(path.toString());
|
||||
FileUtils.deleteDirectory(directory);
|
||||
success = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (cleanup) {
|
||||
if (success && cleanup) {
|
||||
// Delete the parent directories if they are empty (and exist in our data/temp directory)
|
||||
FilesystemUtils.safeDeleteEmptyParentDirectories(path);
|
||||
}
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
public static void safeDeleteEmptyParentDirectories(Path path) throws IOException {
|
||||
|
Loading…
Reference in New Issue
Block a user