Skip to content

Commit e11c2dd

Browse files
committed
fix: Remove $refreshCache code smell
1 parent 54a9b1a commit e11c2dd

File tree

1 file changed

+3
-8
lines changed

1 file changed

+3
-8
lines changed

powershell-adapter/psDscAdapter/win_psDscAdapter.psm1

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ function Invoke-DscCacheRefresh {
7575
else {
7676
"Checking cache for stale PSModulePath" | Write-DscTrace
7777

78-
$m = $env:PSModulePath -split [IO.Path]::PathSeparator | % { Get-ChildItem -Directory -Path $_ -Depth 1 -ea SilentlyContinue }
78+
$m = $env:PSModulePath -split [IO.Path]::PathSeparator | ForEach-Object { Get-ChildItem -Directory -Path $_ -Depth 1 -ErrorAction Ignore }
7979

8080
$hs_cache = [System.Collections.Generic.HashSet[string]]($cache.PSModulePaths)
8181
$hs_live = [System.Collections.Generic.HashSet[string]]($m.FullName)
@@ -106,21 +106,16 @@ function Invoke-DscCacheRefresh {
106106

107107
if (-not ($file_LastWriteTime.Equals($cache_LastWriteTime))) {
108108
"Detected stale cache entry '$($_.Name)'" | Write-DscTrace
109-
$refreshCache = $true
109+
$namedModules.Add($cacheEntry.DscResourceInfo.ModuleName)
110110
break
111111
}
112112
}
113113
else {
114114
"Detected non-existent cache entry '$($_.Name)'" | Write-DscTrace
115-
$refreshCache = $true
115+
$namedModules.Add($cacheEntry.DscResourceInfo.ModuleName)
116116
break
117117
}
118118
}
119-
120-
if ($refreshCache) {
121-
$namedModules.Add($cacheEntry.DscResourceInfo.ModuleName)
122-
$refreshCache = $false
123-
}
124119
}
125120
}
126121
if ($namedModules.Count -gt 0) {

0 commit comments

Comments
 (0)