fix: scope release proofs and bind PCB opening consent
This commit is contained in:
1 parent
42d0cebc54
commit
466f400514
33 files changed
+1358
-61
No files matched your search
@@ -84,6 +84,19 @@ def has_retained_library(library):
|
||||
|
||||
def recheck_previous_release(library, evidence_dir, *, block_name=None, required=False, progress=None):
|
||||
"""Historical records trigger fresh proof, never process termination or repair."""
|
||||
if not required:
|
||||
with _guard:
|
||||
owner = _owners.get(LibraryLock(library).key)
|
||||
marker = blocker_path(library)
|
||||
record = checkpoint_record(marker)
|
||||
if (owner and owner['thread'] == threading.get_ident() and owner['depth'] > 0
|
||||
and not owner['retained'] and not marker.with_suffix('.pending').exists()
|
||||
and record and record['lease_id'] == owner['lease_id']
|
||||
and record['pid'] == os.getpid() and record['status'] == 'OPERATION_IN_PROGRESS'
|
||||
and record.get('block_name') == owner.get('block_name')
|
||||
and owner.get('block_name') in (None, block_name)
|
||||
and 'export_analysis' not in record):
|
||||
return None # Nested Verify belongs to this live transaction, not a past crash.
|
||||
if not (required or has_blocker(library) or has_retained_library(library)):
|
||||
return None
|
||||
def notify(stage, **details):
|
||||
@@ -362,6 +375,23 @@ def _owner_matches_scope(item, library, roots):
|
||||
return False if candidates else None
|
||||
|
||||
|
||||
def _owner_is_blocking(item, library, roots):
|
||||
"""Unknown external clients need resource proof, not a global exit rule."""
|
||||
scope = _owner_matches_scope(item, library, roots)
|
||||
if scope is not None:
|
||||
return scope
|
||||
command = str(item.get('command') or '').casefold()
|
||||
flags = ('--verify-worker', '--repair-worker', '--management-worker', '--native-backup-worker')
|
||||
if any(flag in command for flag in flags):
|
||||
return True # An unreadable in-flight request is not proof of another library.
|
||||
from .failed_session import _command_args
|
||||
try:
|
||||
return any(Path(arg).name.casefold() in ('close_failed_block.vbs', 'save_verified_block.vbs')
|
||||
for arg in _command_args(command)[1:])
|
||||
except (OSError, ValueError):
|
||||
return False
|
||||
|
||||
|
||||
def _enter_maintenance(lease):
|
||||
"""Transfer only a valid known lease, after project admission under lock."""
|
||||
import win32con, win32event, win32file
|
||||
@@ -466,14 +496,21 @@ def _prove_library_released(library, block_name=None, *, allow_unknown_checkpoin
|
||||
shared_root = Path(library).resolve().parent/'SymbolLibs'
|
||||
if allow_unknown_checkpoint and scope_root is not None:
|
||||
raise LibraryBusy('未知检查点必须执行完整库释放证明。')
|
||||
observed = []
|
||||
def check_owners():
|
||||
owners = []
|
||||
observed.clear()
|
||||
from .session_record import active_write_records
|
||||
if active_write_records(library):
|
||||
raise LibraryBusy('本库原生调用或助手尚未确认返回,请等待当前操作结束。')
|
||||
for item in query_owners(names):
|
||||
if item['pid'] == os.getpid():
|
||||
continue
|
||||
if not allow_unknown_checkpoint:
|
||||
roots = (scope_root, shared_root) if scope_root is not None else (Path(library).parent,)
|
||||
if _owner_matches_scope(item, library, roots) is False:
|
||||
if not _owner_is_blocking(item, library, roots):
|
||||
if _owner_matches_scope(item, library, roots) is None:
|
||||
observed.append(item)
|
||||
continue
|
||||
automation = item['name'].casefold() in ('python.exe', 'pythonw.exe', 'cbbrefreshverify.exe')
|
||||
command = item['command'].casefold()
|
||||
@@ -513,7 +550,8 @@ def _prove_library_released(library, block_name=None, *, allow_unknown_checkpoin
|
||||
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,
|
||||
yield {'native_owners': owners, 'observed_owners': list(observed),
|
||||
'addresses': addresses, 'export_copies': export_copies,
|
||||
'unknown_checkpoint_recovery': allow_unknown_checkpoint,
|
||||
'exclusive_files': [str(path) for path in native]}
|
||||
finally:
|
||||
|
||||
Reference in new issue
Block a user