367 files, from working commit b1a079a. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
45 lines
1.5 KiB
Python
45 lines
1.5 KiB
Python
"""Select the existing engine journal, or an explicitly isolated Windows one."""
|
|
import json
|
|
import os
|
|
from pathlib import Path
|
|
|
|
|
|
def is_windows():
|
|
return os.name == 'nt'
|
|
|
|
|
|
def engine_journal(root):
|
|
root = Path(root)
|
|
if is_windows():
|
|
profile = root / 'compat/windows-native.json'
|
|
if profile.exists():
|
|
scope = json.loads(profile.read_text()).get('runtime_journal_scope')
|
|
if scope == 'windows-isolated-v1':
|
|
return root / 'runtime/windows-native-engine-pe.json'
|
|
if scope is not None:
|
|
raise ValueError('Unsupported Windows engine journal scope')
|
|
return root / 'runtime/native-engine-pe.json'
|
|
|
|
|
|
def state_directory(root):
|
|
root = Path(root)
|
|
if engine_journal(root).name == 'windows-native-engine-pe.json':
|
|
return root / 'runtime/windows-state'
|
|
return root / 'runtime'
|
|
|
|
|
|
def state_file(root, name):
|
|
if not isinstance(name, str) or not name or Path(name).name != name or name in ('.', '..'):
|
|
raise ValueError('Single runtime receipt filename required')
|
|
return state_directory(root) / name
|
|
|
|
|
|
def prepare_state_directory(root):
|
|
directory = state_directory(root)
|
|
if directory.is_symlink():
|
|
raise ValueError('Runtime state directory must not be a symlink')
|
|
directory.mkdir(mode=0o700, exist_ok=True)
|
|
if not directory.is_dir() or directory.is_symlink():
|
|
raise ValueError('Owned runtime state directory required')
|
|
return directory
|