From c668bdf5500ddba67dd6d232679aefca12a5db98 Mon Sep 17 00:00:00 2001 From: bwcx_jzy Date: Mon, 8 Jul 2019 18:53:12 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A7=A3=E5=8E=8B=E5=88=A4=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 6 ++-- .../controller/manage/ProjectFileControl.java | 13 +++++-- .../keepbx/jpom/util/CompressionFileUtil.java | 35 ++++++++----------- 3 files changed, 27 insertions(+), 27 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f10824738..abab73d3a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,9 +8,9 @@ ### 解决BUG、优化功能 -1. logBack页面最后修改时间不能正确显示(感谢@JAVA jesion) -2. nginx修改内容截断,不正确情况(感谢@JAVA jesion) -3. nginx、脚本模板保存内容xss标签还原 +1. 【Agent】logBack页面最后修改时间不能正确显示(感谢@JAVA jesion) +2. 【Agent】nginx修改内容截断,不正确情况(感谢@JAVA jesion) +3. 【Agent】nginx、脚本模板保存内容xss标签还原 ----------------------------------------------------------- diff --git a/modules/agent/src/main/java/cn/keepbx/jpom/controller/manage/ProjectFileControl.java b/modules/agent/src/main/java/cn/keepbx/jpom/controller/manage/ProjectFileControl.java index fb5c023ef..ef3cab3c6 100644 --- a/modules/agent/src/main/java/cn/keepbx/jpom/controller/manage/ProjectFileControl.java +++ b/modules/agent/src/main/java/cn/keepbx/jpom/controller/manage/ProjectFileControl.java @@ -21,6 +21,7 @@ import org.springframework.web.bind.annotation.RestController; import javax.annotation.Resource; import java.io.File; +import java.util.List; /** * 项目文件管理 @@ -89,9 +90,15 @@ public class ProjectFileControl extends BaseAgentController { } // 解压 File file = new File(path); - CompressionFileUtil.unCompress(file.getAbsolutePath(), lib.getAbsolutePath()); - if (!file.delete()) { - DefaultSystemLog.LOG().info("删除失败:" + file.getPath()); + try { + List names = CompressionFileUtil.unCompress(file.getAbsolutePath(), lib.getAbsolutePath()); + if (names == null || names.isEmpty()) { + return JsonMessage.getString(500, "没有解压出任何文件"); + } + } finally { + if (!file.delete()) { + DefaultSystemLog.LOG().info("删除失败:" + file.getPath()); + } } } else { multipartFileBuilder.setSavePath(FileUtil.getAbsolutePath(lib)) diff --git a/modules/agent/src/main/java/cn/keepbx/jpom/util/CompressionFileUtil.java b/modules/agent/src/main/java/cn/keepbx/jpom/util/CompressionFileUtil.java index 143c0a9d0..1a6b5d12f 100644 --- a/modules/agent/src/main/java/cn/keepbx/jpom/util/CompressionFileUtil.java +++ b/modules/agent/src/main/java/cn/keepbx/jpom/util/CompressionFileUtil.java @@ -23,12 +23,12 @@ public class CompressionFileUtil { private static int BUFFER_SIZE = 2048; - public static List unTar(String tarFile, String destDir) throws Exception { + private static List unTar(String tarFile, String destDir) throws Exception { File file = new File(tarFile); return unTar(file, destDir); } - public static List unTar(File tarFile, String destDir) throws Exception { + private static List unTar(File tarFile, String destDir) throws Exception { if (StrUtil.isBlank(destDir)) { destDir = tarFile.getParent(); } @@ -36,12 +36,12 @@ public class CompressionFileUtil { return unTar(new FileInputStream(tarFile), destDir); } - public static List unTarBZip2(String file, String destDir) throws Exception { + private static List unTarBZip2(String file, String destDir) throws Exception { File tarFile = new File(file); return unTarBZip2(tarFile, destDir); } - public static List unTarBZip2(File tarFile, String destDir) throws Exception { + private static List unTarBZip2(File tarFile, String destDir) throws Exception { if (StrUtil.isBlank(destDir)) { destDir = tarFile.getParent(); } @@ -49,12 +49,12 @@ public class CompressionFileUtil { return unTar(new BZip2CompressorInputStream(new FileInputStream(tarFile)), destDir); } - public static List unBZip2(String bzip2File, String destDir) throws IOException { + private static List unBZip2(String bzip2File, String destDir) throws IOException { File file = new File(bzip2File); return unBZip2(file, destDir); } - public static List unTarGZ(File tarFile, String destDir) throws Exception { + private static List unTarGZ(File tarFile, String destDir) throws Exception { if (StrUtil.isBlank(destDir)) { destDir = tarFile.getParent(); } @@ -62,22 +62,22 @@ public class CompressionFileUtil { return unTar(new GzipCompressorInputStream(new FileInputStream(tarFile)), destDir); } - public static List unTarGZ(String file, String destDir) throws Exception { + private static List unTarGZ(String file, String destDir) throws Exception { File tarFile = new File(file); return unTarGZ(tarFile, destDir); } - public static List unZip(String zipfile, String destDir) throws Exception { + private static List unZip(String zipfile, String destDir) throws Exception { File zipFile = new File(zipfile); return unZip(zipFile, destDir); } - public static List unGZ(String gzFile, String destDir) throws IOException { + private static List unGZ(String gzFile, String destDir) throws IOException { File file = new File(gzFile); return unGZ(file, destDir); } - public static void createDirectory(String outputDir, String subDir) { + private static void createDirectory(String outputDir, String subDir) { File file = new File(outputDir); if (!(subDir == null || "".equals(subDir.trim()))) { //子目录不为空 @@ -136,18 +136,14 @@ public class CompressionFileUtil { } } } - } catch (Exception e) { - e.printStackTrace(); - throw e; } finally { IOUtils.closeQuietly(tarIn); } - return fileNames; } - public static List unBZip2(File srcFile, String destDir) throws IOException { + private static List unBZip2(File srcFile, String destDir) throws IOException { if (StrUtil.isBlank(destDir)) { destDir = srcFile.getParent(); } @@ -169,7 +165,7 @@ public class CompressionFileUtil { return fileNames; } - public static List unGZ(File srcFile, String destDir) throws IOException { + private static List unGZ(File srcFile, String destDir) throws IOException { if (StrUtil.isBlank(destDir)) { destDir = srcFile.getParent(); } @@ -191,7 +187,7 @@ public class CompressionFileUtil { return fileNames; } - public static List unZip(File zipfile, String destDir) throws Exception { + private static List unZip(File zipfile, String destDir) throws Exception { if (StrUtil.isBlank(destDir)) { destDir = zipfile.getParent(); } @@ -217,13 +213,10 @@ public class CompressionFileUtil { } } } - } catch (Exception e) { - e.printStackTrace(); - throw e; } finally { IOUtils.closeQuietly(is); } return fileNames; } -} \ No newline at end of file +}