fix: preserve unknown assets and retained export-copy ownership

This commit is contained in:
阿白叔 committed 2026-11-03 12:24:54 +08:00
1 parent 55a82fdc5f
commit f21781f170
8 files changed
+312 -10

No files matched your search

+15 -4
View File
@@ -66,8 +66,11 @@ def has_blocker(library):
def _persist_blocker(library, status='OWNER_RELEASE_UNCONFIRMED', *, lease_id):
path = blocker_path(library)
pending = path.with_suffix('.pending')
previous = checkpoint_record(path)
export_record = ({'export_analysis': previous['export_analysis']}
if previous and previous['lease_id'] == lease_id and 'export_analysis' in previous else {})
with pending.open('w', encoding='utf-8') as stream:
json.dump({'protocol': 'cbb-refresh-verify-library-lease', 'version': 1,
json.dump({**export_record, 'protocol': 'cbb-refresh-verify-library-lease', 'version': 1,
'lease_id': lease_id, 'library': str(library), 'status': status,
'pid': os.getpid(), 'time': datetime.now(timezone.utc).isoformat()}, stream)
stream.flush(); os.fsync(stream.fileno())
@@ -159,6 +162,9 @@ class LibraryLock:
if not self.entered:
return
owner = _owners[self.key]
checkpoint = checkpoint_record(blocker_path(self.library))
if checkpoint is not None and 'export_analysis' in checkpoint:
owner['retained'] = True
if self.safe_to_release is not None:
try:
safe = self.safe_to_release() is True
@@ -237,7 +243,8 @@ def _enter_maintenance(lease):
0, None, win32con.OPEN_ALWAYS, win32con.FILE_ATTRIBUTE_NORMAL, None)
# All target/process/address/exclusive-file checks finish BEFORE
# any old checkpoint replacement. Keep the exact sidecar open.
with lease.maintenance_guard() as proof:
from .native_export_guard import prove_export_copies_released
with prove_export_copies_released(lease.library), lease.maintenance_guard() as proof:
if (marker.read_bytes() if marker.exists() else None) != old:
raise LibraryBusy('维护检查期间检查点变化')
if old is not None:
@@ -284,6 +291,9 @@ def _prove_library_released(library):
import pythoncom, win32com.client, win32con, win32file
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
from .native_engineering_identity import _OWNER_NAMES
assert_retained_exports_idle()
if any(worker.poll() is None for worker in _retained_workers):
raise LibraryBusy('原生管理工作进程尚未返回,不能解除协调阻止。')
from .com_runtime import initialize_com, uninitialize_com
@@ -291,7 +301,7 @@ def _prove_library_released(library):
try:
service = win32com.client.GetObject('winmgmts:')
names = ('LibraryManager.exe', 'ExpeditionPCB.exe', 'viewdraw.exe',
'iCDBProjectBackup.exe', 'ReuseBlockImporter.exe', 'CleanWGLib.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)]
@@ -307,11 +317,12 @@ def _prove_library_released(library):
if Path(library).resolve() not in native:
raise LibraryBusy('目标库身份缺失,不能解除协调阻止。')
with ExitStack() as stack:
export_copies = stack.enter_context(prove_export_copies_released(library))
for path in native:
handle = win32file.CreateFile(str(path), win32con.GENERIC_READ, 0, None,
win32con.OPEN_EXISTING, win32con.FILE_ATTRIBUTE_NORMAL, None)
stack.callback(handle.Close)
yield {'native_owners': owners, 'addresses': addresses,
yield {'native_owners': owners, 'addresses': addresses, 'export_copies': export_copies,
'exclusive_files': [str(path) for path in native]}
finally:
uninitialize_com(initialized)