From 6b41d7235b8e6d2bdca22c8dab800480b889dcdb Mon Sep 17 00:00:00 2001 From: Rolf Bjarne Kvinge Date: Thu, 28 Nov 2019 08:20:08 +0100 Subject: [PATCH 1/2] [xibuild] Clean up temporary files when done. --- tools/xibuild/Main.cs | 38 +++++++++++++++++++++----------------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/tools/xibuild/Main.cs b/tools/xibuild/Main.cs index 3c9ad4cb496e..aad31c500c55 100644 --- a/tools/xibuild/Main.cs +++ b/tools/xibuild/Main.cs @@ -115,23 +115,27 @@ static int RunTool (string toolPath, string combinedArgs, string baseConfigFile) { var tmpMSBuildExePathForConfig = Path.GetTempFileName (); var configFilePath = tmpMSBuildExePathForConfig + ".config"; - - GenerateAppConfig (configFilePath, baseConfigFile, out string MSBuildSdksPath); - - var psi = new ProcessStartInfo { - FileName = toolPath, - Arguments = combinedArgs, - UseShellExecute = false, - }; - // Required so that msbuild can read the correct config file - psi.EnvironmentVariables ["MSBUILD_EXE_PATH"] = tmpMSBuildExePathForConfig; - // MSBuildSDKsPath only works via an env var - psi.EnvironmentVariables ["MSBuildSDKsPath"] = MSBuildSdksPath; - - var p = Process.Start (psi); - - p.WaitForExit (); - return p.ExitCode; + try { + GenerateAppConfig (configFilePath, baseConfigFile, out string MSBuildSdksPath); + + var psi = new ProcessStartInfo { + FileName = toolPath, + Arguments = combinedArgs, + UseShellExecute = false, + }; + // Required so that msbuild can read the correct config file + psi.EnvironmentVariables ["MSBUILD_EXE_PATH"] = tmpMSBuildExePathForConfig; + // MSBuildSDKsPath only works via an env var + psi.EnvironmentVariables ["MSBuildSDKsPath"] = MSBuildSdksPath; + + var p = Process.Start (psi); + + p.WaitForExit (); + return p.ExitCode; + } finally { + File.Delete (tmpMSBuildExePathForConfig); + File.Delete (configFilePath); + } } static void GenerateAppConfig (string targetConfigFile, string baseConfigFile, out string MSBuildSdksPath) From 79819dff02a0625fd3261d7a46908c0f65135731 Mon Sep 17 00:00:00 2001 From: Rolf Bjarne Kvinge Date: Mon, 2 Dec 2019 18:42:52 +0100 Subject: [PATCH 2/2] Check if file exists before trying to delete it. --- tools/xibuild/Main.cs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tools/xibuild/Main.cs b/tools/xibuild/Main.cs index aad31c500c55..f4a0337b231a 100644 --- a/tools/xibuild/Main.cs +++ b/tools/xibuild/Main.cs @@ -133,8 +133,10 @@ static int RunTool (string toolPath, string combinedArgs, string baseConfigFile) p.WaitForExit (); return p.ExitCode; } finally { - File.Delete (tmpMSBuildExePathForConfig); - File.Delete (configFilePath); + if (File.Exists (tmpMSBuildExePathForConfig)) + File.Delete (tmpMSBuildExePathForConfig); + if (File.Exists (tmpMSBuildExePathForConfig)) + File.Delete (configFilePath); } }