Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
孙永强 committed Oct 23, 2024
1 parent cb60b53 commit 8e57d82
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
4 changes: 2 additions & 2 deletions virus_scanner/db_oper.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ def update_vscan_record(self, repo_id, scan_commit_id):
def add_virus_record(self, records):
session = self.edb_session()
try:
session.add_all(VirusFile(repo_id, commit_id, file_path, 0, 0)
for repo_id, commit_id, file_path in records)
session.add_all(VirusFile(repo_id, commit_id, file_path, 0, 0, discovery_time)
for repo_id, commit_id, file_path, discovery_time in records)
session.commit()
return 0
except Exception as e:
Expand Down
6 changes: 4 additions & 2 deletions virus_scanner/models.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from sqlalchemy.orm import mapped_column
from sqlalchemy.sql.sqltypes import Integer, String, Text, Boolean
from sqlalchemy.sql.sqltypes import Integer, String, Text, Boolean, DateTime

from seafevents.db import Base

Expand All @@ -26,12 +26,14 @@ class VirusFile(Base):
file_path = mapped_column(Text, nullable=False)
has_deleted = mapped_column(Boolean, nullable=False, index=True)
has_ignored = mapped_column(Boolean, nullable=False, index=True)
timestamp = mapped_column(DateTime(), nullable=False)
__table_args__ = {'extend_existing': True}

def __init__(self, repo_id, commit_id, file_path, has_deleted, has_ignored):
def __init__(self, repo_id, commit_id, file_path, has_deleted, has_ignored, timestamp):
super().__init__()
self.repo_id = repo_id
self.commit_id = commit_id
self.file_path = file_path
self.has_deleted = has_deleted
self.has_ignored = has_ignored
self.timestamp = timestamp
3 changes: 2 additions & 1 deletion virus_scanner/virus_scan.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# -*- coding: utf-8 -*-
import datetime
import os
import tempfile
import subprocess
Expand Down Expand Up @@ -85,7 +86,7 @@ def scan_virus(self, scan_task):
elif ret == 1:
logger.info('File %s virus scan by %s: Found virus.', fpath, self.settings.scan_cmd)
vnum += 1
vrecords.append((scan_task.repo_id, scan_task.head_commit_id, fpath))
vrecords.append((scan_task.repo_id, scan_task.head_commit_id, fpath, datetime.datetime.utcnow()))
else:
logger.debug('File %s virus scan by %s: Failed.', fpath, self.settings.scan_cmd)
nfailed += 1
Expand Down

0 comments on commit 8e57d82

Please sign in to comment.