[platform] making the Defender configuration script resilient to missing excluded directories (IDEA-333056)

GitOrigin-RevId: e1d3c4813f65c88f08357bf6d0c0e1df7e502336
This commit is contained in:
Roman Shevchenko
2023-11-24 11:10:16 +01:00
committed by intellij-monorepo-bot
parent 08e03cfc28
commit a49624747f

View File

@@ -18,14 +18,16 @@ try {
# returns `$true` when a path is already covered by the exclusion list
function Test-Excluded ([string] $path, [string[]] $exclusions) {
foreach ($exclusion in $exclusions) {
$expanded = [System.Environment]::ExpandEnvironmentVariables($exclusion)
$resolvedPaths = Resolve-Path -Path $expanded
foreach ($resolved in $resolvedPaths) {
$resolvedStr = $resolved.ProviderPath.ToString()
if ([cultureinfo]::InvariantCulture.CompareInfo.IsPrefix($path, $resolvedStr, @("IgnoreCase"))) {
return $true
try {
$expanded = [System.Environment]::ExpandEnvironmentVariables($exclusion)
$resolvedPaths = Resolve-Path -Path $expanded -ErrorAction Stop
foreach ($resolved in $resolvedPaths) {
$resolvedStr = $resolved.ProviderPath.ToString()
if ([cultureinfo]::InvariantCulture.CompareInfo.IsPrefix($path, $resolvedStr, @("IgnoreCase"))) {
return $true
}
}
}
} catch [System.Management.Automation.ItemNotFoundException] { }
}
return $false