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

Commit

Permalink
Merge pull request #318 from alphagov/get-clamdscans-stderr
Browse files Browse the repository at this point in the history
Get stderr when running clamdscan
  • Loading branch information
timmow committed Jul 1, 2014
2 parents fce8931 + 114a598 commit d3a02a5
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 d3a02a5

Please sign in to comment.