From a0afde52ac489ea799dc0663644e2708ddc99cf3 Mon Sep 17 00:00:00 2001 From: LamGC Date: Tue, 17 May 2022 19:59:04 +0800 Subject: [PATCH] =?UTF-8?q?fix(launch):=20=E4=BF=AE=E5=A4=8D=20Maven=20?= =?UTF-8?q?=E6=9C=AC=E5=9C=B0=E4=BB=93=E5=BA=93=E6=96=87=E4=BB=B6=E5=A4=B9?= =?UTF-8?q?=E6=9C=AA=E5=88=9D=E5=A7=8B=E5=8C=96=E7=9A=84=E9=97=AE=E9=A2=98?= =?UTF-8?q?.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 由于 Maven 本地仓库文件夹未初始化, 将导致启动时发生错误, 现已修复该问题. --- scalabot-app/src/main/kotlin/AppMain.kt | 29 +++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/scalabot-app/src/main/kotlin/AppMain.kt b/scalabot-app/src/main/kotlin/AppMain.kt index 25e6330..6663765 100644 --- a/scalabot-app/src/main/kotlin/AppMain.kt +++ b/scalabot-app/src/main/kotlin/AppMain.kt @@ -10,6 +10,13 @@ import org.telegram.telegrambots.meta.TelegramBotsApi import org.telegram.telegrambots.meta.generics.BotSession import org.telegram.telegrambots.updatesreceivers.DefaultBotSession import java.io.File +import java.io.IOException +import java.nio.file.attribute.PosixFilePermission +import java.nio.file.attribute.PosixFilePermissions +import kotlin.io.path.createDirectories +import kotlin.io.path.exists +import kotlin.io.path.isReadable +import kotlin.io.path.isWritable import kotlin.system.exitProcess private val log = KotlinLogging.logger { } @@ -65,6 +72,28 @@ internal class Launcher(private val config: AppConfig = Const.config) : AutoClos if (config.mavenLocalRepository != null && config.mavenLocalRepository.isNotEmpty()) { val repoPath = AppPaths.DATA_ROOT.file.toPath() .resolve(config.mavenLocalRepository) + .apply { + if (!exists()) { + if (!parent.isWritable() || !parent.isReadable()) { + throw IOException("Unable to read and write the directory where Maven repository is located.") + } + if (System.getProperty("os.name").lowercase().startsWith("windows")) { + createDirectories() + } else { + createDirectories( + PosixFilePermissions.asFileAttribute( + setOf( + PosixFilePermission.OWNER_READ, + PosixFilePermission.OWNER_WRITE, + PosixFilePermission.GROUP_READ, + PosixFilePermission.GROUP_WRITE, + PosixFilePermission.OTHERS_READ, + ) + ) + ) + } + } + } .toRealPath() .toFile() repoPath