Skip to content

Commit

Permalink
Merge pull request #646 from nscuro/ensure-data-dir
Browse files Browse the repository at this point in the history
Ensure the data directory exists, and is read- and writable
  • Loading branch information
nscuro authored Aug 29, 2024
2 parents 6f77219 + 2075614 commit 177c218
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions alpine-common/src/main/java/alpine/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -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())) {
Expand Down

0 comments on commit 177c218

Please # to comment.