cmdlet refactor

This commit is contained in:
2026-05-04 18:41:01 -07:00
parent 3ce339b3c1
commit 24f983473f
44 changed files with 1320 additions and 309 deletions
+37
View File
@@ -582,6 +582,8 @@ class SCP(Provider):
if not local_path.exists() or not local_path.is_file():
raise FileNotFoundError(f"File not found: {local_path}")
pipe_obj = kwargs.get("pipe_obj")
settings = self._resolve_settings(
instance_name=str(kwargs.get("instance") or kwargs.get("store") or "").strip() or None,
require_explicit=bool(kwargs.get("instance") or kwargs.get("store")),
@@ -609,8 +611,30 @@ class SCP(Provider):
if not self._is_sftp_negotiation_error(exc):
raise
self._ensure_directory_via_ssh(ssh, remote_dir)
if self._remote_filename_exists_via_ssh(ssh, remote_path):
try:
if pipe_obj is not None:
if not isinstance(getattr(pipe_obj, "extra", None), dict):
pipe_obj.extra = {}
pipe_obj.extra["upload_duplicate"] = True
pipe_obj.extra["upload_duplicate_rule"] = "filename"
pipe_obj.extra["upload_duplicate_target"] = remote_path
except Exception:
pass
return self._build_url(remote_path, settings=settings)
else:
self._ensure_directory(sftp, remote_dir, base_path=str(settings.get("base_path") or "/"))
if self._remote_filename_exists(sftp, remote_path):
try:
if pipe_obj is not None:
if not isinstance(getattr(pipe_obj, "extra", None), dict):
pipe_obj.extra = {}
pipe_obj.extra["upload_duplicate"] = True
pipe_obj.extra["upload_duplicate_rule"] = "filename"
pipe_obj.extra["upload_duplicate_target"] = remote_path
except Exception:
pass
return self._build_url(remote_path, settings=settings)
scp_client = self._open_scp(ssh)
scp_client.put(str(local_path), remote_path=remote_path)
finally:
@@ -620,6 +644,19 @@ class SCP(Provider):
return self._build_url(remote_path, settings=settings)
def _remote_filename_exists(self, sftp: Any, remote_path: str) -> bool:
try:
sftp.stat(remote_path)
return True
except Exception:
return False
def _remote_filename_exists_via_ssh(self, ssh: Any, remote_path: str) -> bool:
normalized = self._normalize_remote_path(remote_path, default=self._base_path)
quoted_path = shlex.quote(normalized)
status, _, _ = self._run_ssh_command(ssh, f"test -e {quoted_path}")
return status == 0
def _run_test_connection(self) -> Dict[str, Any]:
settings = self._resolve_settings()
if not settings.get("host"):