fix(PathManager): allow paths to be symlinks
* fix(PathManager): allow paths to be symlinks
Useful for directories like cachedModules.
* fix(PathManager): fix formatting on libraries-not-found message.
%n is only a newline when run through a Formatter (or printf).
-// Copyright 2021 The Terasology Foundation
+// Copyright 2022 The Terasology Foundation
// SPDX-License-Identifier: Apache-2.0
package org.terasology.engine.core;
import java.lang.reflect.Field;
import java.net.URI;
import java.net.URISyntaxException;
+import java.nio.file.FileAlreadyExistsException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
@@ -97,11 +98,11 @@ private static Path findInstallPath() {
}
}
- System.err.println(
+ System.err.printf(
"Native library installation directory not found. %n" +
"Things will almost certainly crash as a result, %n" +
"unless something else installed everything to java.library.path. %n" +
- "Searched: %n" + installationSearchPaths
+ "Searched: %s%n", installationSearchPaths
);
return currentDirectory;
}
@@ -327,7 +328,14 @@ private void updateDirs() throws IOException {
modPaths = defaultModPaths();
for (Path path : getAllPaths()) {
+ try {
Files.createDirectories(path);
+ } catch (FileAlreadyExistsException e) {
+ // It's okay if it exists as a symlink to a directory.
+ if (!(Files.isSymbolicLink(path) && Files.isDirectory(path))) {
+ throw e;
+ }
+ }
}
// --------------------------------- Setup native paths ---------------------
