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:
Stefan Agner 2025-05-09 11:07:22 +02:00 committed by GitHub
parent 481bbc5be8
commit 39bd20c0e7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 23 additions and 2 deletions

View File

@ -1322,8 +1322,8 @@ class Addon(AddonModel):
arcname="data",
)
# Backup config
if addon_config_used:
# Backup config (if used and existing, restore handles this gracefully)
if addon_config_used and self.path_config.is_dir():
atomic_contents_add(
backup,
self.path_config,

View File

@ -446,6 +446,27 @@ async def test_backup(
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(
coresys: CoreSys,
install_addon_ssh: Addon,