From 1bb82d744a94ceb3239af7bd9cce013a6a35b806 Mon Sep 17 00:00:00 2001 From: Caelan Sayler Date: Mon, 26 May 2025 21:44:41 +0100 Subject: [PATCH] Apply error handling for elevated process --- src/bins/src/commands/apply_windows_impl.rs | 19 +++++++++++++++++-- .../Locators/WindowsVelopackLocator.cs | 2 +- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/bins/src/commands/apply_windows_impl.rs b/src/bins/src/commands/apply_windows_impl.rs index 218bd2a3..9d35e995 100644 --- a/src/bins/src/commands/apply_windows_impl.rs +++ b/src/bins/src/commands/apply_windows_impl.rs @@ -51,14 +51,29 @@ pub fn apply_package_impl(old_locator: &VelopackLocator, package: &PathBuf, run_ } else { info!("Re-launching as administrator to update in {:?}", root_path); - let args: Vec = vec!["--norestart".into(), "--package".into(), package.into()]; + let args: Vec = vec!["--norestart".into(), "--package".into(), package.into(), "--root".into(), root_path.into()]; let exe_path = std::env::current_exe()?; let work_dir: Option = None; // same as this process let process_handle = process::run_process_as_admin(&exe_path, args, work_dir, false)?; info!("Waiting (up to 10 minutes) for elevated process to exit..."); let result = process::wait_for_process_to_exit(process_handle, Some(Duration::from_secs(10 * 60)))?; - info!("Elevated process has exited ({:?}).", result); + + match result { + process::WaitResult::WaitTimeout => { + bail!("Elevated process has not exited within 10 minutes. (TIMEOUT)"); + } + process::WaitResult::ExitCode(code) => { + if code != 0 { + bail!("Elevated process has exited with ERROR: {}.", code); + } else { + info!("Elevated process has run successfully."); + } + } + process::WaitResult::NoWaitRequired => { + info!("Elevated process has not required waiting."); + } + } return Ok(new_locator); } } diff --git a/src/lib-csharp/Locators/WindowsVelopackLocator.cs b/src/lib-csharp/Locators/WindowsVelopackLocator.cs index c69e90d9..751d51a2 100644 --- a/src/lib-csharp/Locators/WindowsVelopackLocator.cs +++ b/src/lib-csharp/Locators/WindowsVelopackLocator.cs @@ -123,7 +123,7 @@ namespace Velopack.Locators var tempTargetUpdateExe = Path.Combine(TempAppRootDirectory, "Update.exe"); if (File.Exists(UpdateExePath) && !File.Exists(tempTargetUpdateExe)) { initLog.Warn("Application directory is not writable. Copying Update.exe to temp location: " + tempTargetUpdateExe); - Debugger.Launch(); + // Debugger.Launch(); Directory.CreateDirectory(TempAppRootDirectory); File.Copy(UpdateExePath, tempTargetUpdateExe); }