Scan files with clamdscan #77
@ -17,15 +17,20 @@ def clamdscan(file_id: int):
|
|||||||
file = files.models.File.objects.get(pk=file_id)
|
file = files.models.File.objects.get(pk=file_id)
|
||||||
abs_path = os.path.join(settings.MEDIA_ROOT, file.source.path)
|
abs_path = os.path.join(settings.MEDIA_ROOT, file.source.path)
|
||||||
completed_process = files.utils.run_clamdscan(abs_path)
|
completed_process = files.utils.run_clamdscan(abs_path)
|
||||||
scan_result = {
|
|
||||||
'args': completed_process.args,
|
|
||||||
'stdout': completed_process.stdout.decode(),
|
|
||||||
'stderr': completed_process.stderr.decode(),
|
|
||||||
'returncode': completed_process.returncode,
|
|
||||||
}
|
|
||||||
logger.info('File pk=%s scanned: exit code %s', file.pk, completed_process.returncode)
|
logger.info('File pk=%s scanned: exit code %s', file.pk, completed_process.returncode)
|
||||||
|
results = {
|
||||||
|
'clamdscan': {
|
||||||
|
'args': completed_process.args,
|
||||||
|
'stdout': completed_process.stdout.decode(),
|
||||||
|
'stderr': completed_process.stderr.decode(),
|
||||||
|
'returncode': completed_process.returncode,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
is_ok = completed_process.returncode == 0
|
||||||
file_validation, is_new = files.models.FileValidation.objects.get_or_create(
|
file_validation, is_new = files.models.FileValidation.objects.get_or_create(
|
||||||
file=file, defaults={'results': {'clamdscan': scan_result}}
|
file=file, defaults={'results': results, 'is_ok': is_ok}
|
||||||
)
|
)
|
||||||
file_validation.is_ok = completed_process.returncode == 0
|
if not is_new:
|
||||||
file_validation.save()
|
file_validation.results = results
|
||||||
|
file_validation.is_ok = is_ok
|
||||||
|
file_validation.save(update_fields={'results', 'is_ok'})
|
||||||
|
Loading…
Reference in New Issue
Block a user