diff --git a/homeassistant/backup_restore.py b/homeassistant/backup_restore.py index f9250e3129e..57e1c734dfc 100644 --- a/homeassistant/backup_restore.py +++ b/homeassistant/backup_restore.py @@ -64,6 +64,9 @@ def restore_backup_file_content(config_dir: Path) -> RestoreBackupFileContent | ) except (FileNotFoundError, KeyError, json.JSONDecodeError): return None + finally: + # Always remove the backup instruction file to prevent a boot loop + instruction_path.unlink(missing_ok=True) def _clear_configuration_directory(config_dir: Path, keep: Iterable[str]) -> None: diff --git a/tests/test_backup_restore.py b/tests/test_backup_restore.py index bce5eca4292..10ea64a6a61 100644 --- a/tests/test_backup_restore.py +++ b/tests/test_backup_restore.py @@ -57,11 +57,14 @@ def test_reading_the_instruction_contents( return_value=content, side_effect=side_effect, ), + mock.patch("pathlib.Path.unlink", autospec=True) as unlink_mock, ): - read_content = backup_restore.restore_backup_file_content( - Path(get_test_config_dir()) - ) + config_path = Path(get_test_config_dir()) + read_content = backup_restore.restore_backup_file_content(config_path) assert read_content == expected + unlink_mock.assert_called_once_with( + config_path / ".HA_RESTORE", missing_ok=True + ) def test_restoring_backup_that_does_not_exist() -> None: