Validate installation state before prefill and resume

This commit is contained in:
ICUMADETHIS committed 2026-11-22 08:05:04 +00:00
1 parent afae80c908
commit 83831e8ebd
3 files changed
+78 -2

No files matched your search

+15 -2
View File
@@ -36,10 +36,23 @@ def load(dest):
data = json.loads(path.read_text(encoding='utf-8'))
except (OSError, ValueError):
raise StateError('state.unreadable', path) from None
if not isinstance(data, dict) or not isinstance(data.get('steps'), dict):
if not isinstance(data, dict):
raise StateError('state.unreadable', path)
if data.get('format', 0) > FORMAT:
version = data.get('format', 0)
if type(version) is not int or version < 0:
raise StateError('state.unreadable', path)
if version > FORMAT:
raise StateError('state.newer_format', path)
# The GUI and resume planner read these fields before running a step. A JSON value of the wrong type must take
# the same error path as unreadable JSON, rather than raising from their comparisons or dict lookups.
for name in ('release', 'lang', 'version'):
if name in data and not isinstance(data[name], str):
raise StateError('state.unreadable', path)
for name in ('steps', 'inputs'):
records = data.get(name, {} if name == 'inputs' else None)
if not isinstance(records, dict) or any(not isinstance(record, dict) for record in records.values()):
raise StateError('state.unreadable', path)
data.setdefault('inputs', {}) # older records may omit it; the extraction step expects a dictionary
return data