fix: admit linked legacy ICDB projects and explain blocked actions
This commit is contained in:
1 parent
5eac654c36
commit
d36b6bcad0
8 files changed
+138
-18
No files matched your search
@@ -65,6 +65,25 @@ def _scoped_addresses(request):
|
||||
return addresses
|
||||
|
||||
|
||||
def maintenance_project_files(project, pcb):
|
||||
"""A legacy linked PCB need not contain the auxiliary PCB/pcb.prj.
|
||||
|
||||
Its explicit ProjectFile must bind back to the main project. Never guess
|
||||
template.prj (or another PRJ) as an alternative database repair target.
|
||||
"""
|
||||
from .backup_recovery import _project_text
|
||||
project, pcb = Path(project), Path(pcb)
|
||||
auxiliary = pcb.parent/'pcb.prj'
|
||||
if auxiliary.is_file():
|
||||
return project, auxiliary
|
||||
if os.path.lexists(auxiliary):
|
||||
raise ValueError(f'MAINTENANCE_TARGET_UNCONFIRMED: 工程配置不是文件:{auxiliary}')
|
||||
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.prj,且 PCB 的 ProjectFile 未唯一指向当前主工程')
|
||||
return (project,)
|
||||
|
||||
|
||||
def select_maintenance_target(request):
|
||||
from .verify_runner import preflight
|
||||
from .backup_recovery import _project_text
|
||||
@@ -75,7 +94,7 @@ def select_maintenance_target(request):
|
||||
project, pcb = preflight(request)
|
||||
scan_tree(project.parent)
|
||||
candidates = []
|
||||
for candidate in (project, pcb.parent/'pcb.prj'):
|
||||
for candidate in maintenance_project_files(project, pcb):
|
||||
if not candidate.is_file():
|
||||
raise ValueError('MAINTENANCE_TARGET_UNCONFIRMED: 缺少工程配置')
|
||||
text = _project_text(candidate)
|
||||
@@ -114,7 +133,7 @@ def maintenance_target_guard(request, expected=None):
|
||||
'project': str(target.project.resolve()), 'database': str(target.database.resolve()),
|
||||
'addresses': baseline,
|
||||
'engineering_references': {str(p.resolve()): hash_file(p)
|
||||
for p in (project, pcb, pcb.parent/'pcb.prj')}}
|
||||
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()
|
||||
@@ -223,4 +242,4 @@ def run_existing_address_maintenance(request, *, verify, progress=None):
|
||||
except Exception as error:
|
||||
return save(VerifyResult('BLOCKED' if recovery is None else 'FAIL', stderr=str(error),
|
||||
safe_to_continue=False, recovery_attempts=(recovery,) if recovery else (),
|
||||
error_category='ICDB_MAINTENANCE_BLOCKED'))
|
||||
error_category='ICDB_MAINTENANCE_BLOCKED', error_stage=record['stage']))
|
||||
Reference in new issue
Block a user