fix: narrow cross-item and cross-library blockers
This commit is contained in:
1 parent
53118bae19
commit
aea6192ef9
8 files changed
+178
-15
No files matched your search
@@ -315,7 +315,7 @@ def owned_snapshot(path):
|
||||
|
||||
|
||||
@contextmanager
|
||||
def _prove_library_released(library):
|
||||
def _prove_library_released(library, block_name=None):
|
||||
"""Hold all native database read handles during explicit lease release."""
|
||||
import win32con, win32file
|
||||
from .owner_probe import query_owners
|
||||
@@ -333,11 +333,16 @@ def _prove_library_released(library):
|
||||
'iCDBProjectBackup.exe', 'ReuseBlockImporter.exe', 'CleanWGLib.exe',
|
||||
'cscript.exe', 'wscript.exe', 'python.exe', 'pythonw.exe',
|
||||
'CbbRefreshVerify.exe', *sorted(_OWNER_NAMES))
|
||||
scope_root = (Path(library).resolve().parent/'ReusableBlocksLP'/block_name/'Work').resolve() if block_name else None
|
||||
def check_owners():
|
||||
owners = []
|
||||
for item in query_owners(names):
|
||||
if item['pid'] == os.getpid():
|
||||
continue
|
||||
if scope_root is not None and item.get('command'):
|
||||
command = str(item['command']).casefold().replace('/', '\\')
|
||||
if str(scope_root).casefold().replace('/', '\\') not in command:
|
||||
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 (
|
||||
@@ -348,11 +353,14 @@ def _prove_library_released(library):
|
||||
return owners
|
||||
check_owners()
|
||||
entries = scan_tree(Path(library).parent)
|
||||
addresses = [str(path) for path in entries if path.name.casefold() == 'saddress.adr']
|
||||
addresses = [str(path) for path in entries if path.name.casefold() == 'saddress.adr'
|
||||
and (scope_root is None or path.resolve().is_relative_to(scope_root))]
|
||||
if addresses:
|
||||
raise LibraryBusy(f'库中仍有数据库地址记录,不能自动解除:{addresses}')
|
||||
native = [path for path in entries if path.is_file()
|
||||
and (path.suffix.casefold() == '.lmc' or path.name.casefold() in ('icdb.dat', 'layoutdb.lyt'))]
|
||||
native = [path for path in entries if path.is_file() and (
|
||||
path.suffix.casefold() == '.lmc'
|
||||
or (path.name.casefold() in ('icdb.dat', 'layoutdb.lyt')
|
||||
and (scope_root is None or path.resolve().is_relative_to(scope_root))))]
|
||||
if Path(library).resolve() not in native:
|
||||
raise LibraryBusy('目标库身份缺失,不能解除协调阻止。')
|
||||
with ExitStack() as stack:
|
||||
@@ -368,7 +376,7 @@ def _prove_library_released(library):
|
||||
uninitialize_com(initialized)
|
||||
|
||||
|
||||
def release_retained_library(library, evidence_dir):
|
||||
def release_retained_library(library, evidence_dir, *, block_name=None):
|
||||
"""Explicit user-requested release, after fresh owner/address/access proof.
|
||||
|
||||
The upload sidecar is never deleted. This acknowledges process release,
|
||||
@@ -398,7 +406,9 @@ def release_retained_library(library, evidence_dir):
|
||||
win32con.OPEN_ALWAYS, win32con.FILE_ATTRIBUTE_NORMAL, None)
|
||||
except Exception as error:
|
||||
raise LibraryBusy('其他进程仍持有库锁,不能解除。') from error
|
||||
with _prove_library_released(library) as proof:
|
||||
proof_context = (_prove_library_released(library, block_name=block_name)
|
||||
if block_name else _prove_library_released(library))
|
||||
with proof_context as proof:
|
||||
marker = blocker_path(library)
|
||||
checkpoints = (marker, marker.with_suffix('.pending'))
|
||||
if any(path.exists() and checkpoint_record(path) is None for path in checkpoints):
|
||||
|
||||
Reference in new issue
Block a user