From 207561434866b23cb1735f7105ff50e1e3298061 Mon Sep 17 00:00:00 2001 From: nscuro Date: Wed, 28 Aug 2024 13:09:21 +0200 Subject: [PATCH] Ensure the data directory exists, and is read- and writable Alpine currently tries to create the `system.id` file despite the data directory potentially not existing, which causes `NoSuchFileException`s. Signed-off-by: nscuro --- .../src/main/java/alpine/Config.java | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/alpine-common/src/main/java/alpine/Config.java b/alpine-common/src/main/java/alpine/Config.java index 1e32a9c3..5b802cee 100644 --- a/alpine-common/src/main/java/alpine/Config.java +++ b/alpine-common/src/main/java/alpine/Config.java @@ -272,6 +272,28 @@ void init() { LOGGER.error("A fatal error occurred loading application version information. Please correct the issue and restart the application."); } + final File dataDirectory = getDataDirectorty(); + if (!dataDirectory.exists()) { + if (!dataDirectory.mkdirs()) { + LOGGER.warn(""" + Data directory %s does not exist, and could not be created. \ + Please ensure that the user running the JVM has sufficient permissions.\ + """.formatted(dataDirectory.getAbsolutePath())); + } + } + if (!dataDirectory.canRead()) { + LOGGER.warn(""" + Data directory %s is not readable. \ + Please ensure that the user running the JVM has sufficient permissions.\ + """.formatted(dataDirectory.getAbsolutePath())); + } + if (!dataDirectory.canWrite()) { + LOGGER.warn(""" + Data directory %s is not writable. \ + Please ensure that the user running the JVM has sufficient permissions.\ + """.formatted(dataDirectory.getAbsolutePath())); + } + final File systemIdFile = getSystemIdFilePath(); if (!systemIdFile.exists()) { try (OutputStream fos = Files.newOutputStream(systemIdFile.toPath())) {