Reject folder syncs outside of game-dir
This commit is contained in:
parent
c7aeef43dd
commit
31ae7a6d3a
1 changed files with 34 additions and 22 deletions
|
@ -31,6 +31,9 @@ import java.util.function.Consumer;
|
|||
import java.util.stream.Stream;
|
||||
|
||||
abstract public class DataExchange {
|
||||
private final Path GAME_FOLDER = FabricLoader.getInstance()
|
||||
.getGameDir()
|
||||
.normalize();
|
||||
public final static SyncFolderDescriptor SYNC_FOLDER = new SyncFolderDescriptor("BCLIB-SYNC", FabricLoader.getInstance()
|
||||
.getGameDir()
|
||||
.resolve("bclib-sync")
|
||||
|
@ -183,7 +186,10 @@ abstract public class DataExchange {
|
|||
|
||||
//Note: make sure loadCache was called before using this
|
||||
boolean hasRelativeFile(String relFile) {
|
||||
return fileCache.stream().filter(sf -> sf.equals(relFile)).findFirst().isPresent();
|
||||
return fileCache.stream()
|
||||
.filter(sf -> sf.equals(relFile))
|
||||
.findFirst()
|
||||
.isPresent();
|
||||
}
|
||||
|
||||
//Note: make sure loadCache was called before using this
|
||||
|
@ -193,7 +199,10 @@ abstract public class DataExchange {
|
|||
|
||||
//Note: make sure loadCache was called before using this
|
||||
SubFile getLocalSubFile(String relPath) {
|
||||
return fileCache.stream().filter(sf -> sf.relPath.equals(relPath)).findFirst().orElse(null);
|
||||
return fileCache.stream()
|
||||
.filter(sf -> sf.relPath.equals(relPath))
|
||||
.findFirst()
|
||||
.orElse(null);
|
||||
}
|
||||
|
||||
Stream<SubFile> relativeFilesStream() {
|
||||
|
@ -202,11 +211,13 @@ abstract public class DataExchange {
|
|||
}
|
||||
|
||||
public Path mapAbsolute(String relPath) {
|
||||
return this.localFolder.resolve(relPath).normalize();
|
||||
return this.localFolder.resolve(relPath)
|
||||
.normalize();
|
||||
}
|
||||
|
||||
public Path mapAbsolute(SubFile subFile) {
|
||||
return this.localFolder.resolve(subFile.relPath).normalize();
|
||||
return this.localFolder.resolve(subFile.relPath)
|
||||
.normalize();
|
||||
}
|
||||
|
||||
public boolean acceptChildElements(Path absPath) {
|
||||
|
@ -280,12 +291,7 @@ abstract public class DataExchange {
|
|||
protected void initClientside() {
|
||||
if (client != null) return;
|
||||
client = clientSupplier(this);
|
||||
/*ClientLoginConnectionEvents.INIT.register((a, b) ->{
|
||||
System.out.println("INIT");
|
||||
});
|
||||
ClientLoginConnectionEvents.QUERY_START.register((a, b) ->{
|
||||
System.out.println("INIT");
|
||||
});*/
|
||||
|
||||
ClientPlayConnectionEvents.INIT.register(client::onPlayInit);
|
||||
ClientPlayConnectionEvents.JOIN.register(client::onPlayReady);
|
||||
ClientPlayConnectionEvents.DISCONNECT.register(client::onPlayDisconnect);
|
||||
|
@ -424,6 +430,8 @@ abstract public class DataExchange {
|
|||
}
|
||||
|
||||
protected void registerSyncFolder(String folderID, Path localBaseFolder, boolean removeAdditionalFiles) {
|
||||
localBaseFolder = localBaseFolder.normalize();
|
||||
if (PathUtil.isChildOf(GAME_FOLDER, localBaseFolder)) {
|
||||
final SyncFolderDescriptor desc = new SyncFolderDescriptor(folderID, localBaseFolder, removeAdditionalFiles);
|
||||
if (this.syncFolderDescriptions.contains(desc)) {
|
||||
BCLib.LOGGER.warning("Tried to override Folder Sync '" + folderID + "' again.");
|
||||
|
@ -432,6 +440,10 @@ abstract public class DataExchange {
|
|||
this.syncFolderDescriptions.add(desc);
|
||||
}
|
||||
}
|
||||
else {
|
||||
BCLib.LOGGER.error(localBaseFolder + " (from " + folderID + ") is outside the game directory " + GAME_FOLDER + ". Sync is not allowed.");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue