Bug Report
There's a logic bug in the following lines:
|
$inPath, $strippedPath = Split-PathLikeEnvVar $Path (Get-EnvVar -Name $TargetEnvVar -Global:$Global) |
|
if (!$inPath -or $Force) { |
|
if (!$Quiet) { |
|
$Path | ForEach-Object { |
|
Write-Host "Adding $(friendly_path $_) to $(if ($Global) {'global'} else {'your'}) path." |
|
} |
|
} |
|
Set-EnvVar -Name $TargetEnvVar -Value ((@($Path) + $strippedPath) -join ';') -Global:$Global |
|
} |
|
# current session |
|
$inPath, $strippedPath = Split-PathLikeEnvVar $Path $env:PATH |
|
if (!$inPath -or $Force) { |
|
$env:PATH = (@($Path) + $strippedPath) -join ';' |
|
} |
|
} |
The return value $inPath of the function Split-PathLikeEnvVar is the string containing the components of $Path already in TargetEnvVar, so when given multiple strings, the if (!$Path test will be false when any of the components were already present, rather than when all the components were present.
Current Behavior
Calling Add-Path with multiple paths, if only one of them is in the variable, the other is not added.
Expected Behavior
When calling Add-Path with multiple paths, if any of them is in not in the variable, they are all added back.
Additional context/output
Noticed while updating #6580.
Possible Solution
Split-PathLikeEnvVar should return two lists rather than two strings, and Add-Path should then prepend the items that are not $inPath, which incidentally is also a better solution to the problem raised in #6580 (comment).
System details
Windows version: 11
OS architecture: 64bit
PowerShell version: 7.6.4
Scoop Configuration
N/A
Bug Report
There's a logic bug in the following lines:
Scoop/lib/system.ps1
Lines 106 to 120 in b588a06
The return value
$inPathof the functionSplit-PathLikeEnvVaris the string containing the components of$Pathalready in TargetEnvVar, so when given multiple strings, theif (!$Pathtest will be false when any of the components were already present, rather than when all the components were present.Current Behavior
Calling
Add-Pathwith multiple paths, if only one of them is in the variable, the other is not added.Expected Behavior
When calling
Add-Pathwith multiple paths, if any of them is in not in the variable, they are all added back.Additional context/output
Noticed while updating #6580.
Possible Solution
Split-PathLikeEnvVarshould return two lists rather than two strings, andAdd-Pathshould then prepend the items that are not$inPath, which incidentally is also a better solution to the problem raised in #6580 (comment).System details
Windows version: 11
OS architecture: 64bit
PowerShell version: 7.6.4
Scoop Configuration
N/A