Don't remove add-on repos if add-on is installed (#3364)

This commit is contained in:
Joakim Sørensen 2021-12-14 21:04:31 +01:00 committed by GitHub
parent eadc629cd9
commit 5503f93a75
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 29 additions and 3 deletions

View File

@ -4,7 +4,7 @@ import logging
from ..const import URL_HASSIO_ADDONS
from ..coresys import CoreSys, CoreSysAttributes
from ..exceptions import StoreGitError, StoreJobError, StoreNotFound
from ..exceptions import StoreError, StoreGitError, StoreJobError, StoreNotFound
from ..jobs.decorator import Job, JobCondition
from ..resolution.const import ContextType, IssueType, SuggestionType
from .addon import AddonStore
@ -115,6 +115,13 @@ class StoreManager(CoreSysAttributes):
# Delete stale repositories
for url in old_rep - new_rep - BUILTIN_REPOSITORIES:
repository = self.get_from_url(url)
if repository.slug in (
addon.repository for addon in self.sys_addons.installed
):
raise StoreError(
f"Can't remove '{repository.source}'. It's used by installed add-ons",
logger=_LOGGER.error,
)
await self.repositories.pop(repository.slug).remove()
self.sys_config.drop_addon_repository(url)

View File

@ -1,10 +1,13 @@
{
"advanced": false,
"arch": ["amd64"],
"arch": [
"amd64"
],
"slug": "test",
"description": "Test add-on",
"location": "tmp_path",
"name": "Test Add-on",
"repository": "https://github.com/awesome-developer/awesome-repo",
"repository": "a474bbd1",
"stage": "stable",
"version": "1.0.0"
}

View File

@ -4,6 +4,8 @@ from unittest.mock import patch
import pytest
from supervisor.addons.addon import Addon
from supervisor.exceptions import StoreError
from supervisor.resolution.const import SuggestionType
from supervisor.store import BUILTIN_REPOSITORIES
@ -72,3 +74,17 @@ async def test_preinstall_valid_repository(coresys, store_manager):
await store_manager.update_repositories(BUILTIN_REPOSITORIES)
assert store_manager.get("core").validate()
assert store_manager.get("local").validate()
@pytest.mark.asyncio
async def test_remove_used_repository(coresys, store_manager, store_addon):
"""Test removing used custom repository."""
coresys.addons.data.install(store_addon)
addon = Addon(coresys, store_addon.slug)
coresys.addons.local[addon.slug] = addon
with pytest.raises(
StoreError,
match="Can't remove 'https://github.com/awesome-developer/awesome-repo'. It's used by installed add-ons",
):
await store_manager.update_repositories([])