From 9f2772ae710c12783ec49c92a793221399488889 Mon Sep 17 00:00:00 2001 From: MeterSphere Bot <78466014+metersphere-bot@users.noreply.github.com> Date: Wed, 7 Sep 2022 19:00:22 +0800 Subject: [PATCH] =?UTF-8?q?revert(=E6=8E=A5=E5=8F=A3=E5=AE=9A=E4=B9=89):?= =?UTF-8?q?=20=E5=9B=9E=E9=80=80=E6=9C=8D=E5=8A=A1=E5=99=A8=E5=90=8C?= =?UTF-8?q?=E6=AD=A5=E5=88=A0=E9=99=A4=E6=96=87=E4=BB=B6=20(#17750)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: wxg0103 <727495428@qq.com> --- .../api/service/ApiAutomationService.java | 7 --- .../api/service/ApiDefinitionService.java | 3 -- .../metersphere/commons/utils/FileUtils.java | 44 +------------------ 3 files changed, 1 insertion(+), 53 deletions(-) diff --git a/backend/src/main/java/io/metersphere/api/service/ApiAutomationService.java b/backend/src/main/java/io/metersphere/api/service/ApiAutomationService.java index 60d87a6662..9b88c9cd3a 100644 --- a/backend/src/main/java/io/metersphere/api/service/ApiAutomationService.java +++ b/backend/src/main/java/io/metersphere/api/service/ApiAutomationService.java @@ -427,13 +427,6 @@ public class ApiAutomationService { extScheduleMapper.updateNameByResourceID(request.getId(), request.getName());// 修改场景name,同步到修改首页定时任务 uploadFiles(request, bodyFiles, scenarioFiles); - if (CollectionUtils.isNotEmpty(request.getScenarioDefinition().getHashTree())) { - request.getScenarioDefinition().getHashTree().stream().forEach(hashTree -> { - //删除不需要的文件 - FileUtils.deleteBodyFiles(hashTree); - }); - } - // 存储依赖关系 ApiAutomationRelationshipEdgeService relationshipEdgeService = CommonBeanFactory.getBean(ApiAutomationRelationshipEdgeService.class); if (relationshipEdgeService != null) { diff --git a/backend/src/main/java/io/metersphere/api/service/ApiDefinitionService.java b/backend/src/main/java/io/metersphere/api/service/ApiDefinitionService.java index a937e1611a..9504dc3b1b 100644 --- a/backend/src/main/java/io/metersphere/api/service/ApiDefinitionService.java +++ b/backend/src/main/java/io/metersphere/api/service/ApiDefinitionService.java @@ -419,9 +419,6 @@ public class ApiDefinitionService { mockConfigService.updateMockReturnMsgByApi(returnModel); FileUtils.createBodyFiles(request.getRequest().getId(), bodyFiles); - //删除不需要的文件 - FileUtils.deleteBodyFiles(request.getRequest()); - String context = SessionUtils.getUserId().concat(Translator.get("update_api")).concat(":").concat(returnModel.getName()); Map paramMap = new HashMap<>(); getParamMap(paramMap, returnModel.getProjectId(), SessionUtils.getUserId(), returnModel.getId(), returnModel.getName(), returnModel.getCreateUser()); diff --git a/backend/src/main/java/io/metersphere/commons/utils/FileUtils.java b/backend/src/main/java/io/metersphere/commons/utils/FileUtils.java index 1ee6d48f6d..c5eb378b43 100644 --- a/backend/src/main/java/io/metersphere/commons/utils/FileUtils.java +++ b/backend/src/main/java/io/metersphere/commons/utils/FileUtils.java @@ -1,14 +1,10 @@ package io.metersphere.commons.utils; -import io.metersphere.api.dto.definition.request.sampler.MsHTTPSamplerProxy; -import io.metersphere.api.dto.scenario.Body; -import io.metersphere.api.dto.scenario.KeyValue; import io.metersphere.api.dto.scenario.request.BodyFile; import io.metersphere.base.domain.FileMetadata; import io.metersphere.base.domain.JarConfig; import io.metersphere.commons.exception.MSException; import io.metersphere.i18n.Translator; -import io.metersphere.plugin.core.MsTestElement; import io.metersphere.service.JarConfigService; import io.metersphere.utils.LoggerUtil; import org.apache.commons.collections.CollectionUtils; @@ -24,7 +20,6 @@ import org.springframework.web.multipart.MultipartFile; import java.io.*; import java.util.*; -import java.util.stream.Collectors; import java.util.zip.ZipEntry; import java.util.zip.ZipOutputStream; @@ -128,44 +123,7 @@ public class FileUtils { }); } } - - public static void deleteBodyFiles(MsTestElement request) { - if (request != null && StringUtils.isNotBlank(request.getId())) { - String path = BODY_FILE_DIR + File.separator + request.getId(); - File testDir = new File(path); - if (!testDir.exists()) { - return; - } - List files = new ArrayList<>(); - if (request != null && StringUtils.equalsIgnoreCase(request.getType(), HTTPSamplerProxy.class.getSimpleName())) { - MsHTTPSamplerProxy samplerProxy = (MsHTTPSamplerProxy) request; - Body body = samplerProxy.getBody(); - if (body != null && !CollectionUtils.isEmpty(body.getKvs())) { - body.getKvs().stream().filter(KeyValue::isFile).forEach(keyValue -> { - files.addAll(keyValue.getFiles().stream().map(BodyFile::getName).collect(Collectors.toList())); - }); - } - if (body != null && !CollectionUtils.isEmpty(body.getBinary())) { - body.getBinary().stream().filter(KeyValue::isFile).filter(KeyValue::isEnable).forEach(keyValue -> { - files.addAll(keyValue.getFiles().stream().map(BodyFile::getName).collect(Collectors.toList())); - }); - } - } - - File[] optFilesName = testDir.listFiles(); - if (CollectionUtils.isNotEmpty(files)) { - for (File f : optFilesName) { - if (!files.contains(f.getName())) { - f.delete(); - } - } - } else { - FileUtil.deleteContents(testDir); - testDir.delete(); - } - } - } - + public static void copyBodyFiles(String sourceId, String targetId) { try { String sourcePath = BODY_FILE_DIR + File.separator + sourceId;