From 7aa00ff98bc850f67d8c40a7368538ce2f4d2312 Mon Sep 17 00:00:00 2001 From: LamGC Date: Fri, 22 May 2020 20:34:15 +0800 Subject: [PATCH] =?UTF-8?q?[Fix]=20BotCommandProcess=20=E4=BF=AE=E5=A4=8DI?= =?UTF-8?q?mageStore=E4=B8=8D=E5=85=81=E8=AE=B8=E4=BD=BF=E7=94=A8=E8=BD=AF?= =?UTF-8?q?=E9=93=BE=E6=8E=A5=E7=9A=84=E9=97=AE=E9=A2=98;?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../net/lamgc/cgj/bot/BotCommandProcess.java | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/main/java/net/lamgc/cgj/bot/BotCommandProcess.java b/src/main/java/net/lamgc/cgj/bot/BotCommandProcess.java index 77d593d..1dacdbf 100644 --- a/src/main/java/net/lamgc/cgj/bot/BotCommandProcess.java +++ b/src/main/java/net/lamgc/cgj/bot/BotCommandProcess.java @@ -25,6 +25,7 @@ import org.slf4j.LoggerFactory; import java.io.File; import java.io.IOException; import java.nio.charset.StandardCharsets; +import java.nio.file.Files; import java.text.SimpleDateFormat; import java.util.*; import java.util.concurrent.atomic.AtomicInteger; @@ -793,11 +794,19 @@ public class BotCommandProcess { } return result; } - + + /** + * 获取图片存储目录. + *

每次调用都会检查目录是否存在, 如不存在则会抛出异常

+ * @return 返回File对象 + * @throws RuntimeException 当目录创建失败时将包装{@link IOException}异常并抛出. + */ private static File getImageStoreDir() { - if(!imageStoreDir.exists() && !imageStoreDir.mkdirs()) { - log.warn("酷Q图片缓存目录失效!(Path: {} )", imageStoreDir.getAbsolutePath()); - throw new RuntimeException(new IOException("文件夹创建失败!")); + if(!imageStoreDir.exists() && !Files.isSymbolicLink(imageStoreDir.toPath())) { + if(!imageStoreDir.mkdirs()) { + log.warn("酷Q图片缓存目录失效!(Path: {} )", imageStoreDir.getAbsolutePath()); + throw new RuntimeException(new IOException("文件夹创建失败!")); + } } return imageStoreDir; }