|
1 | 1 | import json |
2 | 2 | import logging |
3 | 3 | import os |
4 | | -import shutil |
5 | 4 | import sys |
6 | 5 | import time |
7 | 6 | from asyncio import CancelledError |
|
12 | 11 | from pathlib import Path |
13 | 12 | from typing import cast |
14 | 13 |
|
15 | | -import aiofiles.os |
16 | 14 | import magic |
17 | 15 | from aiofiles.tempfile import TemporaryDirectory as AioTemporaryDirectory |
18 | 16 | from models_library.basic_types import IDStr |
|
22 | 20 | from pydantic import ByteSize, TypeAdapter |
23 | 21 | from servicelib.archiving_utils import PrunableFolder, archive_dir, unarchive_dir |
24 | 22 | from servicelib.async_utils import run_sequentially_in_context |
25 | | -from servicelib.file_utils import remove_directory |
| 23 | +from servicelib.file_utils import remove_directory, shutil_move |
26 | 24 | from servicelib.logging_utils import log_context |
27 | 25 | from servicelib.progress_bar import ProgressBarData |
28 | 26 | from servicelib.utils import limited_gather |
@@ -239,19 +237,6 @@ def _is_zip_file(file_path: Path) -> bool: |
239 | 237 | return f"{mime_type}" == "application/zip" |
240 | 238 |
|
241 | 239 |
|
242 | | -_shutil_move = aiofiles.os.wrap(shutil.move) |
243 | | - |
244 | | - |
245 | | -async def _move_archive(final_path: Path, archive_path: Path) -> set[Path]: |
246 | | - final_path = final_path / archive_path.name |
247 | | - |
248 | | - with log_context(_logger, logging.DEBUG, f"moving {archive_path} to {final_path}"): |
249 | | - final_path.parent.mkdir(exist_ok=True, parents=True) |
250 | | - await _shutil_move(archive_path, final_path) |
251 | | - |
252 | | - return {final_path} |
253 | | - |
254 | | - |
255 | 240 | async def _get_data_from_port( |
256 | 241 | port: Port, *, target_dir: Path, progress_bar: ProgressBarData |
257 | 242 | ) -> tuple[Port, ItemConcreteValue | None, ByteSize]: |
@@ -297,9 +282,16 @@ async def _get_data_from_port( |
297 | 282 | progress_bar=sub_progress, |
298 | 283 | ) |
299 | 284 | else: |
300 | | - archive_files: set[Path] = await _move_archive( |
301 | | - final_path, downloaded_file |
302 | | - ) |
| 285 | + # move archive to directory as is |
| 286 | + final_path = final_path / downloaded_file.name |
| 287 | + |
| 288 | + with log_context( |
| 289 | + _logger, logging.DEBUG, f"moving {downloaded_file} to {final_path}" |
| 290 | + ): |
| 291 | + final_path.parent.mkdir(exist_ok=True, parents=True) |
| 292 | + await shutil_move(downloaded_file, final_path) |
| 293 | + |
| 294 | + archive_files: set[Path] = {final_path} |
303 | 295 |
|
304 | 296 | # NOTE: after the port content changes, make sure old files |
305 | 297 | # which are no longer part of the port, are removed |
|
0 commit comments