From 164248183db8e63671d314b96f7956f8ee03faf5 Mon Sep 17 00:00:00 2001 From: Manuel Thalmann Date: Wed, 21 Aug 2024 03:18:31 +0200 Subject: [PATCH] Prevent initialization of nested operations --- scripts/Common/Scripts/Operations.ps1 | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/scripts/Common/Scripts/Operations.ps1 b/scripts/Common/Scripts/Operations.ps1 index e51d867e..f89f3849 100644 --- a/scripts/Common/Scripts/Operations.ps1 +++ b/scripts/Common/Scripts/Operations.ps1 @@ -23,18 +23,22 @@ $null = New-Module { [scriptblock] $Action ) - $Global:ErrorActionPreference = 'Inquire'; - $env:WSLENV = "CONFIG_MODULE/p"; + if (-not $Global:InOperation) { + $Global:InOperation = $true; + $Global:ErrorActionPreference = 'Inquire'; + $env:WSLENV = "CONFIG_MODULE/p"; - if ($env:CONFIG_MODULE) { - $env:CONFIG_MODULE = Resolve-Path $env:CONFIG_MODULE; + if ($env:CONFIG_MODULE) { + $env:CONFIG_MODULE = Resolve-Path $env:CONFIG_MODULE; + } + + if (Test-Admin) { + Disable-WindowsUpdateAutoRestart; + } + + New-Alias -Force "sudo" gsudo; } - if (Test-Admin) { - Disable-WindowsUpdateAutoRestart; - } - - New-Alias -Force "sudo" gsudo; & $Action; }