mirror of
https://github.com/home-assistant/supervisor.git
synced 2025-07-09 10:16:29 +00:00
Handle non-existing addon config dir (#5871)
* Handle non-existing addon config dir Since users have access to the root of all add-on config directories, they can delete the directory of an add-ons at any time. Hence we need to handle gracefully if it doesn't exist anymore. * Add pytest
This commit is contained in:
parent
481bbc5be8
commit
39bd20c0e7
@ -1322,8 +1322,8 @@ class Addon(AddonModel):
|
|||||||
arcname="data",
|
arcname="data",
|
||||||
)
|
)
|
||||||
|
|
||||||
# Backup config
|
# Backup config (if used and existing, restore handles this gracefully)
|
||||||
if addon_config_used:
|
if addon_config_used and self.path_config.is_dir():
|
||||||
atomic_contents_add(
|
atomic_contents_add(
|
||||||
backup,
|
backup,
|
||||||
self.path_config,
|
self.path_config,
|
||||||
|
@ -446,6 +446,27 @@ async def test_backup(
|
|||||||
assert await install_addon_ssh.backup(tarfile) is None
|
assert await install_addon_ssh.backup(tarfile) is None
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize("status", ["running", "stopped"])
|
||||||
|
async def test_backup_no_config(
|
||||||
|
coresys: CoreSys,
|
||||||
|
install_addon_ssh: Addon,
|
||||||
|
container: MagicMock,
|
||||||
|
status: str,
|
||||||
|
tmp_supervisor_data,
|
||||||
|
path_extern,
|
||||||
|
) -> None:
|
||||||
|
"""Test backing up an addon with deleted config directory."""
|
||||||
|
container.status = status
|
||||||
|
|
||||||
|
install_addon_ssh.data["map"].append({"type": "addon_config", "read_only": False})
|
||||||
|
assert not install_addon_ssh.path_config.exists()
|
||||||
|
install_addon_ssh.path_data.mkdir()
|
||||||
|
await install_addon_ssh.load()
|
||||||
|
|
||||||
|
tarfile = SecureTarFile(coresys.config.path_tmp / "test.tar.gz", "w")
|
||||||
|
assert await install_addon_ssh.backup(tarfile) is None
|
||||||
|
|
||||||
|
|
||||||
async def test_backup_with_pre_post_command(
|
async def test_backup_with_pre_post_command(
|
||||||
coresys: CoreSys,
|
coresys: CoreSys,
|
||||||
install_addon_ssh: Addon,
|
install_addon_ssh: Addon,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user