@ -632,39 +632,41 @@ end {
buffer_size = max_b64_size - ( max_b64_size % 1024 )
buffer_size = max_b64_size - ( max_b64_size % 1024 )
# setup the file stream with read only mode
# setup the file stream with read only mode
setup_script = ''' $ErrorActionPreference = " Stop "
setup_script = ''' param([string]$Path)
$ path = ' %s '
$ ErrorActionPreference = " Stop "
if ( Test - Path - Path $ path - PathType Leaf ) {
if ( Test - Path - Literal Path $ path - PathType Leaf ) {
$ fs = New - Object - TypeName System . IO . FileStream - ArgumentList @ (
$ fs = New - Object - TypeName System . IO . FileStream - ArgumentList @ (
$ path ,
$ path ,
[ System . IO . FileMode ] : : Open ,
[ System . IO . FileMode ] : : Open ,
[ System . IO . FileAccess ] : : Read ,
[ System . IO . FileAccess ] : : Read ,
[ System . IO . FileShare ] : : Read
[ System . IO . FileShare ] : : Read
)
)
$ buffer_size = % d
} elseif ( Test - Path - Path $ path - PathType Container ) {
} elseif ( Test - Path - Path $ path - PathType Container ) {
Write - Output - InputObject " [DIR] "
Write - Output - InputObject " [DIR] "
} else {
} else {
Write - Error - Message " $path does not exist "
Write - Error - Message " $path does not exist "
$ host . SetShouldExit ( 1 )
$ host . SetShouldExit ( 1 )
} ''' % (self._shell._escape(in_path), buffer_size)
} '''
# read the file stream at the offset and return the b64 string
# read the file stream at the offset and return the b64 string
read_script = ''' $ErrorActionPreference = " Stop "
read_script = ''' param([int64]$Offset, [int]$BufferSize)
$ fs. Seek ( % d , [ System . IO . SeekOrigin ] : : Begin ) > $ null
$ ErrorActionPreference = " Stop "
$ buffer = New - Object - TypeName byte [ ] - ArgumentList $ buffer_size
$ fs. Seek ( $ Offset , [ System . IO . SeekOrigin ] : : Begin ) > $ null
$ b ytes_read = $ fs . Read ( $ buffer , 0 , $ buffer_size )
$ b uffer = New - Object - TypeName byte [ ] - ArgumentList $ BufferSize
$ read = $ fs . Read ( $ buffer , 0 , $ buffer . Length )
if ( $ bytes_read - gt 0 ) {
$ bytes = $ buffer [ 0. . ( $ bytes_read - 1 ) ]
if ( $ read - gt 0 ) {
Write - Output - InputObject ( [ System . Convert ] : : ToBase64String ( $ bytes ) )
[ System . Convert ] : : ToBase64String ( $ buffer , 0 , $ read )
} '''
} '''
# need to run the setup script outside of the local scope so the
# need to run the setup script outside of the local scope so the
# file stream stays active between fetch operations
# file stream stays active between fetch operations
rc , stdout , stderr = self . _exec_psrp_script ( setup_script ,
rc , stdout , stderr = self . _exec_psrp_script (
use_local_scope = False )
setup_script ,
use_local_scope = False ,
arguments = [ in_path ] ,
)
if rc != 0 :
if rc != 0 :
raise AnsibleError ( " failed to setup file stream for fetch ' %s ' : %s "
raise AnsibleError ( " failed to setup file stream for fetch ' %s ' : %s "
% ( out_path , to_native ( stderr ) ) )
% ( out_path , to_native ( stderr ) ) )
@ -679,7 +681,10 @@ if ($bytes_read -gt 0) {
while True :
while True :
display . vvvvv ( " PSRP FETCH %s to %s (offset= %d " %
display . vvvvv ( " PSRP FETCH %s to %s (offset= %d " %
( in_path , out_path , offset ) , host = self . _psrp_host )
( in_path , out_path , offset ) , host = self . _psrp_host )
rc , stdout , stderr = self . _exec_psrp_script ( read_script % offset )
rc , stdout , stderr = self . _exec_psrp_script (
read_script ,
arguments = [ offset , buffer_size ] ,
)
if rc != 0 :
if rc != 0 :
raise AnsibleError ( " failed to transfer file to ' %s ' : %s "
raise AnsibleError ( " failed to transfer file to ' %s ' : %s "
% ( out_path , to_native ( stderr ) ) )
% ( out_path , to_native ( stderr ) ) )
@ -813,7 +818,7 @@ if ($bytes_read -gt 0) {
script : str ,
script : str ,
input_data : bytes | str | t . Iterable | None = None ,
input_data : bytes | str | t . Iterable | None = None ,
use_local_scope : bool = True ,
use_local_scope : bool = True ,
arguments : t . Iterable [ str ] | None = None ,
arguments : t . Iterable [ t . Any ] | None = None ,
) - > tuple [ int , bytes , bytes ] :
) - > tuple [ int , bytes , bytes ] :
# Check if there's a command on the current pipeline that still needs to be closed.
# Check if there's a command on the current pipeline that still needs to be closed.
if self . _last_pipeline :
if self . _last_pipeline :