From dfc5b531fcb5a5a9a4e8e73927a919267ba8fad4 Mon Sep 17 00:00:00 2001 From: Caelan Sayler Date: Sun, 27 Feb 2022 13:14:11 +0000 Subject: [PATCH] More aggressively retry when creating stub executables, and do not stop the release if this fails. --- src/SquirrelCli/Program.cs | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/src/SquirrelCli/Program.cs b/src/SquirrelCli/Program.cs index ba066125..baef21fc 100644 --- a/src/SquirrelCli/Program.cs +++ b/src/SquirrelCli/Program.cs @@ -247,8 +247,7 @@ namespace SquirrelCli .Where(x => !x.Name.Contains("squirrel.exe", StringComparison.InvariantCultureIgnoreCase)) .Where(x => Utility.IsFileTopLevelInPackage(x.FullName, pkgPath)) .Where(x => Utility.ExecutableUsesWin32Subsystem(x.FullName)) - .ForEachAsync(x => createExecutableStubForExe(x.FullName)) - .Wait(); + .ForEach(x => createExecutableStubForExe(x.FullName)); // sign all exe's in this package new DirectoryInfo(pkgPath).GetAllFilesRecursively() @@ -376,17 +375,23 @@ namespace SquirrelCli } } - static async Task createExecutableStubForExe(string exeToCopy) + static void createExecutableStubForExe(string exeToCopy) { - var target = Path.Combine( - Path.GetDirectoryName(exeToCopy), - Path.GetFileNameWithoutExtension(exeToCopy) + "_ExecutionStub.exe"); + try { + var target = Path.Combine( + Path.GetDirectoryName(exeToCopy), + Path.GetFileNameWithoutExtension(exeToCopy) + "_ExecutionStub.exe"); - await Utility.CopyToAsync(HelperExe.StubExecutablePath, target); + Utility.Retry(() => File.Copy(HelperExe.StubExecutablePath, target, true)); - using var writer = new Microsoft.NET.HostModel.ResourceUpdater(target, true); - writer.AddResourcesFromPEImage(exeToCopy); - writer.Update(); + Utility.Retry(() => { + using var writer = new Microsoft.NET.HostModel.ResourceUpdater(target, true); + writer.AddResourcesFromPEImage(exeToCopy); + writer.Update(); + }); + } catch (Exception ex) { + Log.ErrorException($"Error creating StubExecutable and copying resources for '{exeToCopy}'. This stub may or may not work properly.", ex); + } } }