mirror of
https://github.com/bunny-lab-io/Borealis.git
synced 2025-10-26 17:41:58 -06:00
Fix Ansible EE metadata persistence on Windows PowerShell
This commit is contained in:
31
Borealis.ps1
31
Borealis.ps1
@@ -64,6 +64,28 @@ $symbols = @{
|
||||
Info = [char]0x2139
|
||||
}
|
||||
|
||||
function Set-FileUtf8Content {
|
||||
param(
|
||||
[Parameter(Mandatory = $true)]
|
||||
[string]$Path,
|
||||
|
||||
[Parameter()]
|
||||
[AllowNull()]
|
||||
[object]$Value = ''
|
||||
)
|
||||
|
||||
$text = if ($null -eq $Value) { '' } else { [string]$Value }
|
||||
$utf8NoBom = New-Object System.Text.UTF8Encoding($false)
|
||||
|
||||
try {
|
||||
Set-Content -Path $Path -Value $text -Encoding UTF8NoBOM -ErrorAction Stop
|
||||
} catch [System.Management.Automation.ParameterBindingException] {
|
||||
[System.IO.File]::WriteAllText($Path, $text, $utf8NoBom)
|
||||
} catch {
|
||||
[System.IO.File]::WriteAllText($Path, $text, $utf8NoBom)
|
||||
}
|
||||
}
|
||||
|
||||
# Admin/Elevation helpers for Agent deployment
|
||||
function Test-IsAdmin {
|
||||
try {
|
||||
@@ -646,22 +668,23 @@ def lockf(*_args, **_kwargs):
|
||||
|
||||
try {
|
||||
if (-not (Test-Path (Join-Path $supportDir '__init__.py') -PathType Leaf)) {
|
||||
Set-Content -Path (Join-Path $supportDir '__init__.py') -Value '' -Encoding UTF8NoBOM
|
||||
Set-FileUtf8Content -Path (Join-Path $supportDir '__init__.py') -Value ''
|
||||
}
|
||||
Set-Content -Path $fcntlStubPath -Value $fcntlStub -Encoding UTF8NoBOM
|
||||
Set-FileUtf8Content -Path $fcntlStubPath -Value $fcntlStub
|
||||
} catch {
|
||||
Write-AgentLog -FileName $LogName -Message "[AnsibleEE] Failed to seed Windows fcntl compatibility shim: $($_.Exception.Message)"
|
||||
}
|
||||
|
||||
try {
|
||||
$metadata | ConvertTo-Json -Depth 5 | Set-Content -Path $metadataPath -Encoding UTF8NoBOM
|
||||
$metadataJson = $metadata | ConvertTo-Json -Depth 5
|
||||
Set-FileUtf8Content -Path $metadataPath -Value $metadataJson
|
||||
} catch {
|
||||
Write-AgentLog -FileName $LogName -Message "[AnsibleEE] Failed to persist metadata.json: $($_.Exception.Message)"
|
||||
throw "Unable to persist Ansible execution environment metadata."
|
||||
}
|
||||
|
||||
try {
|
||||
Set-Content -Path $versionTxtPath -Value $expectedVersionNorm -Encoding UTF8NoBOM
|
||||
Set-FileUtf8Content -Path $versionTxtPath -Value $expectedVersionNorm
|
||||
} catch {}
|
||||
|
||||
Write-AgentLog -FileName $LogName -Message "[AnsibleEE] Execution environment ready at $eeRoot"
|
||||
|
||||
Reference in New Issue
Block a user