From 6b802b65455bbfeb8a6c4acb9a253d23ebf8f217 Mon Sep 17 00:00:00 2001 From: gaoxiongzaq Date: Tue, 19 Dec 2023 15:55:21 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8E=8B=E7=BC=A9=E5=8C=85=E6=96=B9=E6=B3=95?= =?UTF-8?q?=20=E6=A0=87=E6=B3=A8=E8=B7=AF=E5=BE=84=E8=AF=A6=E7=BB=86?= =?UTF-8?q?=E8=AF=B4=E6=98=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/cn/keking/service/CompressFileReader.java | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/server/src/main/java/cn/keking/service/CompressFileReader.java b/server/src/main/java/cn/keking/service/CompressFileReader.java index d0839be5..29b5e987 100644 --- a/server/src/main/java/cn/keking/service/CompressFileReader.java +++ b/server/src/main/java/cn/keking/service/CompressFileReader.java @@ -34,9 +34,10 @@ public class CompressFileReader { public String unRar(String filePath, String filePassword, String fileName, String fileKey) throws Exception { List imgUrls = new ArrayList<>(); String baseUrl = BaseUrlFilter.getBaseUrl(); + String packagePath = "_"; //防止文件名重复 压缩包统一生成文件添加_符号 String folderName = filePath.replace(fileDir, ""); //修复压缩包 多重目录获取路径错误 if (!ObjectUtils.isEmpty(fileKey)) { //压缩包文件 直接赋予路径 不予下载 - folderName = "_decompression"+folderName; + folderName = "_decompression"+folderName; //重新修改多重压缩包 生成文件路径 } RandomAccessFile randomAccessFile = null; IInArchive inArchive = null; @@ -57,11 +58,11 @@ public class CompressFileReader { } str[0] = str[0].replace("\\", File.separator); //Linux 下路径错误 String str1 = str[0].substring(0, str[0].lastIndexOf(File.separator)+ 1); - File file = new File(fileDir, finalFolderName + "_" + File.separator + str1); + File file = new File(fileDir, finalFolderName + packagePath + File.separator + str1); if (!file.exists()) { file.mkdirs(); } - OutputStream out = new FileOutputStream( fileDir+ finalFolderName + "_" + File.separator + str[0], true); + OutputStream out = new FileOutputStream( fileDir+ finalFolderName + packagePath + File.separator + str[0], true); IOUtils.write(data, out); out.close(); } catch (Exception e) { @@ -73,15 +74,15 @@ public class CompressFileReader { if (result == ExtractOperationResult.OK) { FileType type = FileType.typeFromUrl(str[0]); if (type.equals(FileType.PICTURE)) { - imgUrls.add(baseUrl +folderName + "_/" + str[0].replace("\\", "/")); + imgUrls.add(baseUrl +folderName + packagePath +"/" + str[0].replace("\\", "/")); } - fileHandlerService.putImgCache(fileName+ "_", imgUrls); + fileHandlerService.putImgCache(fileName+ packagePath, imgUrls); } else { return null; } } } - return folderName + "_"; + return folderName + packagePath; } catch (Exception e) { throw new Exception(e); } finally {