File 3802-ssh-Remove-is_port-1-from-ssh_sftp.erl.patch of Package erlang

From 0cc7f5287c94b56cd3b06935169946023f81fef4 Mon Sep 17 00:00:00 2001
From: Hans Nilsson <hans@erlang.org>
Date: Mon, 29 Jun 2020 11:08:56 +0200
Subject: [PATCH 2/4] ssh: Remove is_port/1 from ssh_sftp.erl

---
 lib/ssh/src/ssh_sftp.erl | 53 ++++++++++++++++++++--------------------
 1 file changed, 26 insertions(+), 27 deletions(-)

diff --git a/lib/ssh/src/ssh_sftp.erl b/lib/ssh/src/ssh_sftp.erl
index 69fff09979..f16db5af6d 100644
--- a/lib/ssh/src/ssh_sftp.erl
+++ b/lib/ssh/src/ssh_sftp.erl
@@ -111,16 +111,9 @@
 %%%----------------------------------------------------------------
 %%% start_channel/1
 
-start_channel(Cm) when is_pid(Cm) ->
-    start_channel(Cm, []);
+start_channel(Dest) ->
+    start_channel(Dest, []).
  
-start_channel(Socket) when is_port(Socket) ->
-    start_channel(Socket, []);
-
-start_channel(Host) ->
-    start_channel(Host, []).
-
-
 %%%----------------------------------------------------------------
 %%% start_channel/2
 
@@ -142,21 +135,6 @@ start_channel(Host) ->
                    )
                    -> {ok,pid(),ssh:connection_ref()} | {error,reason()} .
 
-start_channel(Socket, UserOptions0) when is_port(Socket) ->
-    UserOptions = legacy_timeout(UserOptions0),
-    Timeout = proplists:get_value(connect_timeout, UserOptions, infinity),
-    {SshOpts, ChanOpts, SftpOpts} = handle_options(UserOptions),
-    case ssh:connect(Socket, SshOpts, Timeout) of
-	{ok,Cm} ->
-	    case start_channel(Cm, ChanOpts ++ SftpOpts) of
-		{ok, Pid} ->
-		    {ok, Pid, Cm};
-		Error ->
-		    Error
-	    end;
-	Error ->
-	    Error
-    end;
 start_channel(Cm, UserOptions0) when is_pid(Cm) ->
     UserOptions = legacy_timeout(UserOptions0),
     Timeout = proplists:get_value(timeout, UserOptions, infinity),
@@ -181,8 +158,30 @@ start_channel(Cm, UserOptions) when is_pid(Cm) ->
 	    Error
     end;
 
-start_channel(Host, UserOptions) ->
-    start_channel(Host, 22, UserOptions).
+start_channel(Dest, UserOptions) ->
+    {SshOpts, ChanOpts, SftpOpts} = handle_options(UserOptions),
+    case ssh:is_host(Dest, SshOpts) of
+        true ->
+            %% Dest looks like is a Host
+            start_channel(Dest, 22, UserOptions);
+        false ->
+            %% No, it is probably not a Host, must be a socket
+            Socket = Dest,
+            Timeout =   % A mixture of ssh:connect and ssh_sftp:start_channel:
+                proplists:get_value(connect_timeout, SshOpts,
+                                    proplists:get_value(timeout, SftpOpts, infinity)),
+            case ssh:connect(Socket, SshOpts, Timeout) of
+                {ok,Cm} ->
+                    case start_channel(Cm, ChanOpts ++ SftpOpts) of
+                        {ok, Pid} ->
+                            {ok, Pid, Cm};
+                        Error ->
+                            Error
+                    end;
+                Error ->
+                    Error
+            end
+    end.
 
 
 %%%----------------------------------------------------------------
-- 
2.26.2

openSUSE Build Service is sponsored by