From df1ab6ef099d31acf6e33a4937188d81eaa9a06c Mon Sep 17 00:00:00 2001 From: Nick Bolton Date: Fri, 6 Sep 2024 16:06:10 +0100 Subject: [PATCH] Only wait for elevated process to end when arg is set (#7488) * Only wait for elevated script to exit when required * Add missing space and only create lock file if wait enabled * Update ChangeLog * Fixed case for wait_for_exit --- ChangeLog | 1 + scripts/install_deps.py | 4 +++- scripts/lib/windows.py | 24 ++++++++++++++---------- 3 files changed, 18 insertions(+), 11 deletions(-) diff --git a/ChangeLog b/ChangeLog index ebb334c03..a7ed9c0cf 100644 --- a/ChangeLog +++ b/ChangeLog @@ -17,6 +17,7 @@ Enhancements: - #7474 FreeBSD GitHub runner with `vmactions/freebsd-vm@v1` - #7479 Add `BUILD.md` to get people started - #7485 Use `.venv` dir for as Python venv and cache +- #7488 Only wait for elevated process to end when arg is set # 1.15.1 diff --git a/scripts/install_deps.py b/scripts/install_deps.py index 4d6a71406..6dd7287fa 100755 --- a/scripts/install_deps.py +++ b/scripts/install_deps.py @@ -222,7 +222,9 @@ class Dependencies: if not self.args.skip_elevated: if not windows.is_admin(): - windows.run_elevated(__file__, "--only-elevated --skip-python") + windows.run_elevated( + __file__, "--only-elevated --skip-python", wait_for_exit=True + ) elif self.args.only_elevated: # The choco command should run from the elevated command. choco = windows.WindowsChoco() diff --git a/scripts/lib/windows.py b/scripts/lib/windows.py index 7b9fbdd05..ffd1cff35 100644 --- a/scripts/lib/windows.py +++ b/scripts/lib/windows.py @@ -30,12 +30,15 @@ WIX_FILE = f"{BUILD_DIR}/installer/Synergy.sln" MSI_FILE = f"{BUILD_DIR}/installer/bin/Release/Synergy.msi" -def run_elevated(script, args=None, use_sys_argv=True): +def run_elevated(script, args=None, use_sys_argv=True, wait_for_exit=False): if not args and use_sys_argv: args = " ".join(sys.argv[1:]) - env.persist_lock_file(LOCK_FILE) - command = f"{script} --pause-on-exit --lock-file {LOCK_FILE} {args}" + if wait_for_exit: + args += f" --lock-file {LOCK_FILE}" + env.persist_lock_file(LOCK_FILE) + + command = f"{script} {args} --pause-on-exit" print(f"Running script with elevated privileges: {command}") WINDOW_HANDLE = None @@ -60,14 +63,15 @@ def run_elevated(script, args=None, use_sys_argv=True): print("Script is running with elevated privileges") - with open(LOCK_FILE, "r") as f: - pid = f.read() + if wait_for_exit: + with open(LOCK_FILE, "r") as f: + pid = f.read() - print(f"Waiting for elevated process to exit: {pid}") - while os.path.exists(LOCK_FILE): - # Intentionally wait forever, since this code should not run where a developer - # has no control, such as in a CI environment. - pass + print(f"Waiting for elevated process to exit: {pid}") + while os.path.exists(LOCK_FILE): + # Intentionally wait forever, since this code should not run where a developer + # has no control, such as in a CI environment. + pass def is_admin():