mirror of
https://github.com/home-assistant/supervisor.git
synced 2025-11-09 19:09:41 +00:00
Remove I/O in event loop for backup create and restore operations (#5634)
* Remove I/O from backup create() function * Move mount check into exectutor thread * Remove I/O from backup open() function * Remove I/O from _folder_save() * Refactor remove_folder and remove_folder_with_excludes Make remove_folder and remove_folder_with_excludes synchronous functions which need to be run in an executor thread to be safely used in asyncio. This makes them better composable with other I/O operations like checking for file existence etc. * Fix logger typo * Use return values for functions running in an exectutor * Move location check into a separate function * Fix extract
This commit is contained in:
@@ -3,13 +3,10 @@
|
||||
from pathlib import Path
|
||||
import shutil
|
||||
|
||||
import pytest
|
||||
|
||||
from supervisor.utils import remove_folder
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_remove_all(tmp_path):
|
||||
def test_remove_all(tmp_path):
|
||||
"""Test remove folder."""
|
||||
# Prepair test folder
|
||||
temp_orig = tmp_path.joinpath("orig")
|
||||
@@ -17,12 +14,11 @@ async def test_remove_all(tmp_path):
|
||||
shutil.copytree(fixture_data, temp_orig, symlinks=True)
|
||||
|
||||
assert temp_orig.exists()
|
||||
await remove_folder(temp_orig)
|
||||
remove_folder(temp_orig)
|
||||
assert not temp_orig.exists()
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_remove_content(tmp_path):
|
||||
def test_remove_content(tmp_path):
|
||||
"""Test remove content of folder."""
|
||||
# Prepair test folder
|
||||
temp_orig = tmp_path.joinpath("orig")
|
||||
@@ -38,8 +34,7 @@ async def test_remove_content(tmp_path):
|
||||
assert test_folder.exists()
|
||||
assert test_file.exists()
|
||||
assert test_hidden.exists()
|
||||
|
||||
await remove_folder(temp_orig, content_only=True)
|
||||
remove_folder(temp_orig, content_only=True)
|
||||
|
||||
assert not test_folder.exists()
|
||||
assert not test_file.exists()
|
||||
|
||||
Reference in New Issue
Block a user