fix: preserve catalog state and verify PCB write access

This commit is contained in:
阿白叔 committed 2026-11-20 23:24:47 +08:00
1 parent 3efeaed656
commit 86837155ea
11 files changed
+651 -92

No files matched your search

+12 -5
View File
@@ -245,13 +245,17 @@ class NativeManagementAdapter:
if hasattr(worker, 'bind_session'):
worker.bind_session(job)
from contextlib import nullcontext
from .operation_queue import commit_worker_start, native_channel
from .operation_queue import commit_worker_start, native_channel, task_stop
# Only admitted native waiting outlives the UI's metadata deadline.
channel = native_channel(read_only=True) if job.get('worker_role') == 'catalog_readonly' else nullcontext()
read_only = job.get('worker_role') == 'catalog_readonly'
channel = native_channel(read_only=True) if read_only else nullcontext()
stop = task_stop(self.stop) if read_only else self.stop
cancelled = False
with channel:
commit_worker_start(worker, job)
while worker.poll() is None and time.monotonic() < deadline:
if self.stop is not None and self.stop.is_set():
if stop is not None and stop.is_set():
cancelled = True
Path(job['cancel_signal']).touch()
break
time.sleep(.1)
@@ -268,8 +272,9 @@ class NativeManagementAdapter:
if self.session_progress is not None else None)
if add_job:
(evidence/'cancel-native-add.signal').touch()
reason = 'CANCELLED' if cancelled else 'TIMEOUT'
return {'success': False, 'safe_to_continue': False,
'detail': f'TIMEOUT: 原生调用尚未返回,保留私有桌面 {desktop},请检查 {evidence}'}
'detail': f'{reason}: 原生调用尚未返回,保留私有桌面 {desktop},请检查 {evidence}'}
try:
result = json.loads((evidence/'result.json').read_text(encoding='utf-8'))
if not isinstance(result.get('safe_to_continue'), bool):
@@ -1117,7 +1122,7 @@ def _catalog_com(job, root):
if name != job['desktop'] or not name.startswith('CbbManagement_'):
raise RuntimeError('拒绝在非本次私有桌面读取原生目录。')
if _process_details('LibraryManager.exe'):
raise RuntimeError('已有 Library Manager 运行,请关闭后重试。')
raise RuntimeError('LIBRARY_MANAGER_BUSY: 已有 Library Manager 运行,请关闭后重试。')
except Exception as error:
error.safe_to_continue = True
raise
@@ -1217,6 +1222,8 @@ def _catalog_com(job, root):
for i in range(1, int(parts.Count) + 1):
partition = parts.Item(i)
for j in range(1, int(partition.Count) + 1):
if job.get('worker_role') == 'catalog_readonly':
_require_management_continuation(job, root)
item = partition.Item(j)
block_name, partition_name = str(item.Name), str(item.PartitionName)
validate_name(block_name)