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):
|
||||
|
||||
@@ -13,8 +13,9 @@ import stat
|
||||
from uuid import uuid4
|
||||
|
||||
|
||||
def assert_native_idle():
|
||||
def assert_native_idle(target=None):
|
||||
from .owner_probe import query_owners
|
||||
from .failed_session import _command_args
|
||||
from .native_management import _retained_workers
|
||||
from .native_export_guard import assert_retained_exports_idle
|
||||
from .native_engineering_identity import _OWNER_NAMES
|
||||
@@ -33,10 +34,28 @@ def assert_native_idle():
|
||||
if not automation or not command or any(flag in command for flag in (
|
||||
'--verify-worker', '--repair-worker', '--management-worker')):
|
||||
owners.append(item)
|
||||
if target is not None:
|
||||
expected = os.path.normcase(os.path.abspath(str(target.project)))
|
||||
scoped = []
|
||||
for item in owners:
|
||||
command = str(item.get('command') or '')
|
||||
if not command:
|
||||
scoped.append(item)
|
||||
elif expected in [os.path.normcase(os.path.abspath(arg)) for arg in _command_args(command)[1:]]:
|
||||
scoped.append(item)
|
||||
owners = scoped
|
||||
if owners:
|
||||
raise ValueError(f'MAINTENANCE_OWNER_ACTIVE: 请正常关闭原生程序/操作助手:{owners}')
|
||||
|
||||
|
||||
def _assert_native_idle_for(target):
|
||||
"""Keep test/third-party zero-argument idle probes compatible."""
|
||||
import inspect
|
||||
if not inspect.signature(assert_native_idle).parameters:
|
||||
return assert_native_idle()
|
||||
return assert_native_idle(target)
|
||||
|
||||
|
||||
def address_snapshot(paths):
|
||||
from .scoped_manifest import hash_file
|
||||
return {str(path.resolve()): {'sha256': hash_file(path), 'size': path.stat().st_size,
|
||||
@@ -173,7 +192,7 @@ def maintenance_target_guard(request, expected=None, *, stop=None):
|
||||
for p in (pcb, *maintenance_project_files(project, pcb))}}
|
||||
if expected is not None and context != expected:
|
||||
raise ValueError('MAINTENANCE_SOURCE_CHANGED: 目标或地址记录在检查后变化')
|
||||
assert_native_idle()
|
||||
_assert_native_idle_for(target)
|
||||
check()
|
||||
def native_files(snapshot):
|
||||
return {path for path, info in snapshot.items() if stat.S_ISREG(info.st_mode) and (
|
||||
@@ -185,7 +204,7 @@ def maintenance_target_guard(request, expected=None, *, stop=None):
|
||||
handle = win32file.CreateFile(str(path), win32con.GENERIC_READ, 0, None,
|
||||
win32con.OPEN_EXISTING, win32con.FILE_ATTRIBUTE_NORMAL, None)
|
||||
stack.callback(handle.Close)
|
||||
assert_native_idle()
|
||||
_assert_native_idle_for(target)
|
||||
current = maintenance_entries(request, check=check)
|
||||
if native_files(current) != files:
|
||||
raise ValueError('MAINTENANCE_SOURCE_CHANGED: 检查期间库文件集合发生变化')
|
||||
@@ -411,7 +430,7 @@ def run_existing_address_maintenance(request, *, diagnosed_target, startup_resul
|
||||
recovery = run_native_repair(target, native_root, mentor_bin=request.mentor_bin,
|
||||
timeout_seconds=max(60, request.timeout_seconds), progress=native_event,
|
||||
maintenance_context=context, stop=stop)
|
||||
assert_native_idle()
|
||||
_assert_native_idle_for(target)
|
||||
recovery = {**recovery, 'native_status': recovery.get('status'), 'validation_passed': False}
|
||||
recovery['release'] = repair_release_state(request, target, recovery)
|
||||
safe = recovery['release'].get('safe_to_continue') is True
|
||||
|
||||
@@ -50,7 +50,12 @@ def run_reimport_recovery(requests, *, previous_evidence, evidence_dir,
|
||||
stage = 'release_check'
|
||||
save(stage)
|
||||
if progress: progress({'stage': stage, 'detail': '正在检查原生会话释放,尚未替换条目'})
|
||||
proof = release_retained_library(library, root/'release')
|
||||
import inspect
|
||||
block_name = requests[0].name if len(requests) == 1 else None
|
||||
if 'block_name' in inspect.signature(release_retained_library).parameters:
|
||||
proof = release_retained_library(library, root/'release', block_name=block_name)
|
||||
else:
|
||||
proof = release_retained_library(library, root/'release')
|
||||
if proof.get('status') != 'RELEASE_CONFIRMED':
|
||||
raise ValueError('原生会话释放未确认,未开始导入。')
|
||||
save('released', release=proof)
|
||||
|
||||
@@ -12,6 +12,14 @@ from PySide6.QtWidgets import (QWidget, QLineEdit, QPushButton, QFormLayout,
|
||||
QTableWidget, QTableWidgetItem, QHeaderView, QCheckBox, QVBoxLayout, QProgressBar, QComboBox,
|
||||
QTabBar, QStackedWidget, QSizePolicy)
|
||||
from PySide6.QtWidgets import QStyle
|
||||
|
||||
|
||||
def _path_key(value):
|
||||
"""Compare local and unavailable UNC paths without touching the network."""
|
||||
raw = str(value or '')
|
||||
if not raw:
|
||||
return ''
|
||||
return os.path.normcase(os.path.normpath(os.path.abspath(raw)))
|
||||
try:
|
||||
from dx_productivity.trial_task_center.ui.workers import ServiceWorker
|
||||
except ImportError:
|
||||
@@ -66,6 +74,8 @@ class MainWindow(QWidget):
|
||||
self.management_adapter = management_adapter or NativeManagementAdapter()
|
||||
self.management_capabilities = self.management_adapter.capabilities()
|
||||
self._management_unsafe = False
|
||||
self._management_unsafe_library = None
|
||||
self._management_operation_library = None
|
||||
self._maintenance_recovery_view = False
|
||||
self._reload_after_maintenance = False
|
||||
self._reimport_offers = ()
|
||||
@@ -319,8 +329,10 @@ class MainWindow(QWidget):
|
||||
if reason:
|
||||
reasons.append(reason)
|
||||
self.management_capability_label.setText('\n'.join(dict.fromkeys(reasons)))
|
||||
current_library = _path_key(self.mentor_lmc_path or self.lmc_edit.text()) if self.lmc_edit.text().strip() else None
|
||||
notice = ('上次管理操作尚未确认安全释放,请检查该操作的结果。'
|
||||
if self._management_unsafe else '')
|
||||
if (self._management_unsafe and self._management_unsafe_library is not None
|
||||
and current_library == _path_key(self._management_unsafe_library)) else '')
|
||||
self.library_notice.setText(notice)
|
||||
self.library_notice.setVisible(bool(notice))
|
||||
for widget in (self.lmc_edit, self.browse_button, self.load_button, self.cbb_table,
|
||||
@@ -362,20 +374,36 @@ class MainWindow(QWidget):
|
||||
if library.is_dir():
|
||||
library = select_library_file(library)
|
||||
def completed(result):
|
||||
self._management_unsafe = False
|
||||
current_library = _path_key(self.mentor_lmc_path or self.lmc_edit.text().strip())
|
||||
if current_library == _path_key(library):
|
||||
self._management_unsafe = False
|
||||
self._management_unsafe_library = None
|
||||
session = self._native_backup_session
|
||||
if session is not None and session.library == library and session.process.poll() is not None:
|
||||
self._release_native_backup_session(session)
|
||||
message = f'原生会话释放检查通过。请审查未完成任务后重新读取中心库。\n{result["evidence_path"]}'
|
||||
self.status_label.setText(message); self.output.append(message)
|
||||
self._start(lambda: release_retained_library(library, self.data_root/'release-checks'), completed)
|
||||
block_name = None
|
||||
if len(self._batch_requests) == 1:
|
||||
block_name = self._batch_requests[0].block_name
|
||||
elif len(self.selected_records()) == 1:
|
||||
block_name = self.selected_records()[0].name
|
||||
import inspect
|
||||
if 'block_name' in inspect.signature(release_retained_library).parameters:
|
||||
action = lambda: release_retained_library(library, self.data_root/'release-checks',
|
||||
block_name=block_name)
|
||||
else:
|
||||
action = lambda: release_retained_library(library, self.data_root/'release-checks')
|
||||
self._start(action, completed)
|
||||
|
||||
def _management_block_reason(self, operation):
|
||||
if self.busy:
|
||||
return '当前任务尚未结束,请等待后再执行库管理操作。'
|
||||
if self._native_backup_same_library():
|
||||
return '该库的版本与备份窗口仍在使用,关闭后可执行写入操作。'
|
||||
if self._management_unsafe:
|
||||
current_library = _path_key(self.mentor_lmc_path or self.lmc_edit.text()) if self.lmc_edit.text().strip() else None
|
||||
if (self._management_unsafe and self._management_unsafe_library is not None
|
||||
and current_library == _path_key(self._management_unsafe_library)):
|
||||
return '上次管理操作的会话尚未安全释放,请先查看异常证据并执行释放检查。'
|
||||
capability = self.management_capabilities[operation]
|
||||
if not capability.supported:
|
||||
@@ -411,6 +439,7 @@ class MainWindow(QWidget):
|
||||
self._global_icdb_run = False
|
||||
self.stop.clear()
|
||||
self._management_is_recovery = bool(recovery_from)
|
||||
self._management_operation_library = _path_key(requests[0].library) if requests else None
|
||||
self.management_dialog = ManagementDialog(requests, self, adapter=self.management_adapter,
|
||||
recovery_from=recovery_from)
|
||||
self._management_results = []
|
||||
@@ -444,6 +473,7 @@ class MainWindow(QWidget):
|
||||
if (getattr(self, '_management_is_recovery', False) and results
|
||||
and all(result.safe_to_continue for result in results)):
|
||||
self._management_unsafe = False
|
||||
self._management_unsafe_library = None
|
||||
self._maintenance_recovery_view = False
|
||||
restored = {result.name for result in results if result.status == 'UPLOADED_VERIFIED'}
|
||||
self._reimport_offers = tuple(offer for offer in self._reimport_offers if offer[1].name not in restored)
|
||||
@@ -455,6 +485,7 @@ class MainWindow(QWidget):
|
||||
self.output.append('副本恢复校验通过,版本待核对。')
|
||||
if any(not result.safe_to_continue for result in results):
|
||||
self._management_unsafe = True
|
||||
self._management_unsafe_library = self._management_operation_library
|
||||
if self.library_lease:
|
||||
self.library_lease.retain_for_recovery()
|
||||
self.status_label.setText('管理操作需要人工确认恢复/释放;已停止写入,未再次读取原生目录。')
|
||||
@@ -541,6 +572,11 @@ class MainWindow(QWidget):
|
||||
if self.busy or not self.lmc_edit.text(): return
|
||||
self._maintenance_recovery_view = False
|
||||
self._global_icdb_run = False
|
||||
if self._management_unsafe_library is not None:
|
||||
requested_library = _path_key(self.lmc_edit.text())
|
||||
if requested_library != _path_key(self._management_unsafe_library):
|
||||
self._management_unsafe = False
|
||||
self._management_unsafe_library = None
|
||||
self.icdb_progress.hide(); self.icdb_phase.hide()
|
||||
self._release_library_lease()
|
||||
self.loaded_path = None; self.cbb_table.setRowCount(0); self._row_by_name = {}; self.ready_names = set()
|
||||
|
||||
Reference in new issue
Block a user