fix: reject native source renames before management writes
This commit is contained in:
1 parent
36ff964230
commit
d40fa3a750
7 files changed
+102
-20
No files matched your search
@@ -308,12 +308,29 @@ class NativeManagementAdapter:
|
||||
removal_input(request.name, request.partition)
|
||||
if request.partition != 'Logical-Physical' or catalog.flow != 1:
|
||||
raise ValueError('仅验证了 DxDesigner / Logical-Physical 管理操作。')
|
||||
self.validate_source(request)
|
||||
|
||||
def validate_source(self, request):
|
||||
if request.operation not in ('add', 'update'):
|
||||
return
|
||||
if request.source is None:
|
||||
raise ValueError('请选择完整来源工程。')
|
||||
source = Path(request.source).resolve(strict=True)
|
||||
if not source.is_file() or source.suffix.casefold() != '.prj':
|
||||
raise ValueError('请选择完整来源工程的 PRJ 文件。')
|
||||
if source.stem.casefold() != request.name.casefold():
|
||||
raise ValueError(f'SOURCE_NAME_MISMATCH: 来源工程名 {source.stem} 与目标 {request.name} 不一致;'
|
||||
'当前版本不支持改名,请重新选择同名 PRJ。')
|
||||
|
||||
def add(self, request, evidence):
|
||||
# Route readiness never grants production mutation authority.
|
||||
capability = self.capabilities()['add']
|
||||
if not capability.supported:
|
||||
return NativeOutcome(False, True, capability.reason, evidence_path=Path(evidence))
|
||||
try:
|
||||
self.validate_source(request)
|
||||
except (OSError, ValueError) as error:
|
||||
return NativeOutcome(False, True, str(error), evidence_path=Path(evidence))
|
||||
return self._add_transaction(request, Path(evidence))
|
||||
|
||||
def prepare_add_transaction(self, request, root, *, original_source):
|
||||
@@ -323,6 +340,7 @@ class NativeManagementAdapter:
|
||||
from .management import source_project
|
||||
from .backup_recovery import _align_library
|
||||
try:
|
||||
self.validate_source(request)
|
||||
if not self.capabilities()['add'].supported:
|
||||
raise ValueError(self.capabilities()['add'].reason)
|
||||
validate_native_copy_paths(request.source, request.library, request.name)
|
||||
@@ -450,6 +468,7 @@ class NativeManagementAdapter:
|
||||
return NativeOutcome(False, True, 'Native Add requires an existing staged PRJ source project.',
|
||||
evidence_path=evidence)
|
||||
try:
|
||||
self.validate_source(request)
|
||||
source_identity = engineering_identity(source)
|
||||
except (ValueError, OSError) as error:
|
||||
return NativeOutcome(False, True, f'Unable to read source engineering identity: {error}',
|
||||
@@ -694,11 +713,11 @@ def _dispatch_diagnostics(root, stage, app, library, *, paths=None):
|
||||
stream.write(json.dumps(record, ensure_ascii=False, default=str) + '\n')
|
||||
|
||||
|
||||
def _set_probe_field(hwnd, control_id, expected, root):
|
||||
"""Set/read a remote Edit with a one-second total message budget."""
|
||||
def _set_probe_field(hwnd, control_id, expected, root, *, read_only=False):
|
||||
"""Set/read or revalidate a remote Edit with a one-second total message budget."""
|
||||
from ctypes import wintypes
|
||||
record = {'control_id': control_id, 'hwnd': int(hwnd), 'expected': expected,
|
||||
'actual': None, 'matched': False}
|
||||
'actual': None, 'matched': False, 'read_only': read_only}
|
||||
deadline = time.monotonic() + 1.0
|
||||
try:
|
||||
user32 = ctypes.WinDLL('user32', use_last_error=True)
|
||||
@@ -715,9 +734,10 @@ def _set_probe_field(hwnd, control_id, expected, root):
|
||||
remaining, ctypes.byref(returned)):
|
||||
raise TimeoutError(f'原生字段消息超时或失败:{control_id}, Windows={ctypes.get_last_error()}')
|
||||
return returned.value
|
||||
text = ctypes.create_unicode_buffer(expected)
|
||||
if not message(0x000C, 0, text): # WM_SETTEXT
|
||||
raise RuntimeError(f'原生字段拒绝写入:{control_id}')
|
||||
if not read_only:
|
||||
text = ctypes.create_unicode_buffer(expected)
|
||||
if not message(0x000C, 0, text): # WM_SETTEXT
|
||||
raise RuntimeError(f'原生字段拒绝写入:{control_id}')
|
||||
buffer = ctypes.create_unicode_buffer(32768)
|
||||
copied = message(0x000D, len(buffer), buffer) # WM_GETTEXT, remote Edit marshalled by Windows.
|
||||
record['actual'] = buffer.value
|
||||
@@ -851,6 +871,9 @@ def _probe_add_dialog_impl(app, job, desktop, owned_pids, root, *, library=None)
|
||||
if not hwnd or win32gui.GetClassName(hwnd) != 'Edit':
|
||||
raise RuntimeError(f'原生新增字段身份不匹配:{control}')
|
||||
_set_probe_field(hwnd, control, value, root)
|
||||
# Changing source/top fields can make Mentor derive a different name.
|
||||
for control, value in fields.items():
|
||||
_set_probe_field(win32gui.GetDlgItem(dialog, control), control, value, root, read_only=True)
|
||||
_write_json(root/'submitted-fields.json', fields)
|
||||
ok = win32gui.GetDlgItem(dialog, 1083)
|
||||
if not ok:
|
||||
|
||||
Reference in new issue
Block a user