diff --git a/app/pipeline/service.py b/app/pipeline/service.py index e65495a..4463d75 100644 --- a/app/pipeline/service.py +++ b/app/pipeline/service.py @@ -18,6 +18,7 @@ from .file_manager import ( check_input_dir_access, connect_samba, create_run_context, + ensure_dir_exists, move_file_to_error, move_file_to_processed, read_remote_file_bytes, @@ -70,6 +71,19 @@ def run_batch( smb_base_path=smb_base_path, user_params={"user_name": samba_user, "password": samba_password}, ) + try: + ensure_dir_exists(input_dir, samba_conn) + except Exception as exc: # noqa: BLE001 + return BatchResult( + status="error", + processed=0, + partial=0, + errors=1, + report_path="", + protocol_path="", + log_path="", + messages=[f"Не удалось создать входную папку: {input_dir}. {exc}"], + ) is_ok, access_error = check_input_dir_access( input_dir=input_dir, samba_conn=samba_conn ) diff --git a/app/samba_access.py b/app/samba_access.py index 20f8713..7a91def 100644 --- a/app/samba_access.py +++ b/app/samba_access.py @@ -2,7 +2,11 @@ from __future__ import annotations from pathlib import Path -from app.pipeline.file_manager import check_input_dir_access, connect_samba +from app.pipeline.file_manager import ( + check_input_dir_access, + connect_samba, + ensure_dir_exists, +) def build_user_params(samba_user: str, samba_password: str) -> dict[str, str]: @@ -27,6 +31,11 @@ def check_access_and_list_files( except RuntimeError as exc: return False, str(exc), [] + try: + ensure_dir_exists(input_dir, samba_conn=samba_conn) + except Exception as exc: # noqa: BLE001 + return False, f"Не удалось создать входную папку: {input_dir}. {exc}", [] + ok, error = check_input_dir_access(Path(input_dir), samba_conn=samba_conn) if not ok: return False, error or "Ошибка доступа к входной папке.", []