Skip to content

Commit d0f541b

Browse files
committed
Add meaningful message when an external process prevents tests cleanup
1 parent 1c1f012 commit d0f541b

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

LibGit2Sharp.Tests/TestHelpers/DirectoryHelper.cs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System.IO;
1+
using System;
2+
using System.IO;
23

34
namespace LibGit2Sharp.Tests.TestHelpers
45
{
@@ -46,7 +47,19 @@ public static void DeleteDirectory(string directoryPath)
4647
}
4748

4849
File.SetAttributes(directoryPath, FileAttributes.Normal);
49-
Directory.Delete(directoryPath, false);
50+
try
51+
{
52+
Directory.Delete(directoryPath, false);
53+
}
54+
catch (IOException ex)
55+
{
56+
throw new IOException(string.Format("{0}The directory '{1}' could not be deleted!" +
57+
"{0}Most of the time, this is due to an external process accessing the files in the temporary repositories created during the test runs, and keeping a handle on the directory, thus preventing the deletion of those files." +
58+
"{0}Known and common causes include:" +
59+
"{0}- Windows Search Indexer (go to the Indexing Options, in the Windows Control Panel, and exclude the bin folder of LibGit2Sharp.Tests)" +
60+
"{0}- Antivirus (exclude the bin folder of LibGit2Sharp.Tests from the paths scanned by your real-time antivirus){0}",
61+
Environment.NewLine, Path.GetFullPath(directoryPath)), ex);
62+
}
5063
}
5164
}
5265
}

0 commit comments

Comments
 (0)