From 2cfc8cad9da793f2d78a3bffb0718c737b22e086 Mon Sep 17 00:00:00 2001 From: JeremyStarTM Date: Sun, 15 Dec 2024 13:50:53 +0100 Subject: [PATCH] Add verification pass to updateDefaultPaths method --- .../engine/base/utility/FileAccess.kt | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/base/src/main/kotlin/de/staropensource/engine/base/utility/FileAccess.kt b/base/src/main/kotlin/de/staropensource/engine/base/utility/FileAccess.kt index 042527c..d66e646 100644 --- a/base/src/main/kotlin/de/staropensource/engine/base/utility/FileAccess.kt +++ b/base/src/main/kotlin/de/staropensource/engine/base/utility/FileAccess.kt @@ -139,34 +139,43 @@ class FileAccess { * Updates all default paths to * their platform-specific path. * + * @throws VerificationFailedException if path creation fails * @since v1-alpha10 */ + @Throws(VerificationFailedException::class) internal fun updateDefaultPaths() { logger.diag("Updating default paths") + // Storage - homeDirectory = FileAccess(System.getProperty("user.home")).createDirectory() + homeDirectory = FileAccess(System.getProperty("user.home")) + .createDirectory().verifyIsDirectory() + configDirectory = FileAccess(when (Environment.operatingSystem) { LINUX, FREEBSD, NETBSD, OPENBSD -> "${homeDirectory}/.config" WINDOWS -> "${homeDirectory}/AppData/Roaming/sosengine-config" else -> "${homeDirectory}/.sosengine/config" - }).createDirectory() + }).createDirectory().verifyIsDirectory() + dataDirectory = FileAccess(when (Environment.operatingSystem) { LINUX, FREEBSD, NETBSD, OPENBSD -> "${homeDirectory}/.local/share" WINDOWS -> "${homeDirectory}/AppData/Roaming/sosengine-data" else -> "${homeDirectory}/.sosengine/data" - }).createDirectory() + }).createDirectory().verifyIsDirectory() + + // Caches temporaryCacheDirectory = FileAccess( System.getProperty("java.io.tmpdir") + "/sosengine-cache-" + ProcessHandle.current().pid() - ).createDirectory().deleteOnShutdown() + ).createDirectory().verifyIsDirectory().deleteOnShutdown() + persistentCacheDirectory = FileAccess(when (Environment.operatingSystem) { LINUX, FREEBSD, NETBSD, OPENBSD -> "${homeDirectory}/.cache" WINDOWS -> "${homeDirectory}/AppData/Local/Temp" else -> "${homeDirectory}/.sosengine/persistent-cache" - }).createDirectory() + }).createDirectory().verifyIsDirectory() }