mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2025-01-24 16:14:26 +08:00
Check against symlinks every time when creating directories
Affects issues: - Fixed #1866
This commit is contained in:
parent
ad85679899
commit
4cf5b79b15
@ -51,7 +51,8 @@ abstract class FileExporter {
|
||||
}
|
||||
|
||||
void export(Path to, List<String> content) throws IOException {
|
||||
Files.createDirectories(to.getParent());
|
||||
Path dir = to.getParent();
|
||||
if (!Files.isSymbolicLink(dir)) Files.createDirectories(dir);
|
||||
Files.write(to, content, StandardCharsets.UTF_8, OPEN_OPTIONS);
|
||||
}
|
||||
|
||||
@ -60,7 +61,8 @@ abstract class FileExporter {
|
||||
}
|
||||
|
||||
void export(Path to, WebResource resource) throws IOException {
|
||||
Files.createDirectories(to.getParent());
|
||||
Path dir = to.getParent();
|
||||
if (!Files.isSymbolicLink(dir)) Files.createDirectories(dir);
|
||||
|
||||
try (
|
||||
InputStream in = resource.asStream();
|
||||
@ -71,7 +73,8 @@ abstract class FileExporter {
|
||||
}
|
||||
|
||||
void export(Path to, byte[] resource) throws IOException {
|
||||
Files.createDirectories(to.getParent());
|
||||
Path dir = to.getParent();
|
||||
if (!Files.isSymbolicLink(dir)) Files.createDirectories(dir);
|
||||
|
||||
try (
|
||||
InputStream in = new ByteArrayInputStream(resource);
|
||||
|
@ -175,7 +175,8 @@ public class ResourceSvc implements ResourceService {
|
||||
byte[] bytes = original.asBytes();
|
||||
OpenOption[] overwrite = {StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING, StandardOpenOption.WRITE};
|
||||
Path to = files.getCustomizationDirectory().resolve(fileName);
|
||||
Files.createDirectories(to.getParent());
|
||||
Path dir = to.getParent();
|
||||
if (!Files.isSymbolicLink(dir)) Files.createDirectories(dir);
|
||||
Files.write(to, bytes, overwrite);
|
||||
return original;
|
||||
}
|
||||
|
@ -91,7 +91,7 @@ public class JSONFileStorage implements JSONStorage {
|
||||
Path writingTo = jsonDirectory.resolve(identifier + '-' + timestamp + JSON_FILE_EXTENSION);
|
||||
String jsonToWrite = addMissingTimestamp(json, timestamp);
|
||||
try {
|
||||
Files.createDirectories(jsonDirectory);
|
||||
if (!Files.isSymbolicLink(jsonDirectory)) Files.createDirectories(jsonDirectory);
|
||||
Files.write(writingTo, jsonToWrite.getBytes(StandardCharsets.UTF_8), StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING, StandardOpenOption.WRITE);
|
||||
} catch (IOException e) {
|
||||
logger.warn("Could not write a file to " + writingTo.toFile().getAbsolutePath() + ": " + e.getMessage());
|
||||
|
@ -43,11 +43,11 @@ public class Config extends ConfigNode {
|
||||
|
||||
public Config(File configFile) {
|
||||
super("", null, null);
|
||||
File folder = configFile.getParentFile();
|
||||
this.configFilePath = configFile.toPath();
|
||||
Path dir = configFilePath.getParent();
|
||||
|
||||
try {
|
||||
Files.createDirectories(folder.toPath());
|
||||
if (!Files.isSymbolicLink(dir)) Files.createDirectories(dir);
|
||||
if (!Files.exists(configFilePath)) Files.createFile(configFilePath);
|
||||
read();
|
||||
save();
|
||||
|
@ -68,10 +68,8 @@ public class ConfigWriter {
|
||||
ConfigNode storedParent = writing.parent;
|
||||
writing.updateParent(null);
|
||||
|
||||
Path directory = outputPath.getParent();
|
||||
if (!directory.toRealPath().toFile().isDirectory()) {
|
||||
Files.createDirectories(directory);
|
||||
}
|
||||
Path dir = outputPath.getParent();
|
||||
if (!Files.isSymbolicLink(dir)) Files.createDirectories(dir);
|
||||
Files.write(outputPath, createLines(writing), StandardCharsets.UTF_8, StandardOpenOption.TRUNCATE_EXISTING, StandardOpenOption.CREATE);
|
||||
|
||||
writing.updateParent(storedParent);
|
||||
|
@ -42,6 +42,7 @@ import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.UncheckedIOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
@ -150,7 +151,8 @@ public class NetworkSettingManager implements SubSystem {
|
||||
private File createServerSettingsFolder() {
|
||||
try {
|
||||
File serverConfigFolder = files.getFileFromPluginFolder("serverConfiguration");
|
||||
Files.createDirectories(serverConfigFolder.toPath());
|
||||
Path dir = serverConfigFolder.toPath();
|
||||
if (!Files.isSymbolicLink(dir)) Files.createDirectories(dir);
|
||||
return serverConfigFolder;
|
||||
} catch (IOException e) {
|
||||
throw new EnableException("Could not initialize NetworkSettingManager: " + e.getMessage(), e);
|
||||
|
@ -67,7 +67,8 @@ public class PlanFiles implements SubSystem {
|
||||
public File getLogsFolder() {
|
||||
try {
|
||||
File folder = getFileFromPluginFolder("logs");
|
||||
Files.createDirectories(folder.toPath());
|
||||
Path dir = folder.toPath();
|
||||
Files.createDirectories(dir);
|
||||
return folder;
|
||||
} catch (IOException e) {
|
||||
throw new UncheckedIOException(e);
|
||||
@ -95,7 +96,8 @@ public class PlanFiles implements SubSystem {
|
||||
ResourceCache.invalidateAll();
|
||||
ResourceCache.cleanUp();
|
||||
try {
|
||||
Files.createDirectories(dataFolder.toPath());
|
||||
Path dir = getDataDirectory();
|
||||
if (!Files.isSymbolicLink(dir)) Files.createDirectories(dir);
|
||||
if (!configFile.exists()) Files.createFile(configFile.toPath());
|
||||
} catch (IOException e) {
|
||||
throw new EnableException("Failed to create config.yml, " + e.getMessage(), e);
|
||||
|
@ -223,7 +223,8 @@ public class PluginErrorLogger implements ErrorLogger {
|
||||
|
||||
private void writeNew(Path errorLog, Throwable throwable, List<String> lines) {
|
||||
try {
|
||||
Files.createDirectories(errorLog.getParent());
|
||||
Path dir = errorLog.getParent();
|
||||
if (!Files.isSymbolicLink(dir)) Files.createDirectories(dir);
|
||||
Files.write(errorLog, lines, StandardOpenOption.CREATE_NEW, StandardOpenOption.APPEND);
|
||||
} catch (IOException e) {
|
||||
throwable.addSuppressed(e);
|
||||
|
@ -83,7 +83,8 @@ public class TestResources {
|
||||
|
||||
private static void createEmptyFile(File toFile) {
|
||||
try {
|
||||
Files.createDirectories(toFile.toPath().getParent());
|
||||
Path dir = toFile.toPath().getParent();
|
||||
if (!Files.isSymbolicLink(dir)) Files.createDirectories(dir);
|
||||
if (!toFile.exists()) {
|
||||
Files.createFile(toFile.toPath());
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user