feat: offer explicit copy recovery after failed ICDB maintenance

This commit is contained in:
阿白叔 committed 2026-11-04 14:16:00 +08:00
1 parent e14a864b37
commit 29959e2988
7 files changed
+520 -27

No files matched your search

+20 -9
View File
@@ -288,7 +288,8 @@ def owned_snapshot(path):
@contextmanager
def _prove_library_released(library):
"""Hold all native database read handles during explicit lease release."""
import pythoncom, win32com.client, win32con, win32file
import win32con, win32file
from .owner_probe import query_owners
from .scoped_manifest import scan_tree
from .native_management import _retained_workers
from .native_export_guard import assert_retained_exports_idle, prove_export_copies_released
@@ -299,15 +300,24 @@ def _prove_library_released(library):
from .com_runtime import initialize_com, uninitialize_com
initialized = initialize_com()
try:
service = win32com.client.GetObject('winmgmts:')
names = ('LibraryManager.exe', 'ExpeditionPCB.exe', 'viewdraw.exe',
'iCDBProjectBackup.exe', 'ReuseBlockImporter.exe', 'CleanWGLib.exe', *sorted(_OWNER_NAMES))
query = 'SELECT ProcessId, Name FROM Win32_Process WHERE ' + ' OR '.join(
f"Name='{name}'" for name in names)
owners = [{'pid': int(item.ProcessId), 'name': str(item.Name)} for item in service.ExecQuery(query)]
service = None
if owners:
raise LibraryBusy(f'原生进程仍存在,不能解除协调阻止:{owners}')
'iCDBProjectBackup.exe', 'ReuseBlockImporter.exe', 'CleanWGLib.exe',
'cscript.exe', 'wscript.exe', 'python.exe', 'pythonw.exe',
'CbbRefreshVerify.exe', *sorted(_OWNER_NAMES))
def check_owners():
owners = []
for item in query_owners(names):
if item['pid'] == os.getpid():
continue
automation = item['name'].casefold() in ('python.exe', 'pythonw.exe', 'cbbrefreshverify.exe')
command = item['command'].casefold()
if not automation or not command or any(flag in command for flag in (
'--verify-worker', '--repair-worker', '--management-worker')):
owners.append(item)
if owners:
raise LibraryBusy(f'原生进程仍存在,不能解除协调阻止:{owners}')
return owners
check_owners()
entries = scan_tree(Path(library).parent)
addresses = [str(path) for path in entries if path.name.casefold() == 'saddress.adr']
if addresses:
@@ -322,6 +332,7 @@ def _prove_library_released(library):
handle = win32file.CreateFile(str(path), win32con.GENERIC_READ, 0, None,
win32con.OPEN_EXISTING, win32con.FILE_ATTRIBUTE_NORMAL, None)
stack.callback(handle.Close)
owners = check_owners()
yield {'native_owners': owners, 'addresses': addresses, 'export_copies': export_copies,
'exclusive_files': [str(path) for path in native]}
finally: