Skip to content

Commit 6936331

Browse files
committed
Fixes cache file encoding read/write
1 parent 456cc26 commit 6936331

File tree

3 files changed

+36
-4
lines changed

3 files changed

+36
-4
lines changed

cache/framework_cache.psm1

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<#
1+
<#
22
### Note ###
33
44
This file is shipping plain with Icinga for Windows for each version.
@@ -14,6 +14,16 @@ if ($null -ne $env:TERM_PROGRAM) {
1414
return;
1515
}
1616

17+
if ($null -eq $Global:IcingaUpdate) {
18+
Remove-Module icinga-powershell-framework -Global -Force;
19+
Remove-Module icinga-powershell-framework -Force;
20+
21+
Import-Module icinga-powershell-framework -Force;
22+
23+
$Global:IcingaUpdate = $TRUE;
24+
return;
25+
}
26+
1727
Write-IcingaFrameworkCodeCache;
1828

1929
Import-Module icinga-powershell-framework -Global -Force;
@@ -22,3 +32,5 @@ Import-Module icinga-powershell-framework -Force;
2232
if ($null -ne $env:TERM_PROGRAM -Or $Global:Icinga.Protected.DeveloperMode) {
2333
Copy-IcingaFrameworkCacheTemplate;
2434
}
35+
36+
$Global:IcingaUpdate = $FALSE;

icinga-powershell-framework.psm1

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,16 @@ function Write-IcingaFrameworkCodeCache()
108108
# Load modules from directory
109109
Get-ChildItem -Path $directory -Recurse -Filter '*.psm1' |
110110
ForEach-Object {
111-
$CacheContent += (Get-Content -Path $_.FullName -Raw -Encoding 'UTF8');
112-
$CacheContent += "`r`n";
111+
[System.IO.FileStream]$FileStream = [System.IO.File]::Open(
112+
$_.FullName,
113+
[System.IO.FileMode]::Open,
114+
[System.IO.FileAccess]::Read,
115+
[System.IO.FileShare]::Read
116+
);
117+
$FileReader = New-Object 'System.IO.StreamReader'($FileStream), (New-Object System.Text.UTF8Encoding $TRUE);
118+
$CacheContent += $FileReader.ReadToEnd();
119+
$FileReader.Close();
120+
$FileReader.Dispose();
113121
}
114122

115123
$CacheContent += "Export-ModuleMember -Function @( '*' ) -Alias @( '*' ) -Variable @( '*' )";
@@ -122,7 +130,7 @@ function Write-IcingaFrameworkCodeCache()
122130
return;
123131
}
124132

125-
Set-Content -Path $CacheFile -Value $CacheContent -Encoding 'UTF8';
133+
[System.IO.File]::WriteAllLines($CacheFile, $CacheContent, (New-Object System.Text.UTF8Encoding $TRUE));
126134

127135
Remove-IcingaFrameworkDependencyFile;
128136

templates/framework_cache.psm1.template

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,16 @@ if ($null -ne $env:TERM_PROGRAM) {
1414
return;
1515
}
1616

17+
if ($null -eq $Global:IcingaUpdate) {
18+
Remove-Module icinga-powershell-framework -Global -Force;
19+
Remove-Module icinga-powershell-framework -Force;
20+
21+
Import-Module icinga-powershell-framework -Force;
22+
23+
$Global:IcingaUpdate = $TRUE;
24+
return;
25+
}
26+
1727
Write-IcingaFrameworkCodeCache;
1828

1929
Import-Module icinga-powershell-framework -Global -Force;
@@ -22,3 +32,5 @@ Import-Module icinga-powershell-framework -Force;
2232
if ($null -ne $env:TERM_PROGRAM -Or $Global:Icinga.Protected.DeveloperMode) {
2333
Copy-IcingaFrameworkCacheTemplate;
2434
}
35+
36+
$Global:IcingaUpdate = $FALSE;

0 commit comments

Comments
 (0)