From 192d2c7a1eb6e2ffddb44b9f9f7d4ccae08bdc7b Mon Sep 17 00:00:00 2001 From: dave caruso Date: Thu, 28 Mar 2024 16:46:11 -0700 Subject: [PATCH] windows: skip cleaning up old binary --- src/cli/upgrade_command.zig | 46 +++++-------------------------------- 1 file changed, 6 insertions(+), 40 deletions(-) diff --git a/src/cli/upgrade_command.zig b/src/cli/upgrade_command.zig index df8e24eec16c03..2d7f0f43e68c0f 100644 --- a/src/cli/upgrade_command.zig +++ b/src/cli/upgrade_command.zig @@ -948,46 +948,12 @@ pub const UpgradeCommand = struct { if (Environment.isWindows) { if (outdated_filename) |to_remove| { - current_executable_buf[target_dir_.len] = '\\'; - const delete_old_script = try std.fmt.allocPrint( - ctx.allocator, - // What is this? - // 1. spawns powershell - // 2. waits for all processes with the same path as the current executable to exit (including the current process) - // 3. deletes the old executable - // - // probably possible to hit a race condition, but i think the worst case is simply the file not getting deleted. - // - // in that edge case, the next time you upgrade it will simply override itself, fixing the bug. - // - // -NoNewWindow doesnt work, will keep the parent alive it seems - // -WindowStyle Hidden seems to just do nothing, not sure why. - // Using -WindowStyle Minimized seems to work, but you can spot a powershell icon appear in your taskbar for about ~1 second - // - // Alternative: we could simply do nothing and leave the `.outdated` file. - \\Start-Process powershell.exe -WindowStyle Minimized -ArgumentList "-NoProfile","-ExecutionPolicy","Bypass","-Command",'&{{$ErrorActionPreference=''SilentlyContinue''; Get-Process|Where-Object{{ $_.Path -eq ''{s}'' }}|Wait-Process; Remove-Item -Path ''{s}'' -Force }};'; exit - , - .{ - destination_executable, - to_remove, - }, - ); - - var delete_argv = [_]string{ - "powershell.exe", - "-NoProfile", - "-ExecutionPolicy", - "Bypass", - "-Command", - delete_old_script, - }; - - _ = std.ChildProcess.run(.{ - .allocator = ctx.allocator, - .argv = &delete_argv, - .cwd = tmpdir_path, - .max_output_bytes = 512, - }) catch {}; + // TODO: this file gets left on disk + // + // We should remove it, however we cannot remove an exe that is still running. + // A prior approach was to spawn a subprocess to remove the file, but that + // would open a terminal window, which steals user focus (even if minimized). + _ = to_remove; } } }