Skip to content

Commit 0aa0bde

Browse files
mjr4077ausintaxasn
authored andcommitted
Fix three bad Split-Path uses that don't work right with -LiteralPath.
This cmdlet couldn't suck any more than it already does... There's zero reason why parameters like `-Parent` and `-Leaf` are gated only to the `-Path` input, but they are and we have to deal with that. Use .NET's `Path.GetFileName()` static method instead, which would be more performant in any case.
1 parent 62b89a7 commit 0aa0bde

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

src/PSAppDeployToolkit/Public/Copy-ADTFile.ps1

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ function Copy-ADTFile
210210
# Strip Microsoft.PowerShell.Core\FileSystem:: from the beginning of the resulting string, since Resolve-Path adds this to UNC paths.
211211
$getItemSplat = @{ $PSCmdlet.ParameterSetName = $srcPath.TrimEnd('\') }
212212
$robocopySource = (Get-Item @getItemSplat -Force).FullName -replace '^Microsoft\.PowerShell\.Core\\FileSystem::'
213-
$robocopyDestination = (Join-Path -Path ((Get-Item -LiteralPath $Destination -Force).FullName -replace '^Microsoft\.PowerShell\.Core\\FileSystem::') -ChildPath (Split-Path @pathSplat -Leaf)).Trim()
213+
$robocopyDestination = (Join-Path -Path ((Get-Item -LiteralPath $Destination -Force).FullName -replace '^Microsoft\.PowerShell\.Core\\FileSystem::') -ChildPath ([System.IO.Path]::GetFileName($($pathSplat.Values)))).Trim()
214214
$robocopyFile = '*'
215215
}
216216
else
@@ -219,7 +219,7 @@ function Copy-ADTFile
219219
# Trim ending backslash from paths which can cause problems with Robocopy.
220220
# Resolve paths in case relative paths beggining with .\, ..\, or \ are used.
221221
# Strip Microsoft.PowerShell.Core\FileSystem:: from the beginning of the resulting string, since Resolve-Path adds this to UNC paths.
222-
$ParentPath = Split-Path @pathSplat -Parent
222+
$ParentPath = Split-Path @pathSplat
223223
$robocopySource = if ([System.String]::IsNullOrWhiteSpace($ParentPath))
224224
{
225225
$ExecutionContext.SessionState.Path.CurrentLocation.Path
@@ -229,7 +229,7 @@ function Copy-ADTFile
229229
(Get-Item -LiteralPath $ParentPath -Force).FullName -replace '^Microsoft\.PowerShell\.Core\\FileSystem::'
230230
}
231231
$robocopyDestination = (Get-Item -LiteralPath $Destination.TrimEnd('\') -Force).FullName -replace '^Microsoft\.PowerShell\.Core\\FileSystem::'
232-
$robocopyFile = (Split-Path @pathSplat -Leaf)
232+
$robocopyFile = [System.IO.Path]::GetFileName($($pathSplat.Values))
233233
}
234234

235235
# Set up copy operation.

0 commit comments

Comments
 (0)