stage 1
This commit is contained in:
parent
6494f9d52a
commit
f9e01a72a0
@ -401,9 +401,43 @@ def _next_available_samba_target(dir_path: str, file_name: str, samba_conn) -> s
|
|||||||
|
|
||||||
|
|
||||||
def _samba_move_file(path_from: str, path_to: str, samba_conn) -> None:
|
def _samba_move_file(path_from: str, path_to: str, samba_conn) -> None:
|
||||||
with samba_conn:
|
try:
|
||||||
samba_conn.copy(path_from=path_from, path_to=path_to, replace=False)
|
with samba_conn:
|
||||||
samba_conn.delete(path_from)
|
samba_conn.copy(path_from=path_from, path_to=path_to, replace=False)
|
||||||
|
except Exception as exc: # noqa: BLE001
|
||||||
|
raise RuntimeError(
|
||||||
|
"SMB move failed at copy stage: "
|
||||||
|
f"source='{path_from}', target='{path_to}', "
|
||||||
|
f"{_format_smb_exception(exc)}"
|
||||||
|
) from exc
|
||||||
|
|
||||||
|
try:
|
||||||
|
with samba_conn:
|
||||||
|
samba_conn.delete(path_from)
|
||||||
|
except Exception as exc: # noqa: BLE001
|
||||||
|
target_exists = _safe_path_exists(path_to, samba_conn)
|
||||||
|
raise RuntimeError(
|
||||||
|
"SMB move failed at delete stage after successful copy: "
|
||||||
|
f"source='{path_from}', target='{path_to}', "
|
||||||
|
f"target_exists={target_exists}, {_format_smb_exception(exc)}"
|
||||||
|
) from exc
|
||||||
|
|
||||||
|
|
||||||
|
def _safe_path_exists(path: str, samba_conn) -> bool:
|
||||||
|
try:
|
||||||
|
with samba_conn:
|
||||||
|
return samba_conn.path_exists(path)
|
||||||
|
except Exception: # noqa: BLE001
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
def _format_smb_exception(exc: Exception) -> str:
|
||||||
|
details = [f"error_type={type(exc).__name__}", f"error={exc}"]
|
||||||
|
for attr_name in ("ntstatus", "status", "winerror", "errno"):
|
||||||
|
value = getattr(exc, attr_name, None)
|
||||||
|
if value is not None:
|
||||||
|
details.append(f"{attr_name}={value}")
|
||||||
|
return ", ".join(details)
|
||||||
|
|
||||||
|
|
||||||
def _write_probe_file(remote_path: str, samba_conn) -> None:
|
def _write_probe_file(remote_path: str, samba_conn) -> None:
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user