解压判断

This commit is contained in:
bwcx_jzy 2019-07-08 18:53:12 +08:00
parent 8a3515ff30
commit c668bdf550
3 changed files with 27 additions and 27 deletions

View File

@ -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标签还原
-----------------------------------------------------------

View File

@ -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<String> 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))

View File

@ -23,12 +23,12 @@ public class CompressionFileUtil {
private static int BUFFER_SIZE = 2048;
public static List<String> unTar(String tarFile, String destDir) throws Exception {
private static List<String> unTar(String tarFile, String destDir) throws Exception {
File file = new File(tarFile);
return unTar(file, destDir);
}
public static List<String> unTar(File tarFile, String destDir) throws Exception {
private static List<String> 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<String> unTarBZip2(String file, String destDir) throws Exception {
private static List<String> unTarBZip2(String file, String destDir) throws Exception {
File tarFile = new File(file);
return unTarBZip2(tarFile, destDir);
}
public static List<String> unTarBZip2(File tarFile, String destDir) throws Exception {
private static List<String> 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<String> unBZip2(String bzip2File, String destDir) throws IOException {
private static List<String> unBZip2(String bzip2File, String destDir) throws IOException {
File file = new File(bzip2File);
return unBZip2(file, destDir);
}
public static List<String> unTarGZ(File tarFile, String destDir) throws Exception {
private static List<String> 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<String> unTarGZ(String file, String destDir) throws Exception {
private static List<String> unTarGZ(String file, String destDir) throws Exception {
File tarFile = new File(file);
return unTarGZ(tarFile, destDir);
}
public static List<String> unZip(String zipfile, String destDir) throws Exception {
private static List<String> unZip(String zipfile, String destDir) throws Exception {
File zipFile = new File(zipfile);
return unZip(zipFile, destDir);
}
public static List<String> unGZ(String gzFile, String destDir) throws IOException {
private static List<String> 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<String> unBZip2(File srcFile, String destDir) throws IOException {
private static List<String> 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<String> unGZ(File srcFile, String destDir) throws IOException {
private static List<String> 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<String> unZip(File zipfile, String destDir) throws Exception {
private static List<String> 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;
}
}
}