Scan files with clamdscan #77

Merged
Anna Sirota merged 17 commits from scan-file into main 2024-04-12 19:11:30 +02:00
2 changed files with 5 additions and 4 deletions
Showing only changes of commit a110c8532a - Show all commits

View File

@ -9,7 +9,7 @@ import files.signals
def scan_selected_files(self, request, queryset): def scan_selected_files(self, request, queryset):
"""Scan selected files.""" """Scan selected files."""
for instance in queryset: for instance in queryset:
files.signals._initiate_scan(instance) files.signals.schedule_scan(instance)
class FileValidationInlineAdmin(admin.StackedInline): class FileValidationInlineAdmin(admin.StackedInline):

View File

@ -16,8 +16,9 @@ def _record_changes(sender: object, instance: files.models.File, **kwargs: objec
instance.record_status_change(was_changed, old_state, **kwargs) instance.record_status_change(was_changed, old_state, **kwargs)
def _initiate_scan(file: files.models.File) -> None: def schedule_scan(file: files.models.File) -> None:
logger.info('Initiating a scan for file pk=%s', file.pk) """Schedule a scan of a given file."""
logger.info('Scheduling a scan for file pk=%s', file.pk)
files.tasks.clamdscan(file_id=file.pk, creator=file, verbose_name=file.source.name) files.tasks.clamdscan(file_id=file.pk, creator=file, verbose_name=file.source.name)
@ -28,4 +29,4 @@ def _scan_new_file(
if not created: if not created:
return return
_initiate_scan(instance) schedule_scan(instance)