Skip to content

Commit 42e7840

Browse files
authored
Fix add-on store reset (#5669)
Make sure that add-on store resets do not delete the root folder. This is important so that successive reset attempts do not fail (the directory passed to `remove_folder` must exist, otherwise find fails with an non-zero exit code). While at it, handle find errors properly and report errors as critical.
1 parent 15e8940 commit 42e7840

File tree

3 files changed

+9
-4
lines changed

3 files changed

+9
-4
lines changed

supervisor/resolution/fixups/store_execute_reset.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""Helpers to check and fix issues with free space."""
22

3+
from functools import partial
34
import logging
45

56
from ...coresys import CoreSys
@@ -40,7 +41,9 @@ async def process_fixup(self, reference: str | None = None) -> None:
4041
_LOGGER.warning("Can't find store %s for fixup", reference)
4142
return
4243

43-
await self.sys_run_in_executor(remove_folder, repository.git.path)
44+
await self.sys_run_in_executor(
45+
partial(remove_folder, folder=repository.git.path, content_only=True)
46+
)
4447

4548
# Load data again
4649
try:

supervisor/utils/__init__.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,7 @@ def remove_folder(
106106
except OSError as err:
107107
_LOGGER.exception("Can't remove folder %s: %s", folder, err)
108108
except subprocess.CalledProcessError as procerr:
109-
_LOGGER.error("Can't remove folder %s: %s", folder, procerr.stderr.strip())
110-
raise procerr
109+
_LOGGER.critical("Can't remove folder %s: %s", folder, procerr.stderr.strip())
111110

112111

113112
def remove_folder_with_excludes(

tests/resolution/fixup/test_store_execute_reset.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""Test evaluation base."""
22

33
# pylint: disable=import-error,protected-access
4+
from os import listdir
45
from pathlib import Path
56
from unittest.mock import AsyncMock, patch
67

@@ -25,16 +26,18 @@ async def test_fixup(coresys: CoreSys, tmp_path):
2526
)
2627

2728
test_repo.mkdir()
29+
(test_repo / ".git").mkdir()
2830
assert test_repo.exists()
2931

3032
mock_repositorie = AsyncMock()
3133
mock_repositorie.git.path = test_repo
3234
coresys.store.repositories["test"] = mock_repositorie
35+
assert len(listdir(test_repo)) > 0
3336

3437
with patch("shutil.disk_usage", return_value=(42, 42, 2 * (1024.0**3))):
3538
await store_execute_reset()
3639

37-
assert not test_repo.exists()
40+
assert len(listdir(test_repo)) == 0
3841
assert mock_repositorie.load.called
3942
assert len(coresys.resolution.suggestions) == 0
4043
assert len(coresys.resolution.issues) == 0

0 commit comments

Comments
 (0)