11defmodule SSHKit.SCP.Download do
2- @ moduledoc false
2+ @ moduledoc """
3+ Helper module used by SSHKit.SCP.download/4.
4+ """
35
46 require Bitwise
57
@@ -28,7 +30,7 @@ defmodule SSHKit.SCP.Download do
2830
2931 defp start ( connection , source , target , options ) do
3032 timeout = Keyword . get ( options , :timeout , :infinity )
31- map_cmd = Keyword . get ( options , :map_cmd , & ( & 1 ) )
33+ map_cmd = Keyword . get ( options , :map_cmd , & & 1 )
3234 command = map_cmd . ( Command . build ( :download , source , options ) )
3335 handler = connection_handler ( options )
3436
@@ -41,10 +43,13 @@ defmodule SSHKit.SCP.Download do
4143 case message do
4244 { :data , _ , 0 , data } ->
4345 process_data ( state , data , options )
46+
4447 { :exit_status , _ , status } ->
4548 exited ( options , state , status )
49+
4650 { :eof , _ } ->
4751 eof ( options , state )
52+
4853 { :closed , _ } ->
4954 closed ( options , state )
5055 end
@@ -55,6 +60,7 @@ defmodule SSHKit.SCP.Download do
5560 case state do
5661 { :next , path , stack , attrs , buffer } ->
5762 next ( options , path , stack , attrs , buffer <> data )
63+
5864 { :read , path , stack , attrs , buffer } ->
5965 read ( options , path , stack , attrs , buffer <> data )
6066 end
@@ -193,7 +199,7 @@ defmodule SSHKit.SCP.Download do
193199 atime = :calendar . gregorian_seconds_to_datetime ( @ epoch + atime )
194200 mtime = :calendar . gregorian_seconds_to_datetime ( @ epoch + mtime )
195201 { :ok , file_info } = File . stat ( path )
196- :ok = File . write_stat ( path , % { file_info | mtime: mtime , atime: atime } , [ :posix ] )
202+ :ok = File . write_stat ( path , % { file_info | mtime: mtime , atime: atime } , [ :posix ] )
197203 end
198204
199205 @ tfmt ~S" (T)(0|[1-9]\d*) (0|[1-9]\d{0,5}) (0|[1-9]\d*) (0|[1-9]\d{0,5})"
@@ -206,14 +212,19 @@ defmodule SSHKit.SCP.Download do
206212 case Regex . run ( @ dfmt , value , capture: :all_but_first ) do
207213 [ "T" , mtime , mtus , atime , atus ] ->
208214 { "T" , dec ( mtime ) , dec ( mtus ) , dec ( atime ) , dec ( atus ) }
215+
209216 [ chr , _ , _ , name ] when chr in [ "C" , "D" ] and name in [ "/" , ".." , "." ] ->
210217 nil
218+
211219 [ "C" , mode , len , name ] ->
212220 { "C" , oct ( mode ) , dec ( len ) , name }
221+
213222 [ "D" , mode , len , name ] ->
214223 { "D" , oct ( mode ) , dec ( len ) , name }
224+
215225 [ "E" ] ->
216226 { "E" }
227+
217228 nil ->
218229 nil
219230 end
0 commit comments