diff --git a/betty/fs.py b/betty/fs.py index 12dfd3f89..03f196f28 100644 --- a/betty/fs.py +++ b/betty/fs.py @@ -1,5 +1,6 @@ from __future__ import annotations +import asyncio import hashlib import os from collections import deque @@ -12,7 +13,6 @@ import aiofiles from aiofiles.os import makedirs -from aiofiles.ospath import exists from aiofiles.threadpool.text import AsyncTextIOWrapper from betty import _ROOT_DIRECTORY_PATH @@ -86,13 +86,12 @@ async def copy2(self, source_path: Path, destination_path: Path) -> Path: raise FileNotFoundError('Could not find any of %s.' % ', '.join(tried_paths)) async def copytree(self, source_path: Path, destination_path: Path) -> AsyncIterable[Path]: - destination_paths = set() + file_destination_paths = set() for fs_path, _ in self._paths: async for file_source_path in iterfiles(fs_path / source_path): file_destination_path = destination_path / file_source_path.relative_to(fs_path / source_path) - if not await exists(file_destination_path): + if file_destination_path not in file_destination_paths: + file_destination_paths.add(file_destination_path) await makedirs(file_destination_path.parent, exist_ok=True) - copy2(file_source_path, file_destination_path) - if file_destination_path not in destination_paths: - destination_paths.add(file_destination_path) - yield file_destination_path + await asyncio.to_thread(copy2, file_source_path, file_destination_path) + yield file_destination_path diff --git a/betty/tests/test_generate.py b/betty/tests/test_generate.py index 82200d449..729a56a11 100644 --- a/betty/tests/test_generate.py +++ b/betty/tests/test_generate.py @@ -182,7 +182,7 @@ async def test_source(self) -> None: class TestResourceOverride: async def test(self) -> None: async with App() as app: - localized_assets_directory_path = Path(app.project.configuration.assets_directory_path) / 'public' / 'static' + localized_assets_directory_path = Path(app.project.configuration.assets_directory_path) / 'public' / 'localized' localized_assets_directory_path.mkdir(parents=True) with open(str(localized_assets_directory_path / 'index.html.j2'), 'w') as f: f.write('{% block page_content %}Betty was here{% endblock %}')