Skip to content

Add meaningful message when an external process prevents tests cleanup #158

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 25, 2012
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions LibGit2Sharp.Tests/TestHelpers/DirectoryHelper.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.IO;
using System;
using System.IO;

namespace LibGit2Sharp.Tests.TestHelpers
{
Expand Down Expand Up @@ -46,7 +47,19 @@ public static void DeleteDirectory(string directoryPath)
}

File.SetAttributes(directoryPath, FileAttributes.Normal);
Directory.Delete(directoryPath, false);
try
{
Directory.Delete(directoryPath, false);
}
catch (IOException ex)
{
throw new IOException(string.Format("{0}The directory '{1}' could not be deleted!" +
"{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." +
"{0}Known and common causes include:" +
"{0}- Windows Search Indexer (go to the Indexing Options, in the Windows Control Panel, and exclude the bin folder of LibGit2Sharp.Tests)" +
"{0}- Antivirus (exclude the bin folder of LibGit2Sharp.Tests from the paths scanned by your real-time antivirus){0}",
Environment.NewLine, Path.GetFullPath(directoryPath)), ex);
}
}
}
}