Skip to content

Commit c8cbfd7

Browse files
author
Andrew
committed
Updates from code review feedback
1 parent 236c283 commit c8cbfd7

File tree

3 files changed

+14
-15
lines changed

3 files changed

+14
-15
lines changed

powershell-adapter/Tests/powershellgroup.config.tests.ps1

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ Describe 'PowerShell adapter resource tests' {
1313
$winpsConfigPath = Join-path $PSScriptRoot "winps_resource.dsc.yaml"
1414

1515
if ($IsLinux -or $IsMacOS) {
16-
$cacheFilePath = Join-Path $env:HOME ".dsc" "dscv3classcache.json"
16+
$cacheFilePath = Join-Path $env:HOME "dsc" "PSAdapterCache.json"
1717
}
1818
else
1919
{
20-
$cacheFilePath = Join-Path $env:LocalAppData "dscv3classcache.json"
21-
$cacheFilePath_v5 = Join-Path $env:LocalAppData "dscv3classcache-v5.json"
20+
$cacheFilePath = Join-Path $env:LocalAppData "dsc" "PSAdapterCache.json"
21+
$cacheFilePath_v5 = Join-Path $env:LocalAppData "dsc" "WindowsPSAdapterCache.json"
2222
}
2323
}
2424
AfterAll {

powershell-adapter/Tests/powershellgroup.resource.tests.ps1

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ Describe 'PowerShell adapter resource tests' {
1111
$env:PSModulePath += [System.IO.Path]::PathSeparator + $PSScriptRoot
1212

1313
if ($IsLinux -or $IsMacOS) {
14-
$cacheFilePath = Join-Path $env:HOME ".dsc" "dscv3classcache.json"
14+
$cacheFilePath = Join-Path $env:HOME "dsc" "PSAdapterCache.json"
1515
}
1616
else
1717
{
18-
$cacheFilePath = Join-Path $env:LocalAppData "dscv3classcache.json"
19-
$cacheFilePath_v5 = Join-Path $env:LocalAppData "dscv3classcache-v5.json"
18+
$cacheFilePath = Join-Path $env:LocalAppData "dsc" "PSAdapterCache.json"
19+
$cacheFilePath_v5 = Join-Path $env:LocalAppData "dsc" "WindowsPSAdapterCache.json"
2020
}
2121
}
2222
AfterAll {

powershell-adapter/psDscAdapter/psDscAdapter.psm1

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,12 @@ function Invoke-DscCacheRefresh {
3939

4040
$refreshCache = $false
4141

42-
$cacheFileSuffix = ".json"
42+
$cacheFilePath = Join-Path $env:LocalAppData "dsc" "PSAdapterCache.json"
4343
if ($PSVersionTable.PSVersion.Major -le 5) {
44-
$cacheFileSuffix = "-v5.json"
44+
$cacheFilePath = Join-Path $env:LocalAppData "dsc" "WindowsPSAdapterCache.json"
4545
}
46-
47-
$cacheFilePath = Join-Path $env:LocalAppData "dscv3classcache$cacheFileSuffix"
4846
if ($IsLinux -or $IsMacOS) {
49-
$cacheFilePath = Join-Path $env:HOME ".dsc" "dscv3classcache$cacheFileSuffix"
47+
$cacheFilePath = Join-Path $env:HOME "dsc" "PSAdapterCache.json"
5048
}
5149

5250
if (Test-Path $cacheFilePath) {
@@ -90,7 +88,7 @@ function Invoke-DscCacheRefresh {
9088
$trace = @{'Debug' = "Checking cache for stale PSModulePath"} | ConvertTo-Json -Compress
9189
$host.ui.WriteErrorLine($trace)
9290

93-
$m = $env:PSModulePath -split [IO.Path]::PathSeparator | %{Get-ChildItem -Directory -Path $_ -ea SilentlyContinue}
91+
$m = $env:PSModulePath -split [IO.Path]::PathSeparator | %{Get-ChildItem -Directory -Path $_ -Depth 1 -ea SilentlyContinue}
9492

9593
$hs_cache = [System.Collections.Generic.HashSet[string]]($cache.PSModulePaths)
9694
$hs_live = [System.Collections.Generic.HashSet[string]]($m.FullName)
@@ -205,7 +203,7 @@ function Invoke-DscCacheRefresh {
205203

206204
# fill in resource files (and their last-write-times) that will be used for up-do-date checks
207205
$lastWriteTimes = @{}
208-
Get-ChildItem -Recurse -Path $dscResource.ParentPath | % {
206+
Get-ChildItem -Recurse -File -Path $dscResource.ParentPath -Include "*.ps1","*.psd1","*psm1","*.mof" -ea SilentlyContinue | % {
209207
$lastWriteTimes.Add($_.FullName, $_.LastWriteTime)
210208
}
211209

@@ -218,14 +216,15 @@ function Invoke-DscCacheRefresh {
218216

219217
[dscResourceCache]$cache = [dscResourceCache]::new()
220218
$cache.ResourceCache = $dscResourceCacheEntries
221-
$m = $env:PSModulePath -split [IO.Path]::PathSeparator | %{Get-ChildItem -Directory -Path $_ -ea SilentlyContinue}
219+
$m = $env:PSModulePath -split [IO.Path]::PathSeparator | %{Get-ChildItem -Directory -Path $_ -Depth 1 -ea SilentlyContinue}
222220
$cache.PSModulePaths = $m.FullName
223221

224222
# save cache for future use
225223
# TODO: replace this with a high-performance serializer
226224
$trace = @{'Debug' = "Saving Get-DscResource cache to '$cacheFilePath'"} | ConvertTo-Json -Compress
227225
$host.ui.WriteErrorLine($trace)
228-
$cache | ConvertTo-Json -Depth 90 | Out-File $cacheFilePath
226+
$jsonCache = $cache | ConvertTo-Json -Depth 90
227+
New-Item -Force -Path $cacheFilePath -Value $jsonCache -Type File | Out-Null
229228
}
230229

231230
return $dscResourceCacheEntries

0 commit comments

Comments
 (0)