1919from models_library .projects import ProjectIDStr
2020from models_library .projects_nodes_io import NodeIDStr
2121from models_library .services_types import ServicePortKey
22- from pydantic import ByteSize
22+ from pydantic import ByteSize , TypeAdapter
2323from servicelib .archiving_utils import PrunableFolder , archive_dir , unarchive_dir
2424from servicelib .async_utils import run_sequentially_in_context
2525from servicelib .file_utils import remove_directory
@@ -102,7 +102,7 @@ async def upload_outputs( # pylint:disable=too-many-statements # noqa: PLR0915
102102 PORTS : Nodeports = await node_ports_v2 .ports (
103103 user_id = settings .DY_SIDECAR_USER_ID ,
104104 project_id = ProjectIDStr (settings .DY_SIDECAR_PROJECT_ID ),
105- node_uuid = NodeIDStr (settings .DY_SIDECAR_NODE_ID ),
105+ node_uuid = TypeAdapter ( NodeIDStr ). validate_python (settings .DY_SIDECAR_NODE_ID ),
106106 r_clone_settings = None ,
107107 io_log_redirect_cb = io_log_redirect_cb ,
108108 aws_s3_cli_settings = None ,
@@ -242,18 +242,14 @@ def _is_zip_file(file_path: Path) -> bool:
242242_shutil_move = aiofiles .os .wrap (shutil .move )
243243
244244
245- async def _move_file_to_input_port (
246- final_path : Path , downloaded_file : Path , dest_folder : PrunableFolder
247- ) -> None :
248- with log_context (_logger , logging .DEBUG , f"moving { downloaded_file } " ):
249- final_path = final_path / downloaded_file .name
250- final_path .parent .mkdir (exist_ok = True , parents = True )
245+ async def _move_archive (final_path : Path , archive_path : Path ) -> set [Path ]:
246+ final_path = final_path / archive_path .name
251247
252- await _shutil_move (downloaded_file , final_path )
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 )
253251
254- # NOTE: after the port content changes, make sure old files
255- # which are no longer part of the port, are removed
256- dest_folder .prune (exclude = {final_path })
252+ return {final_path }
257253
258254
259255async def _get_data_from_port (
@@ -288,24 +284,26 @@ async def _get_data_from_port(
288284 with log_context (_logger , logging .DEBUG , "creating directory" ):
289285 final_path .mkdir (exist_ok = True , parents = True )
290286 port_data = f"{ final_path } "
291- dest_folder = PrunableFolder (final_path )
292287
293288 if _is_zip_file (downloaded_file ):
294289 with log_context (
295290 _logger ,
296291 logging .DEBUG ,
297292 f"unzipping '{ downloaded_file } ' to { final_path } " ,
298293 ):
299- unarchived : set [Path ] = await unarchive_dir (
294+ archive_files : set [Path ] = await unarchive_dir (
300295 archive_to_extract = downloaded_file ,
301296 destination_folder = final_path ,
302297 progress_bar = sub_progress ,
303298 )
304- dest_folder .prune (exclude = unarchived )
305299 else :
306- await _move_file_to_input_port (final_path , downloaded_file , dest_folder )
300+ archive_files : set [Path ] = await _move_archive (
301+ final_path , downloaded_file
302+ )
307303
308- _logger .debug ("all moved to %s" , final_path )
304+ # NOTE: after the port content changes, make sure old files
305+ # which are no longer part of the port, are removed
306+ PrunableFolder (final_path ).prune (exclude = archive_files )
309307 else :
310308 transferred_bytes = sys .getsizeof (port_data )
311309
@@ -328,7 +326,7 @@ async def download_target_ports(
328326 PORTS : Nodeports = await node_ports_v2 .ports (
329327 user_id = settings .DY_SIDECAR_USER_ID ,
330328 project_id = ProjectIDStr (settings .DY_SIDECAR_PROJECT_ID ),
331- node_uuid = NodeIDStr (settings .DY_SIDECAR_NODE_ID ),
329+ node_uuid = TypeAdapter ( NodeIDStr ). validate_python (settings .DY_SIDECAR_NODE_ID ),
332330 r_clone_settings = None ,
333331 io_log_redirect_cb = io_log_redirect_cb ,
334332 aws_s3_cli_settings = None ,
0 commit comments