fix: inspect addressless ICDB projects and ask for PCB recovery version
This commit is contained in:
1 parent
c85696080d
commit
de952a68d6
11 files changed
+558
-22
No files matched your search
@@ -1,7 +1,7 @@
|
||||
"""User-requested native inspection of a project with an existing advertisement.
|
||||
"""User-requested native inspection with or without an existing advertisement.
|
||||
|
||||
An advertisement is never deleted, quarantined or called stale by this module.
|
||||
Exclusive access permits a backed-up official inspection, not ordinary Verify.
|
||||
Exclusive access and exact project binding permit an official inspection.
|
||||
"""
|
||||
from contextlib import contextmanager, ExitStack
|
||||
from dataclasses import asdict, replace
|
||||
@@ -34,7 +34,8 @@ def assert_native_idle():
|
||||
automation = name in ('python.exe', 'pythonw.exe', 'cbbrefreshverify.exe')
|
||||
if not automation or not command or any(flag in command for flag in (
|
||||
'--verify-worker', '--repair-worker', '--management-worker')):
|
||||
owners.append({'pid': int(item.ProcessId), 'name': str(item.Name)})
|
||||
owners.append({'pid': int(item.ProcessId), 'name': str(item.Name),
|
||||
'command': str(item.CommandLine or '')})
|
||||
if owners:
|
||||
raise ValueError(f'MAINTENANCE_OWNER_ACTIVE: 请正常关闭原生程序/操作助手:{owners}')
|
||||
|
||||
@@ -113,6 +114,15 @@ def select_maintenance_target(request):
|
||||
raise ValueError('MAINTENANCE_TARGET_UNCONFIRMED: 缺少 icdb.dat')
|
||||
candidates.append(RepairTarget(candidate, candidate.parent/'database'))
|
||||
addresses = _scoped_addresses(request)
|
||||
if not addresses:
|
||||
# A crashed project may retain its internal open state after the server
|
||||
# advertisement disappears. Explicit maintenance must still inspect it.
|
||||
references = re.findall(r'^KEY ProjectFile "([^"\r\n]+)"', _project_text(pcb), re.M)
|
||||
if len(references) != 1 or (pcb.parent/references[0]).resolve() != project.resolve():
|
||||
raise ValueError('MAINTENANCE_TARGET_UNCONFIRMED: PCB 的 ProjectFile 未唯一指向所选主工程')
|
||||
if len(candidates) != 1:
|
||||
raise ValueError('MAINTENANCE_TARGET_UNCONFIRMED: 无地址记录且存在多个工程数据库,不能推测修复目标')
|
||||
return candidates[0], project, pcb, addresses
|
||||
if len(addresses) != 1:
|
||||
raise ValueError('MAINTENANCE_TARGET_UNCONFIRMED: 需要唯一工程地址记录;共享或多个数据库不能推测修复')
|
||||
matches = [target for target in candidates
|
||||
@@ -153,6 +163,10 @@ def maintenance_target_guard(request, expected=None):
|
||||
|
||||
|
||||
def maintenance_needed(request):
|
||||
# An explicit maintenance request must reach native inspection even when
|
||||
# no address/checkpoint remains. Selection and ownership are guarded later.
|
||||
if request.maintenance is True:
|
||||
return True
|
||||
from .library_lock import has_blocker
|
||||
from .icdb_ownership import unreleased_addresses
|
||||
from .verify_runner import preflight
|
||||
@@ -198,8 +212,8 @@ def run_existing_address_maintenance(request, *, verify, progress=None):
|
||||
json.dump({'intent': 'explicit_maintenance', 'target': asdict(target),
|
||||
'maintenance_context': context}, stream, default=str, ensure_ascii=False)
|
||||
emit('native_repair_start', detail='核对占用后由官方工具检查/修复;应用不自动备份')
|
||||
# Repeat immediately before dispatch; worker repeats after complete
|
||||
# backup and before launching its native process as well.
|
||||
# Repeat immediately before dispatch; the worker repeats before
|
||||
# launching the native process as well.
|
||||
with maintenance_target_guard(request, context): pass
|
||||
recovery = run_native_repair(target, native_root, mentor_bin=request.mentor_bin,
|
||||
timeout_seconds=max(60, request.timeout_seconds), progress=progress,
|
||||
@@ -227,6 +241,17 @@ def run_existing_address_maintenance(request, *, verify, progress=None):
|
||||
good = verified.status == 'PASS' and verified.library_flag == 'GREEN' and owner_safe
|
||||
recovery.update(status='REPAIRED' if good else 'REPAIR_VALIDATION_FAILED',
|
||||
validation_passed=good, validation_evidence=str(verified.evidence_path or ''))
|
||||
if good and verified.evidence_path:
|
||||
restored = Path(verified.evidence_path).parent/'pcb-version-restoration.json'
|
||||
if restored.exists():
|
||||
version = json.loads(restored.read_text(encoding='utf-8'))
|
||||
if (version.get('confirm_sent') is not True or version.get('historical_restore') is not True
|
||||
or Path(version['project']).resolve() != checked['project'].resolve()
|
||||
or version.get('choice') not in ('last_user_saved', 'autosave')):
|
||||
raise ValueError('PCB_VERSION_RESTORATION_EVIDENCE_INVALID')
|
||||
recovery.update(status='RESTORED_REVIEW_REQUIRED', pcb_version=version)
|
||||
verified = replace(verified, stdout=verified.stdout +
|
||||
f'\n已按用户选择恢复 PCB({version["date"]})并通过校验;版本待核对。')
|
||||
if verified.error_category == 'PCB_VERSION_CHOICE_REQUIRED':
|
||||
owner_safe = False
|
||||
good = False
|
||||
|
||||
Reference in new issue
Block a user