Skip to content

Commit

Permalink
Fix boot loop after restoring backup (home-assistant#133581)
Browse files Browse the repository at this point in the history
  • Loading branch information
emontnemery authored Dec 19, 2024
1 parent 94c7d18 commit 255f85e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
3 changes: 3 additions & 0 deletions homeassistant/backup_restore.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
9 changes: 6 additions & 3 deletions tests/test_backup_restore.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 255f85e

Please sign in to comment.