Skip to content

Commit 16823a1

Browse files
committed
Fix empty path handling for Windows PowerShell adapter
1 parent db7aff0 commit 16823a1

File tree

2 files changed

+21
-5
lines changed

2 files changed

+21
-5
lines changed

powershell-adapter/Tests/win_powershellgroup.tests.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ class PSClassResource {
118118
New-Item -Path $modulePath -ItemType File -Value $module -Force | Out-Null
119119
}
120120

121-
$env:PSModulePath = $windowsPowerShellPath + [System.IO.Path]::PathSeparator + $env:PSModulePath
121+
$env:PSModulePath = $windowsPowerShellPath + [System.IO.Path]::PathSeparator + $env:PSModulePath + [System.IO.Path]::PathSeparator
122122
}
123123

124124
AfterAll {

powershell-adapter/psDscAdapter/win_psDscAdapter.psm1

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ function Invoke-DscCacheRefresh {
6060
$namedModules = [System.Collections.Generic.List[Object]]::new()
6161
$cacheFilePath = Join-Path $env:LocalAppData "dsc\WindowsPSAdapterCache.json"
6262

63+
# Reset PSModulePath to not contain empty entries
64+
Set-ValidPSModulePath
65+
6366
if (Test-Path $cacheFilePath) {
6467
"Reading from Get-DscResource cache file $cacheFilePath" | Write-DscTrace
6568

@@ -244,10 +247,10 @@ function Invoke-DscCacheRefresh {
244247
}
245248

246249
$dscResourceCacheEntries.Add([dscResourceCacheEntry]@{
247-
Type = "$moduleName/$($dscResource.Name)"
248-
DscResourceInfo = $DscResourceInfo
249-
LastWriteTimes = $lastWriteTimes
250-
})
250+
Type = "$moduleName/$($dscResource.Name)"
251+
DscResourceInfo = $DscResourceInfo
252+
LastWriteTimes = $lastWriteTimes
253+
})
251254
}
252255

253256
if ($namedModules.Count -gt 0) {
@@ -701,6 +704,19 @@ function GetClassBasedCapabilities {
701704
}
702705
}
703706

707+
function Set-ValidPSModulePath {
708+
[CmdletBinding()]
709+
param()
710+
711+
end {
712+
if (($env:PSModulePath -split [System.IO.Path]::PathSeparator) -contains '') {
713+
"Removing empty entry from PSModulePath: '$env:PSModulePath'" | Write-DscTrace -Operation Debug
714+
$env:PSModulePath = ($env:PSModulePath -split [System.IO.Path]::PathSeparator | Where-Object { $_ -ne '' }) -join [System.IO.Path]::PathSeparator
715+
}
716+
}
717+
}
718+
719+
704720
# cached resource
705721
class dscResourceCacheEntry {
706722
[string] $Type

0 commit comments

Comments
 (0)