Reset readonly on remove data (#569)
* Reset readonly on remove data * Update addon.py * Update utils.py * Fix lint * Update utils.py * Update utils.py * Update utils.py * Update utils.py * Update addon.py
This commit is contained in:
parent
e7e0b9adda
commit
029f277945
|
@ -4,7 +4,7 @@ from concurrent.futures import ThreadPoolExecutor
|
|||
import logging
|
||||
import sys
|
||||
|
||||
import hassio.bootstrap as bootstrap
|
||||
from hassio import bootstrap
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
|
|
@ -14,7 +14,7 @@ from voluptuous.humanize import humanize_error
|
|||
|
||||
from .validate import (
|
||||
validate_options, SCHEMA_ADDON_SNAPSHOT, RE_VOLUME, RE_SERVICE)
|
||||
from .utils import check_installed
|
||||
from .utils import check_installed, remove_data
|
||||
from ..const import (
|
||||
ATTR_NAME, ATTR_VERSION, ATTR_SLUG, ATTR_DESCRIPTON, ATTR_BOOT, ATTR_MAP,
|
||||
ATTR_OPTIONS, ATTR_PORTS, ATTR_SCHEMA, ATTR_IMAGE, ATTR_REPOSITORY,
|
||||
|
@ -636,7 +636,7 @@ class Addon(CoreSysAttributes):
|
|||
if self.path_data.is_dir():
|
||||
_LOGGER.info(
|
||||
"Remove Home-Assistant addon data folder %s", self.path_data)
|
||||
shutil.rmtree(str(self.path_data))
|
||||
await remove_data(self.path_data)
|
||||
|
||||
# Cleanup audio settings
|
||||
if self.path_asound.exists():
|
||||
|
@ -857,7 +857,7 @@ class Addon(CoreSysAttributes):
|
|||
def _restore_data():
|
||||
"""Restore data."""
|
||||
if self.path_data.is_dir():
|
||||
shutil.rmtree(str(self.path_data), ignore_errors=True)
|
||||
await remove_data(self.path_data)
|
||||
shutil.copytree(str(Path(temp, "data")), str(self.path_data))
|
||||
|
||||
try:
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
"""Util addons functions."""
|
||||
import asyncio
|
||||
import hashlib
|
||||
import logging
|
||||
import re
|
||||
|
@ -33,3 +34,20 @@ def check_installed(method):
|
|||
return await method(addon, *args, **kwargs)
|
||||
|
||||
return wrap_check
|
||||
|
||||
|
||||
async def remove_data(folder):
|
||||
"""Remove folder and reset privileged."""
|
||||
try:
|
||||
proc = await asyncio.create_subprocess_shell(
|
||||
["rm", "-rf", str(folder)], stdout=asyncio.DEVNULL
|
||||
)
|
||||
|
||||
response = await proc.communicate()
|
||||
wrong = response[1].decode()
|
||||
except OSError as err:
|
||||
wrong = str(err)
|
||||
|
||||
if proc.returncode == 0:
|
||||
return
|
||||
_LOGGER.error("Can't remove Add-on Data: %s", wrong)
|
||||
|
|
|
@ -16,7 +16,7 @@ ALL_FOLDERS = [FOLDER_HOMEASSISTANT, FOLDER_SHARE, FOLDER_ADDONS, FOLDER_SSL]
|
|||
|
||||
def unique_addons(addons_list):
|
||||
"""Validate that an add-on is unique."""
|
||||
single = set([addon[ATTR_SLUG] for addon in addons_list])
|
||||
single = set(addon[ATTR_SLUG] for addon in addons_list)
|
||||
|
||||
if len(single) != len(addons_list):
|
||||
raise vol.Invalid("Invalid addon list on snapshot!")
|
||||
|
|
5
pylintrc
5
pylintrc
|
@ -21,7 +21,6 @@ disable=
|
|||
abstract-class-little-used,
|
||||
abstract-class-not-used,
|
||||
unused-argument,
|
||||
global-statement,
|
||||
redefined-variable-type,
|
||||
too-many-arguments,
|
||||
too-many-branches,
|
||||
|
@ -32,7 +31,9 @@ disable=
|
|||
too-many-statements,
|
||||
too-many-lines,
|
||||
too-few-public-methods,
|
||||
abstract-method
|
||||
abstract-method,
|
||||
no-else-return,
|
||||
useless-return
|
||||
|
||||
[EXCEPTIONS]
|
||||
overgeneral-exceptions=Exception,HomeAssistantError
|
||||
|
|
Loading…
Reference in New Issue