Fix boot loop after restoring backup (#133581)

This commit is contained in:
Erik Montnemery 2024-12-19 16:04:59 +01:00 committed by GitHub
parent 94c7d18346
commit 255f85eb2f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 9 additions and 3 deletions

View File

@ -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:

View File

@ -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: