Skip to content

Commit

Permalink
(GH-1781) fix: use ProviderPath for Get-Location
Browse files Browse the repository at this point in the history
When seeing the following error:
`ERROR: Exception calling "Start" with "0" argument(s): "The directory
name is invalid"` this can stem off of permissions issues or an
incorrectly formatted directory being passed. When using Get-Location,
if that location is a UNC path, PowerShell shows that with
`Microsoft.PowerShell.Core\FileSystem::\\server\share`, resulting in
that entire string to be passed as the PATH for the working directory
that is passed to
`System.Diagnostics.Process.StartInfo.WorkingDirectory`. Unfortunately
that doesn't evaluate to an acutal valid path, thus the error is
produced. Instead, the path should be evaluated with ProviderPath,
which removes the `Microsoft.PowerShell.Core\FileSystem::` from the
actual path, resulting in a valid path using a UNC location.

Also make a determination if the path is not set (such as with things
that are run during provisioning) and provide a valid working directory
using cache location.
  • Loading branch information
ferventcoder committed May 29, 2019
1 parent a2f358c commit 9e2e49a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,13 @@ param(
$destinationNoRedirection = $destination
}

$workingDirectory = Get-Location -PSProvider "FileSystem"
$workingDirectory = $(Get-Location -PSProvider 'FileSystem')
if ($workingDirectory -eq $null -or $workingDirectory.ProviderPath -eq $null) {
Write-Debug "Unable to use current location for Working Directory. Using Cache Location instead."
$workingDirectory = $env:TEMP
}
$workingDirectory = $workingDirectory.ProviderPath

$params = "x -aoa -bd -bb1 -o`"$destinationNoRedirection`" -y `"$fileFullPathNoRedirection`""
if ($specificfolder) {
$params += " `"$specificfolder`""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ Array of exit codes indicating success. Defaults to `@(0)`.
.PARAMETER WorkingDirectory
The working directory for the running process. Defaults to
`Get-Location`.
`Get-Location`. If current location is a UNC path, uses
`$env:TEMP` for default as of 0.10.14.
Available in 0.10.1+.
Expand Down Expand Up @@ -117,14 +118,20 @@ param(
[parameter(Mandatory=$false)][switch] $minimized,
[parameter(Mandatory=$false)][switch] $noSleep,
[parameter(Mandatory=$false)] $validExitCodes = @(0),
[parameter(Mandatory=$false)][string] $workingDirectory = $(Get-Location -PSProvider "FileSystem"),
[parameter(Mandatory=$false)][string] $workingDirectory = $(Get-Location -PSProvider 'FileSystem'),
[parameter(Mandatory=$false)][string] $sensitiveStatements = '',
[parameter(ValueFromRemainingArguments = $true)][Object[]] $ignoredArguments
)
[string]$statements = $statements -join ' '

Write-FunctionCallLogMessage -Invocation $MyInvocation -Parameters $PSBoundParameters

if ($workingDirectory -eq $null -or $workingDirectory.ProviderPath -eq $null) {
Write-Debug "Unable to use current location for Working Directory. Using Cache Location instead."
$workingDirectory = $env:TEMP
}
$workingDirectory = $workingDirectory.ProviderPath

$alreadyElevated = $false
if (Test-ProcessAdminRights) {
$alreadyElevated = $true
Expand Down

1 comment on commit 9e2e49a

@ferventcoder
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Follow on commit at 02ea65e

Please sign in to comment.