Browse Source

Clean up the per-session ILSpy.xml temp dir

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
pull/3755/head
Siegfried Pammer 2 months ago
parent
commit
9603ef815a
  1. 27
      ILSpy.Tests/TestApp.axaml.cs

27
ILSpy.Tests/TestApp.axaml.cs

@ -40,11 +40,36 @@ public class TestApp : ProductionApp @@ -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 */ }
}
}

Loading…
Cancel
Save