Skip to content
This repository has been archived by the owner on Mar 24, 2021. It is now read-only.

Commit

Permalink
Get stderr when running clamdscan
Browse files Browse the repository at this point in the history
Previously, when clamdscan's had an error we haven't had any information about what went wrong. This should address that.
  • Loading branch information
nick-gravgaard committed Jul 1, 2014
1 parent fce8931 commit 114a598
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions backdrop/admin/scanned_file.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import hashlib
import subprocess
import os
from subprocess import Popen, PIPE


class VirusSignatureError(StandardError):
Expand Down Expand Up @@ -30,7 +30,10 @@ def _scan_file(self):
self._clamscan(self._file_path))

def _clamscan(self, filename):
retcode = subprocess.call(["clamdscan", filename])
args = ['clamdscan', filename]
proc = Popen(args, stdout=PIPE, stderr=PIPE)
_, stderrdata = proc.communicate()
retcode = proc.returncode
# 0 : No virus found.
# 1 : Virus(es) found.
# 2 : An error occured.
Expand All @@ -39,7 +42,8 @@ def _clamscan(self, filename):
elif retcode == 1:
return True
elif retcode == 2:
raise SystemError('Error running the clamdscan virus scanner')
raise SystemError('Error running the clamdscan virus scanner. '
'Stderr was "{}"'.format(stderrdata))

def _clean_up(self):
# Remove temporary file
Expand Down

0 comments on commit 114a598

Please sign in to comment.