Attempt to remove watchman watch directories when enlistment is deleted

This commit is contained in:
Kevin Willford 2019-11-07 16:53:12 -07:00
Родитель 77c552c64d
Коммит 5c9b30a730
2 изменённых файлов: 55 добавлений и 0 удалений

Просмотреть файл

@ -1,5 +1,8 @@
using System;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
namespace Scalar.FunctionalTests.Tools
{
@ -53,6 +56,45 @@ namespace Scalar.FunctionalTests.Tools
}
}
public static string GetProgramLocation(string processName)
{
ProcessResult result = ProcessHelper.Run(GetProgramLocator(), processName);
if (result.ExitCode != 0)
{
return null;
}
string firstPath =
string.IsNullOrWhiteSpace(result.Output)
? null
: result.Output.Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries).FirstOrDefault();
if (firstPath == null)
{
return null;
}
try
{
return Path.GetDirectoryName(firstPath);
}
catch (IOException)
{
return null;
}
}
private static string GetProgramLocator()
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
return "where";
}
else
{
return "which";
}
}
private static string StartProcess(Process executingProcess, Stream inputStream = null)
{
executingProcess.Start();

Просмотреть файл

@ -122,6 +122,19 @@ namespace Scalar.FunctionalTests.Tools
public void DeleteEnlistment()
{
string watchmanLocation = ProcessHelper.GetProgramLocation("watchman");
if (!string.IsNullOrEmpty(watchmanLocation))
{
try
{
ProcessHelper.Run(Path.Combine(watchmanLocation, "watchman"), $"watch-del {this.RepoRoot}");
}
catch (Exception ex)
{
Console.WriteLine($"Failed to delete watch on {this.RepoRoot}. {ex.ToString()}");
}
}
TestResultsHelper.OutputScalarLogs(this);
RepositoryHelpers.DeleteTestDirectory(this.EnlistmentRoot);
}