SUPPORT-8836:fixes

This commit is contained in:
adel.ka 2024-12-31 02:21:31 +03:00
parent 384a97d629
commit 1a771c33f9

View file

@ -28,9 +28,9 @@ public class FileScanService {
File tempFile = null;
try {
tempFile = saveFile(file);
return runKeslScan(tempFile);
return runKeslScan(tempFile, file.getOriginalFilename());
}
catch (Exception e) {
catch (IOException | InterruptedException e) {
throw new AvException("Error scanning file: " + file.getOriginalFilename(), e);
}
finally {
@ -47,15 +47,14 @@ public class FileScanService {
private File saveFile(MultipartFile file) throws IOException {
Path uploadPath = Paths.get(uploadDirectory);
if (!Files.exists(uploadPath)) {
Files.createDirectories(uploadPath);
}
Path tempFile = Files.createTempFile(uploadPath, "kesl-upload-", ".tmp");
file.transferTo(tempFile.toFile());
return tempFile.toFile();
Path tempFilePath = Files.createTempFile(uploadPath, "kesl-upload-", ".tmp");
File tempFile = tempFilePath.toFile();
file.transferTo(tempFile);
return tempFile;
}
private int runKeslScan(File file) throws IOException, InterruptedException {
private int runKeslScan(File file, String originalFileName) throws IOException, InterruptedException {
ProcessBuilder processBuilder = new ProcessBuilder(KESL_CONTROL, KESL_SCAN,
file.getAbsolutePath()
);
@ -65,8 +64,6 @@ public class FileScanService {
if (exitCode == 0 || exitCode == 72) {
return exitCode;
}
else {
throw new AvException("KESL error, exit code: " + exitCode);
}
throw new AvException("KESL error scanning file: " + originalFileName + ", exit code: " + exitCode);
}
}