From 9603ef815a0eee3dda0c4d34da622da6e05cd90d Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Sun, 3 May 2026 19:27:51 +0200 Subject: [PATCH] Clean up the per-session ILSpy.xml temp dir MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit TestApp routes ILSpySettings to a fresh GUID dir under %TEMP%/ILSpy.Avalonia.Tests/ so production settings stay untouched, but the dirs were never removed — hundreds piled up across runs. Register a ProcessExit handler that deletes the active session's dir, plus sweep any leftovers from previous runs at startup so an interrupted session doesn't strand a stale folder forever. Both deletes are best-effort to avoid a Windows file-lock crash on shutdown. Assisted-by: Claude:claude-opus-4-7:Claude Code --- ILSpy.Tests/TestApp.axaml.cs | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/ILSpy.Tests/TestApp.axaml.cs b/ILSpy.Tests/TestApp.axaml.cs index b9baf6fb6..73e2129e7 100644 --- a/ILSpy.Tests/TestApp.axaml.cs +++ b/ILSpy.Tests/TestApp.axaml.cs @@ -40,11 +40,36 @@ public class TestApp : ProductionApp public override void OnFrameworkInitializationCompleted() { - var dir = Path.Combine(Path.GetTempPath(), "ILSpy.Tests", Guid.NewGuid().ToString("N")); + var sessionsRoot = Path.Combine(Path.GetTempPath(), "ILSpy.Tests"); + // Sweep any leftover session dirs from previous runs first — ProcessExit-time cleanup + // is best-effort and the active session's settings file is sometimes still locked when + // the runtime tears down, leaving one orphan per process. This catches them next run. + SweepLeftovers(sessionsRoot); + + var dir = Path.Combine(sessionsRoot, Guid.NewGuid().ToString("N")); Directory.CreateDirectory(dir); var configPath = Path.Combine(dir, "ILSpy.xml"); ILSpySettings.SettingsFilePathProvider = () => configPath; + AppDomain.CurrentDomain.ProcessExit += (_, _) => TryDeleteDirectory(dir); var composition = AppComposition.Initialize(); } + + static void SweepLeftovers(string sessionsRoot) + { + if (!Directory.Exists(sessionsRoot)) + return; + foreach (var sub in Directory.EnumerateDirectories(sessionsRoot)) + TryDeleteDirectory(sub); + } + + static void TryDeleteDirectory(string dir) + { + try + { + if (Directory.Exists(dir)) + Directory.Delete(dir, recursive: true); + } + catch { /* best-effort — don't crash on shutdown if a file is briefly locked */ } + } }