Skip to content

Commit 63fde3b

Browse files
authored
Do not backup add-on being uninstalled (#5917)
1 parent 5285e60 commit 63fde3b

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

supervisor/addons/addon.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1335,6 +1335,13 @@ def _addon_backup(
13351335

13361336
wait_for_start: asyncio.Task | None = None
13371337

1338+
# Refuse to backup if add-on is unknown (e.g. has been uninstalled by the user
1339+
# since the backup got started).
1340+
if self.state == AddonState.UNKNOWN:
1341+
raise AddonsError(
1342+
f"Add-on {self.slug} is not installed, cannot backup!", _LOGGER.error
1343+
)
1344+
13381345
data = {
13391346
ATTR_USER: self.persist,
13401347
ATTR_SYSTEM: self.data,

tests/addons/test_addon.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ async def test_addon_state_listener(coresys: CoreSys, install_addon_ssh: Addon)
102102
with patch.object(DockerAddon, "attach"):
103103
await install_addon_ssh.load()
104104

105-
assert install_addon_ssh.state == AddonState.UNKNOWN
105+
assert install_addon_ssh.state == AddonState.STOPPED
106106

107107
with patch.object(Addon, "watchdog_container"):
108108
_fire_test_event(coresys, f"addon_{TEST_ADDON_SLUG}", ContainerState.RUNNING)

tests/conftest.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
ATTR_TYPE,
4141
ATTR_VERSION,
4242
REQUEST_FROM,
43+
AddonState,
4344
CoreState,
4445
)
4546
from supervisor.coresys import CoreSys
@@ -615,6 +616,7 @@ async def install_addon_ssh(coresys: CoreSys, repository):
615616
coresys.addons.data._data = coresys.addons.data._schema(coresys.addons.data._data)
616617

617618
addon = Addon(coresys, store.slug)
619+
addon.state = AddonState.STOPPED
618620
coresys.addons.local[addon.slug] = addon
619621
yield addon
620622

@@ -627,6 +629,7 @@ async def install_addon_example(coresys: CoreSys, repository):
627629
coresys.addons.data._data = coresys.addons.data._schema(coresys.addons.data._data)
628630

629631
addon = Addon(coresys, store.slug)
632+
addon.state = AddonState.STOPPED
630633
coresys.addons.local[addon.slug] = addon
631634
yield addon
632635

0 commit comments

Comments
 (0)