Skip to content

Commit

Permalink
Build - Bug Fix for issue #71.
Browse files Browse the repository at this point in the history
  • Loading branch information
dotps1 committed Mar 29, 2018
1 parent 28fe89d commit f78a354
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 22 deletions.
33 changes: 32 additions & 1 deletion Tests/Receive-WinSCPItem.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Describe "Receive-WinSCPItem" {
$results = Receive-WinSCPItem -Path "/TextFile.txt" -Destination $temp.FullName
Remove-WinSCPSession

It "Results of Get-WinSCPItem should not be null." {
It "Results of Receive-WinSCPItem should not be null." {
$results |
Should Not Be Null
}
Expand All @@ -38,6 +38,37 @@ Describe "Receive-WinSCPItem" {
}
}

Context "New-WinSCPSession -SessionOption ( New-WinSCPSessionOption -Credential `$credential -HostName $env:COMPUTERNAME -Protocol Ftp ); Receive-WinSCPItem -Path `"/SubDirectory`" -Destination `"$($temp.FullName)`"; Remove-WinSCPSession" {
New-WinSCPSession -SessionOption ( New-WinSCPSessionOption -Credential $credential -HostName $env:COMPUTERNAME -Protocol Ftp )
$results = Receive-WinSCPItem -Path "/SubDirectory" -Destination $temp.FullName
Remove-WinSCPSession

It "Results of Receive-WinSCPItem should not be null." {
$results |
Should Not Be Null
}

It "Results of transfer should be success." {
$results.IsSuccess |
Should Be $true
}

It "SubDirectory should exist in $temp." {
Test-Path -Path "$($temp.FullName)\SubDirectory" |
Should Be $true
}

It "SubDirectoryTextFile.txt should exist in $temp\SubDirectory." {
Test-Path -Path "$($temp.FullName)\SubDirectory\SubDirectoryTextFile.txt" |
Should Be $true
}

It "WinSCP process should not exist." {
Get-Process -Name WinSCP -ErrorAction SilentlyContinue |
Should BeNullOrEmpty
}
}

Context "Invoke-ScriptAnalyzer -Path `"$((Get-Module -Name WinSCP).ModuleBase)\Public\Receive-WinSCPItem.ps1`"" {
$results = Invoke-ScriptAnalyzer -Path "$((Get-Module -Name WinSCP).ModuleBase)\Public\Receive-WinSCPItem.ps1"

Expand Down
7 changes: 7 additions & 0 deletions Update-WinSCPCore.ps1
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#requires -Modules platyPS

[CmdletBinding()]
[OutputType()]

Expand Down Expand Up @@ -55,6 +57,11 @@ if ($publishedVersion -gt $currentVersion) {
Remove-Item -Path "${env:TEMP}\$payloadName" -Force -Confirm:$false
Remove-Item -Path "${env:TEMP}\WinSCP" -Recurse -Force -Confirm:$false

# Recompile the Help file(s).
Import-Module -Path "${pwd}\WinSCP"
Update-MarkdownHelpModule -Path "..\Wiki"
New-ExternalHelp -Path ..\Wiki -OutputPath "${pwd}\WinSCP\en-US" -Force

try {
git add .
git commit -a -m "Build - Updating WinSCP Core to $publishedVersion."
Expand Down
30 changes: 9 additions & 21 deletions WinSCP/Public/Receive-WinSCPItem.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
Mandatory = $true,
ValueFromPipeline = $true
)]
[ValidateScript({
if ($_.Opened) {
return $true
} else {
[ValidateScript({
if ($_.Opened) {
return $true
} else {
throw "The WinSCP Session is not in an Open state."
}
})]
Expand Down Expand Up @@ -45,25 +45,13 @@

[Parameter()]
[WinSCP.TransferOptions]
$TransferOptions = (New-Object -TypeName WinSCP.TransferOptions)
$TransferOptions = ( New-Object -TypeName WinSCP.TransferOptions )
)

process {
foreach ($remotePathValue in (Format-WinSCPPathString -Path $($RemotePath))) {
$localPathEndsWithBackSlash = $LocalPath.EndsWith(
"\"
)
if (-not $localPathEndsWithBackSlash) {
$LocalPath += "\"
}

$remotePathValueEndsWithForwardSlash = $remotePathValue.EndsWith(
"/"
)
if (-not $remotePathValueEndsWithForwardSlash) {
if ((Get-WinSCPItem -WinSCPSession $WinSCPSession -Path $remotePathValue -ErrorAction SilentlyContinue).IsDirectory) {
$remotePathValue += "/"
}
foreach ($remotePathValue in ( Format-WinSCPPathString -Path $($RemotePath) )) {
if ((Get-Item -Path $LocalPath).PSIsContainer -and -not $LocalPath.EndsWith( [System.IO.Path]::DirectorySeparatorChar )) {
$LocalPath += [System.IO.Path]::DirectorySeparatorChar
}

try {
Expand All @@ -74,7 +62,7 @@
if ($result.IsSuccess) {
Write-Output -InputObject $result
} else {
$result.Failures[0] |
$result.Failures[0] |
Write-Error
}
} catch {
Expand Down

0 comments on commit f78a354

Please sign in to comment.