Fix fetch when retrieving a file with a multiple of the buffer size (#33697)

* Fix fetch when retrieving a file with a multiple of the buffer size

* fixed sanity issue
This commit is contained in:
Jordan Borean 2017-12-12 14:56:21 +10:00 committed by GitHub
parent e3f44b74bd
commit 6e4c690a37
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -571,23 +571,29 @@ class Connection(ConnectionBase):
while True: while True:
try: try:
script = ''' script = '''
If (Test-Path -PathType Leaf "%(path)s") $path = "%(path)s"
If (Test-Path -Path $path -PathType Leaf)
{ {
$stream = New-Object IO.FileStream("%(path)s", [System.IO.FileMode]::Open, [System.IO.FileAccess]::Read, [IO.FileShare]::ReadWrite); $buffer_size = %(buffer_size)d
$stream.Seek(%(offset)d, [System.IO.SeekOrigin]::Begin) | Out-Null; $offset = %(offset)d
$buffer = New-Object Byte[] %(buffer_size)d;
$bytesRead = $stream.Read($buffer, 0, %(buffer_size)d); $stream = New-Object -TypeName IO.FileStream($path, [IO.FileMode]::Open, [IO.FileAccess]::Read, [IO.FileShare]::ReadWrite)
$bytes = $buffer[0..($bytesRead-1)]; $stream.Seek($offset, [System.IO.SeekOrigin]::Begin) > $null
[System.Convert]::ToBase64String($bytes); $buffer = New-Object -TypeName byte[] $buffer_size
$stream.Close() | Out-Null; $bytes_read = $stream.Read($buffer, 0, $buffer_size)
if ($bytes_read -gt 0) {
$bytes = $buffer[0..($bytes_read - 1)]
[System.Convert]::ToBase64String($bytes)
}
$stream.Close() > $null
} }
ElseIf (Test-Path -PathType Container "%(path)s") ElseIf (Test-Path -Path $path -PathType Container)
{ {
Write-Host "[DIR]"; Write-Host "[DIR]";
} }
Else Else
{ {
Write-Error "%(path)s does not exist"; Write-Error "$path does not exist";
Exit 1; Exit 1;
} }
''' % dict(buffer_size=buffer_size, path=self._shell._escape(in_path), offset=offset) ''' % dict(buffer_size=buffer_size, path=self._shell._escape(in_path), offset=offset)