Peach: Local-first video metadata scraper and media manager.
fix(settings): 重读短暂占用的源码改字状态
longmeidaobb902aa8e63d
diff --git a/src/peach/dev_copy_runtime.py b/src/peach/dev_copy_runtime.pyindex aa67f3cf6..19e077697 100644--- a/src/peach/dev_copy_runtime.py+++ b/src/peach/dev_copy_runtime.py@@ -32,9 +32,22 @@ def _write(root: Path, data: dict) -> dict:return data+def _read_status(path: Path) -> dict:+ """Windows 原子替换期间短暂占用可重读;持续拒绝访问仍交给调用方。"""+ for attempt in range(5):+ try:+ return json.loads(path.read_text(encoding='utf-8'))+ except FileNotFoundError:+ return {}+ except PermissionError:+ if attempt == 4:+ raise+ time.sleep(.02)+ return {}++def status(root: Path) -> dict:- path = _directory(root) / 'apply.json'- data = json.loads(path.read_text(encoding='utf-8')) if path.exists() else {}+ data = _read_status(_directory(root) / 'apply.json')if data.get('state') in ACTIVE:if data['state'] == 'waiting_restart':if time.time() - data['updated'] > 30:diff --git a/tests/test_dev_copy.py b/tests/test_dev_copy.pyindex c683492d2..b513b6e33 100644--- a/tests/test_dev_copy.py+++ b/tests/test_dev_copy.py@@ -11,6 +11,20 @@ from peach import dev_copyclass DevCopyTests(unittest.TestCase):+ def test_status_recovers_from_a_short_read_lock_and_preserves_persistent_denial(self):+ from peach import dev_copy_runtime as runtime+ with tempfile.TemporaryDirectory() as tmp:+ root = Path(tmp).resolve()+ with patch.object(Path, 'read_text', side_effect=[PermissionError('sharing'), '{"state":"ready"}']), \+ patch.object(runtime.time, 'sleep') as sleep:+ self.assertEqual(runtime.status(root)['state'], 'ready')+ sleep.assert_called_once()+ with patch.object(Path, 'read_text', side_effect=PermissionError('denied')) as read, \+ patch.object(runtime.time, 'sleep') as sleep, self.assertRaises(PermissionError):+ runtime.status(root)+ self.assertEqual(read.call_count, 5)+ self.assertEqual(sleep.call_count, 4)+def test_static_text_can_be_deleted_and_dynamic_placeholders_are_required(self):with tempfile.TemporaryDirectory() as tmp:root = Path(tmp).resolve()