Maybe fix problems with symlinks (#956)

This commit is contained in:
Luck 2018-04-30 14:44:09 +01:00
parent 2e136666be
commit e3a783c546
No known key found for this signature in database
GPG Key ID: EFA9B3EC5FD90F8B
6 changed files with 20 additions and 9 deletions

View File

@ -33,6 +33,7 @@ import me.lucko.luckperms.common.dependencies.relocation.Relocation;
import me.lucko.luckperms.common.dependencies.relocation.RelocationHandler; import me.lucko.luckperms.common.dependencies.relocation.RelocationHandler;
import me.lucko.luckperms.common.plugin.LuckPermsPlugin; import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
import me.lucko.luckperms.common.storage.StorageType; import me.lucko.luckperms.common.storage.StorageType;
import me.lucko.luckperms.common.utils.MoreFiles;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
@ -82,7 +83,7 @@ public class DependencyManager {
private Path getSaveDirectory() { private Path getSaveDirectory() {
Path saveDirectory = this.plugin.getBootstrap().getDataDirectory().resolve("lib"); Path saveDirectory = this.plugin.getBootstrap().getDataDirectory().resolve("lib");
try { try {
Files.createDirectories(saveDirectory); MoreFiles.createDirectoriesIfNotExists(saveDirectory);
} catch (IOException e) { } catch (IOException e) {
throw new RuntimeException("Unable to create lib directory", e); throw new RuntimeException("Unable to create lib directory", e);
} }

View File

@ -57,7 +57,6 @@ import ninja.leaping.configurate.SimpleConfigurationNode;
import ninja.leaping.configurate.Types; import ninja.leaping.configurate.Types;
import java.io.IOException; import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
@ -132,7 +131,7 @@ public abstract class AbstractConfigurateDao extends AbstractDao {
@Override @Override
public void init() throws IOException { public void init() throws IOException {
this.dataDirectory = this.plugin.getBootstrap().getDataDirectory().resolve(this.dataDirectoryName); this.dataDirectory = this.plugin.getBootstrap().getDataDirectory().resolve(this.dataDirectoryName);
Files.createDirectories(this.dataDirectory); MoreFiles.createDirectoriesIfNotExists(this.dataDirectory);
this.uuidDataFile = MoreFiles.createFileIfNotExists(this.dataDirectory.resolve("uuidcache.txt")); this.uuidDataFile = MoreFiles.createFileIfNotExists(this.dataDirectory.resolve("uuidcache.txt"));
this.uuidCache.load(this.uuidDataFile); this.uuidCache.load(this.uuidDataFile);

View File

@ -39,7 +39,7 @@ public final class MoreFiles {
} }
public static Path createDirectoryIfNotExists(Path path) throws IOException { public static Path createDirectoryIfNotExists(Path path) throws IOException {
if (Files.exists(path) && Files.isDirectory(path)) { if (Files.exists(path) && (Files.isDirectory(path) || Files.isSymbolicLink(path))) {
return path; return path;
} }
@ -47,5 +47,14 @@ public final class MoreFiles {
return path; return path;
} }
public static Path createDirectoriesIfNotExists(Path path) throws IOException {
if (Files.exists(path) && (Files.isDirectory(path) || Files.isSymbolicLink(path))) {
return path;
}
Files.createDirectories(path);
return path;
}
private MoreFiles() {} private MoreFiles() {}
} }

View File

@ -32,6 +32,7 @@ import me.lucko.luckperms.common.dependencies.classloader.PluginClassLoader;
import me.lucko.luckperms.common.dependencies.classloader.ReflectionClassLoader; import me.lucko.luckperms.common.dependencies.classloader.ReflectionClassLoader;
import me.lucko.luckperms.common.plugin.SchedulerAdapter; import me.lucko.luckperms.common.plugin.SchedulerAdapter;
import me.lucko.luckperms.common.plugin.bootstrap.LuckPermsBootstrap; import me.lucko.luckperms.common.plugin.bootstrap.LuckPermsBootstrap;
import me.lucko.luckperms.common.utils.MoreFiles;
import me.lucko.luckperms.sponge.utils.VersionData; import me.lucko.luckperms.sponge.utils.VersionData;
import org.slf4j.Logger; import org.slf4j.Logger;
@ -53,7 +54,6 @@ import org.spongepowered.api.scheduler.SynchronousExecutor;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import java.util.Optional; import java.util.Optional;
import java.util.UUID; import java.util.UUID;
@ -242,7 +242,7 @@ public class LPSpongeBootstrap implements LuckPermsBootstrap {
public Path getDataDirectory() { public Path getDataDirectory() {
Path dataDirectory = this.game.getGameDirectory().toAbsolutePath().resolve("luckperms"); Path dataDirectory = this.game.getGameDirectory().toAbsolutePath().resolve("luckperms");
try { try {
Files.createDirectories(dataDirectory); MoreFiles.createDirectoriesIfNotExists(dataDirectory);
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }

View File

@ -45,6 +45,7 @@ import me.lucko.luckperms.common.sender.Sender;
import me.lucko.luckperms.common.tasks.CacheHousekeepingTask; import me.lucko.luckperms.common.tasks.CacheHousekeepingTask;
import me.lucko.luckperms.common.tasks.ExpireTemporaryTask; import me.lucko.luckperms.common.tasks.ExpireTemporaryTask;
import me.lucko.luckperms.common.treeview.PermissionRegistry; import me.lucko.luckperms.common.treeview.PermissionRegistry;
import me.lucko.luckperms.common.utils.MoreFiles;
import me.lucko.luckperms.sponge.calculators.SpongeCalculatorFactory; import me.lucko.luckperms.sponge.calculators.SpongeCalculatorFactory;
import me.lucko.luckperms.sponge.commands.SpongeMainCommand; import me.lucko.luckperms.sponge.commands.SpongeMainCommand;
import me.lucko.luckperms.sponge.contexts.SpongeContextManager; import me.lucko.luckperms.sponge.contexts.SpongeContextManager;
@ -223,7 +224,7 @@ public class LPSpongePlugin extends AbstractLuckPermsPlugin {
Path path = this.bootstrap.getConfigPath().resolve("luckperms.conf"); Path path = this.bootstrap.getConfigPath().resolve("luckperms.conf");
if (!Files.exists(path)) { if (!Files.exists(path)) {
try { try {
Files.createDirectories(this.bootstrap.getConfigPath()); MoreFiles.createDirectoriesIfNotExists(this.bootstrap.getConfigPath());
try (InputStream is = getClass().getClassLoader().getResourceAsStream("luckperms.conf")) { try (InputStream is = getClass().getClassLoader().getResourceAsStream("luckperms.conf")) {
Files.copy(is, path); Files.copy(is, path);
} }

View File

@ -31,6 +31,7 @@ import com.google.gson.GsonBuilder;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
import me.lucko.luckperms.common.utils.ImmutableCollectors; import me.lucko.luckperms.common.utils.ImmutableCollectors;
import me.lucko.luckperms.common.utils.MoreFiles;
import me.lucko.luckperms.sponge.service.model.LPPermissionService; import me.lucko.luckperms.sponge.service.model.LPPermissionService;
import java.io.BufferedReader; import java.io.BufferedReader;
@ -101,7 +102,7 @@ public class SubjectStorage {
private Path resolveFile(String collectionIdentifier, String subjectIdentifier) { private Path resolveFile(String collectionIdentifier, String subjectIdentifier) {
Path collection = this.container.resolve(collectionIdentifier); Path collection = this.container.resolve(collectionIdentifier);
try { try {
Files.createDirectories(collection); MoreFiles.createDirectoriesIfNotExists(collection);
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }
@ -128,7 +129,7 @@ public class SubjectStorage {
* @throws IOException if the write fails * @throws IOException if the write fails
*/ */
public void saveToFile(SubjectDataContainer container, Path file) throws IOException { public void saveToFile(SubjectDataContainer container, Path file) throws IOException {
Files.createDirectories(file.getParent()); MoreFiles.createDirectoriesIfNotExists(file.getParent());
try (BufferedWriter writer = Files.newBufferedWriter(file, StandardCharsets.UTF_8)) { try (BufferedWriter writer = Files.newBufferedWriter(file, StandardCharsets.UTF_8)) {
this.gson.toJson(container.serialize(), writer); this.gson.toJson(container.serialize(), writer);
writer.flush(); writer.flush();