mirror of
https://github.com/dbarzin/pandora-box.git
synced 2025-07-19 13:29:42 +02:00
fix race condition
This commit is contained in:
parent
b89ad80ed8
commit
d469c3a64c
1 changed files with 8 additions and 15 deletions
|
@ -77,24 +77,23 @@ infected_files = None
|
||||||
|
|
||||||
class scanThread (threading.Thread):
|
class scanThread (threading.Thread):
|
||||||
"""Scanning thread"""
|
"""Scanning thread"""
|
||||||
def __init__(self, id):
|
def __init__(self):
|
||||||
threading.Thread.__init__(self)
|
threading.Thread.__init__(self)
|
||||||
self.id = id
|
self.pandora = pypandora.PyPandora(root_url=pandora_root_url)
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
# print(f"Thread-{self.id} Starting ")
|
|
||||||
while not exitFlag:
|
while not exitFlag:
|
||||||
queueLock.acquire()
|
queueLock.acquire()
|
||||||
if not workQueue.empty():
|
if not workQueue.empty():
|
||||||
file = workQueue.get()
|
file = workQueue.get()
|
||||||
queueLock.release()
|
queueLock.release()
|
||||||
self.scan(self.id, file)
|
self.scan(file)
|
||||||
else:
|
else:
|
||||||
queueLock.release()
|
queueLock.release()
|
||||||
time.sleep(0.1)
|
time.sleep(0.1)
|
||||||
# print(f"Thread-{self.id} Done.")
|
# print(f"Thread-{self.id} Done.")
|
||||||
|
|
||||||
def scan(self, id, file):
|
def scan(self, file):
|
||||||
global infected_files, scanned, file_count, used
|
global infected_files, scanned, file_count, used
|
||||||
try:
|
try:
|
||||||
# get file information
|
# get file information
|
||||||
|
@ -116,17 +115,13 @@ class scanThread (threading.Thread):
|
||||||
if file_size > (1024 * 1024 * 1024):
|
if file_size > (1024 * 1024 * 1024):
|
||||||
status = "TOO BIG"
|
status = "TOO BIG"
|
||||||
else:
|
else:
|
||||||
queueLock.acquire()
|
|
||||||
res = pandora.submit_from_disk(file)
|
res = pandora.submit_from_disk(file)
|
||||||
queueLock.release()
|
|
||||||
|
|
||||||
time.sleep(0.1)
|
time.sleep(0.1)
|
||||||
loop = 0
|
loop = 0
|
||||||
|
|
||||||
while loop < (1024 * 256):
|
while loop < (1024 * 256):
|
||||||
queueLock.acquire()
|
|
||||||
res = pandora.task_status(res["taskId"])
|
res = pandora.task_status(res["taskId"])
|
||||||
queueLock.release()
|
|
||||||
|
|
||||||
# Handle responde from Pandora
|
# Handle responde from Pandora
|
||||||
status = res["status"]
|
status = res["status"]
|
||||||
|
@ -145,7 +140,7 @@ class scanThread (threading.Thread):
|
||||||
f'Scan {file_name} '
|
f'Scan {file_name} '
|
||||||
f'[{human_readable_size(file_size)}] '
|
f'[{human_readable_size(file_size)}] '
|
||||||
'-> '
|
'-> '
|
||||||
f'{status} ({int(file_scan_end_time - file_scan_start_time)}s)')
|
f'{status} ({(file_scan_end_time - file_scan_start_time):.1f}s)')
|
||||||
logging.info(
|
logging.info(
|
||||||
f'file="{file_name}", '
|
f'file="{file_name}", '
|
||||||
f'size="{file_size}", '
|
f'size="{file_size}", '
|
||||||
|
@ -559,8 +554,6 @@ def scan():
|
||||||
|
|
||||||
if has_quarantine:
|
if has_quarantine:
|
||||||
qfolder = os.path.join(quarantine_folder, datetime.datetime.now().strftime("%y%m%d-%H%M"))
|
qfolder = os.path.join(quarantine_folder, datetime.datetime.now().strftime("%y%m%d-%H%M"))
|
||||||
if not is_fake_scan:
|
|
||||||
pandora = pypandora.PyPandora(root_url=pandora_root_url)
|
|
||||||
|
|
||||||
# Instantice work quere
|
# Instantice work quere
|
||||||
workQueue = queue.Queue(512)
|
workQueue = queue.Queue(512)
|
||||||
|
@ -569,8 +562,8 @@ def scan():
|
||||||
exitFlag = False
|
exitFlag = False
|
||||||
|
|
||||||
# Instanciate threads
|
# Instanciate threads
|
||||||
for i in range(maxThreads):
|
for _ in range(maxThreads):
|
||||||
thread = scanThread(i)
|
thread = scanThread()
|
||||||
thread.start()
|
thread.start()
|
||||||
threads.append(thread)
|
threads.append(thread)
|
||||||
|
|
||||||
|
@ -595,7 +588,7 @@ def scan():
|
||||||
t.join()
|
t.join()
|
||||||
|
|
||||||
update_bar(100, flush=True)
|
update_bar(100, flush=True)
|
||||||
log("Scan done in %ds, %d files scanned, %d files infected" %
|
log("Scan done in %.1fs, %d files scanned, %d files infected" %
|
||||||
((time.time() - scan_start_time), file_count, len(infected_files)),
|
((time.time() - scan_start_time), file_count, len(infected_files)),
|
||||||
flush=True)
|
flush=True)
|
||||||
logging.info(
|
logging.info(
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue