feat: add guarded native CBB management and recovery coordination

This commit is contained in:
阿白叔 committed 2026-11-02 21:13:24 +08:00
1 parent 3415e010ff
commit 797a79c30e
17 files changed
+2423 -15

No files matched your search

+21 -3
View File
@@ -506,14 +506,26 @@ def run_verify(request, *, progress=None, flag_reader=None, process_runner=None,
# Cover contents checking, native work and final state reads with one
# session-wide mutex. The worker-stage lock below is reentrant on Windows.
import win32event, win32con
from .com_runtime import initialize_com, uninitialize_com
initialized = initialize_com()
mutex = win32event.CreateMutex(None, False, r'Local\CbbRefreshVerify795')
acquired = False
library_lock = None
release_confirmed = True
try:
acquired = win32event.WaitForSingleObject(mutex, 0) in (
win32con.WAIT_OBJECT_0, win32con.WAIT_ABANDONED)
if not acquired:
return VerifyResult('BLOCKED', stderr='已有 CBB 校验任务运行,请等待结束。',
safe_to_continue=False)
from .library_lock import LibraryLock, LibraryBusy
if Path(request.lmc_file).is_file():
try:
library_lock = LibraryLock(request.lmc_file, safe_to_release=lambda: release_confirmed)
library_lock.__enter__()
except LibraryBusy as error:
return VerifyResult('BLOCKED', stderr=str(error), safe_to_continue=False)
release_confirmed = False
result = _run_verify_serialized(
request, progress=progress, flag_reader=flag_reader,
process_runner=process_runner, port_check=port_check,
@@ -595,11 +607,17 @@ def run_verify(request, *, progress=None, flag_reader=None, process_runner=None,
ensure_ascii=False, default=str, indent=2), encoding='utf-8')
except OSError:
pass # Keep the native/repair errors even if evidence storage fails.
release_confirmed = result.safe_to_continue
return result
finally:
if acquired:
win32event.ReleaseMutex(mutex)
mutex.Close()
try:
if library_lock is not None:
library_lock.__exit__(None, None, None)
finally:
if acquired:
win32event.ReleaseMutex(mutex)
mutex.Close()
uninitialize_com(initialized)
def _run_verify_serialized(request, *, progress=None, flag_reader=None, process_runner=None,