From 8fb126a0917106d159cd7b2d3a72223ccc6d6a86 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 982da29d..1f17cc5e 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; }