diff --git a/core/src/main/kotlin/net/corda/core/internal/PathUtils.kt b/core/src/main/kotlin/net/corda/core/internal/PathUtils.kt index 0f7d214af4..e8559f2f62 100644 --- a/core/src/main/kotlin/net/corda/core/internal/PathUtils.kt +++ b/core/src/main/kotlin/net/corda/core/internal/PathUtils.kt @@ -194,3 +194,12 @@ inline fun Path.readObject(): T = readAll().deserialize() /** Calculate the hash of the contents of this file. */ inline val Path.hash: SecureHash get() = read { it.hash() } + +/* Check if the Path is symbolic link */ +fun Path.safeSymbolicRead(): Path { + if (Files.isSymbolicLink(this)) { + return (Files.readSymbolicLink(this)) + } else { + return (this) + } +} diff --git a/node-api/src/main/kotlin/net/corda/nodeapi/internal/crypto/KeyStoreUtilities.kt b/node-api/src/main/kotlin/net/corda/nodeapi/internal/crypto/KeyStoreUtilities.kt index 617a5df6e8..f489f23bad 100644 --- a/node-api/src/main/kotlin/net/corda/nodeapi/internal/crypto/KeyStoreUtilities.kt +++ b/node-api/src/main/kotlin/net/corda/nodeapi/internal/crypto/KeyStoreUtilities.kt @@ -7,9 +7,11 @@ import net.corda.core.internal.createDirectories import net.corda.core.internal.exists import net.corda.core.internal.read import net.corda.core.internal.write +import net.corda.core.internal.safeSymbolicRead import java.io.IOException import java.io.InputStream import java.nio.file.Path +import java.nio.file.Files import java.security.* import java.security.cert.Certificate import java.security.cert.X509Certificate @@ -30,7 +32,7 @@ fun loadOrCreateKeyStore(keyStoreFilePath: Path, storePassword: String): KeyStor keyStoreFilePath.read { keyStore.load(it, pass) } } else { keyStore.load(null, pass) - keyStoreFilePath.toAbsolutePath().parent?.createDirectories() + keyStoreFilePath.toAbsolutePath().parent?.safeSymbolicRead()?.createDirectories() keyStoreFilePath.write { keyStore.store(it, pass) } } return keyStore diff --git a/node/src/main/kotlin/net/corda/node/internal/NodeStartup.kt b/node/src/main/kotlin/net/corda/node/internal/NodeStartup.kt index 4b0e989d8f..a41908ce42 100644 --- a/node/src/main/kotlin/net/corda/node/internal/NodeStartup.kt +++ b/node/src/main/kotlin/net/corda/node/internal/NodeStartup.kt @@ -12,6 +12,7 @@ import net.corda.core.internal.* import net.corda.core.internal.concurrent.thenMatch import net.corda.core.internal.cordapp.CordappImpl import net.corda.core.internal.errors.AddressBindingException +import net.corda.core.internal.safeSymbolicRead import net.corda.core.utilities.Try import net.corda.core.utilities.contextLogger import net.corda.core.utilities.loggerFor @@ -487,11 +488,7 @@ fun CliWrapperBase.initLogging(baseDirectory: Path): Boolean { //Test for access to the logging path and shutdown if we are unable to reach it. val logPath = baseDirectory / NodeCliCommand.LOGS_DIRECTORY_NAME try { - if (Files.isSymbolicLink(logPath)){ - Files.readSymbolicLink(logPath).createDirectories() - } else { - logPath.createDirectories() - } + logPath.safeSymbolicRead()?.createDirectories() } catch (e: IOException) { printError("Unable to create logging directory ${logPath.toString()}. Node will now shutdown.") return false