From 39bd20c0e795a0ffbd2d076d1e8b4abed6cb47b2 Mon Sep 17 00:00:00 2001 From: Stefan Agner Date: Fri, 9 May 2025 11:07:22 +0200 Subject: [PATCH] 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 --- supervisor/addons/addon.py | 4 ++-- tests/addons/test_addon.py | 21 +++++++++++++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/supervisor/addons/addon.py b/supervisor/addons/addon.py index 338e0475a..3a64b82e1 100644 --- a/supervisor/addons/addon.py +++ b/supervisor/addons/addon.py @@ -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, diff --git a/tests/addons/test_addon.py b/tests/addons/test_addon.py index 8c52a25a7..2f8965c88 100644 --- a/tests/addons/test_addon.py +++ b/tests/addons/test_addon.py @@ -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,