diff options
Diffstat (limited to 'src/main')
-rw-r--r-- | src/main/java/org/onap/sdc/helmvalidator/helm/validation/FileManager.java | 26 |
1 files changed, 5 insertions, 21 deletions
diff --git a/src/main/java/org/onap/sdc/helmvalidator/helm/validation/FileManager.java b/src/main/java/org/onap/sdc/helmvalidator/helm/validation/FileManager.java index 4bc8ea6..ab1d186 100644 --- a/src/main/java/org/onap/sdc/helmvalidator/helm/validation/FileManager.java +++ b/src/main/java/org/onap/sdc/helmvalidator/helm/validation/FileManager.java @@ -20,12 +20,11 @@ package org.onap.sdc.helmvalidator.helm.validation; -import java.io.File; import java.io.IOException; import java.nio.file.Files; +import java.nio.file.Path; import java.nio.file.Paths; import java.nio.file.StandardCopyOption; -import java.time.Instant; import org.onap.sdc.helmvalidator.helm.validation.exception.SaveFileException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -47,12 +46,11 @@ public class FileManager { String saveFile(MultipartFile file) { LOGGER.debug("Base PATH: {}", basePath); - try { - String filePath = basePath + File.separator + generateFileName(file.getOriginalFilename()); - LOGGER.info("Attempt to save file : {}", filePath); - Files.copy(file.getInputStream(), Paths.get(filePath), StandardCopyOption.REPLACE_EXISTING); - return filePath; + final Path tmpFilePath = Files.createTempFile(Paths.get(basePath), "chart-", ".tgz"); + LOGGER.info("Attempt to save file : {}", tmpFilePath); + Files.copy(file.getInputStream(), tmpFilePath, StandardCopyOption.REPLACE_EXISTING); + return tmpFilePath.toString(); } catch (IOException e) { throw new SaveFileException("Cannot save file: " + file.getOriginalFilename(), e); } @@ -66,18 +64,4 @@ public class FileManager { LOGGER.warn("Cannot delete file: {}, Exception: {}", path, e.getStackTrace()); } } - - private String generateFileName(String fileName) { - if (isValidFileName(fileName)) { - return Instant.now().toEpochMilli() + "_" + fileName.replaceAll("\\s+", ""); - } - throw new SaveFileException("Not allowed file name"); - } - - private boolean isValidFileName(String fileName) { - if (fileName == null){ - return false; - } - return !fileName.contains("/"); - } } |