SUPPORT-8841: change exceptions
This commit is contained in:
parent
a34f46a707
commit
cd60ff4e53
1 changed files with 9 additions and 7 deletions
|
|
@ -32,9 +32,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 {
|
||||
|
|
@ -59,7 +59,7 @@ public class FileScanService {
|
|||
return tempFile.toFile();
|
||||
}
|
||||
|
||||
private ScanResult runKeslScan(File file) throws IOException, InterruptedException {
|
||||
private ScanResult runKeslScan(File file, String originalFileName) throws IOException, InterruptedException {
|
||||
ProcessBuilder processBuilder = new ProcessBuilder(KESL_CONTROL, KESL_SCAN,
|
||||
file.getAbsolutePath()
|
||||
);
|
||||
|
|
@ -68,7 +68,7 @@ public class FileScanService {
|
|||
|
||||
try (InputStream inputStream = process.getInputStream()) {
|
||||
String result = new String(inputStream.readAllBytes());
|
||||
checkScanResult(result);
|
||||
checkScanResult(result, originalFileName);
|
||||
|
||||
int exitCode = process.waitFor();
|
||||
if (exitCode == 0) {
|
||||
|
|
@ -92,18 +92,20 @@ public class FileScanService {
|
|||
);
|
||||
}
|
||||
else {
|
||||
throw new AvException("KESL error, exit code: " + exitCode);
|
||||
throw new AvException("KESL error scanning file "
|
||||
+ originalFileName
|
||||
+ ", exit code: " + exitCode);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void checkScanResult(String result) {
|
||||
private void checkScanResult(String result, String originalFileName) {
|
||||
for (String line : result.split("\n")) {
|
||||
String[] lineParts = line.split(":");
|
||||
if (lineParts.length > 1) {
|
||||
if (lineParts[0].startsWith(passwordProtectedResultName)
|
||||
&& Integer.parseInt(lineParts[1].trim()) > 0) {
|
||||
throw new AvException("Detected password-protected file");
|
||||
throw new AvException("Detected password-protected file: " + originalFileName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue