Merge pull request #352 from Icinga:fix/missing_file_creation_file_writer

Fix: File writer did not create non-existing files

Fixes newly implemented file writer, by creating files which were not existing prior to writing into them.
This commit is contained in:
Lord Hepipud 2021-08-21 13:45:45 +02:00 committed by GitHub
commit 1241c58909
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -5,6 +5,19 @@ function Write-IcingaFileSecure()
$Value $Value
); );
if ([string]::IsNullOrEmpty($File)) {
return;
}
if ((Test-Path $File) -eq $FALSE) {
try {
New-Item -ItemType File -Path $File -ErrorAction Stop | Out-Null;
} catch {
Exit-IcingaThrowException -InputString $_.Exception -CustomMessage $File -StringPattern 'System.UnauthorizedAccessException' -ExceptionType 'Permission' -ExceptionThrown $IcingaExceptions.Permission.CacheFolder;
Exit-IcingaThrowException -CustomMessage $_.Exception -ExceptionType 'Unhandled' -Force;
}
}
[int]$WaitTicks = 0; [int]$WaitTicks = 0;
[bool]$FileUpdated = $FALSE; [bool]$FileUpdated = $FALSE;