fix(launch): 修复 Maven 本地仓库文件夹未初始化的问题.

由于 Maven 本地仓库文件夹未初始化, 将导致启动时发生错误, 现已修复该问题.
This commit is contained in:
LamGC 2022-05-17 19:59:04 +08:00
parent ef37f3b2d7
commit a0afde52ac
Signed by: LamGC
GPG Key ID: 6C5AE2A913941E1D

View File

@ -10,6 +10,13 @@ import org.telegram.telegrambots.meta.TelegramBotsApi
import org.telegram.telegrambots.meta.generics.BotSession import org.telegram.telegrambots.meta.generics.BotSession
import org.telegram.telegrambots.updatesreceivers.DefaultBotSession import org.telegram.telegrambots.updatesreceivers.DefaultBotSession
import java.io.File 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 import kotlin.system.exitProcess
private val log = KotlinLogging.logger { } 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()) { if (config.mavenLocalRepository != null && config.mavenLocalRepository.isNotEmpty()) {
val repoPath = AppPaths.DATA_ROOT.file.toPath() val repoPath = AppPaths.DATA_ROOT.file.toPath()
.resolve(config.mavenLocalRepository) .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() .toRealPath()
.toFile() .toFile()
repoPath repoPath