public void ScrubbingDirectoriesWithMounts() { string rootDirectory = Path.Combine(TestOutputDirectory, nameof(ScrubbingDirectoriesWithMounts)); const string NonScrubbableMountName = "NonScrubbable"; string nonScrubbableMountPath = Path.Combine(rootDirectory, NonScrubbableMountName); const string ScrubbableMountName = "Scrubbable"; string scrubbableMountPath = Path.Combine(rootDirectory, ScrubbableMountName); const string NestedScrubbableMountName = "NestedScrubbable"; string nestedScrubbableMountPath = Path.Combine(scrubbableMountPath, NestedScrubbableMountName); MountPathExpander mountPathExpander = CreateMountPathExpander( new TestMount(NonScrubbableMountName, nonScrubbableMountPath, MountFeatures.Writable | MountFeatures.Readable), new TestMount(ScrubbableMountName, scrubbableMountPath, MountFeatures.Scrubbable), new TestMount(NestedScrubbableMountName, nestedScrubbableMountPath, MountFeatures.Scrubbable)); string f = WriteFile(Path.Combine(nonScrubbableMountPath, "D", "f")); string g1 = WriteFile(Path.Combine(scrubbableMountPath, "D", "g1")); string g2 = WriteFile(Path.Combine(scrubbableMountPath, "D", "g2")); string h = WriteFile(Path.Combine(scrubbableMountPath, "D", "E", "h")); string i = WriteFile(Path.Combine(scrubbableMountPath, "D", "F", "i")); string j = WriteFile(Path.Combine(nestedScrubbableMountPath, "D", "j")); var inBuild = new HashSet <string>(StringComparer.OrdinalIgnoreCase) { Path.Combine(scrubbableMountPath, "D", "E"), g1 }; var scrubber = new DirectoryScrubber( LoggingContext, m_loggingConfiguration, path => inBuild.Contains(path), pathsToScrub: new[] { Path.Combine(nonScrubbableMountPath, "D"), scrubbableMountPath }, blockedPaths: new string[0], nonDeletableRootDirectories: new string[0], mountPathExpander: mountPathExpander, maxDegreeParallelism: 2); scrubber.RemoveExtraneousFilesAndDirectories(new CancellationToken()); // NonScrubbable\D produces a warning. AssertWarningEventLogged(EventId.ScrubbingFailedBecauseDirectoryIsNotScrubbable); // f is in NonScrubbable. XAssert.IsTrue(File.Exists(f)); // g1 & h (via Scrubbable\D\E) is in build. XAssert.IsTrue(File.Exists(g1)); XAssert.IsTrue(File.Exists(h)); // NestedScrubbable, although not in build, but is a mount root. XAssert.IsTrue(Directory.Exists(nestedScrubbableMountPath)); // Scrubbed files/directories. XAssert.IsFalse(File.Exists(g2)); XAssert.IsFalse(File.Exists(i)); XAssert.IsFalse(Directory.Exists(Path.Combine(scrubbableMountPath, "D", "F"))); XAssert.IsFalse(File.Exists(j)); XAssert.IsFalse(Directory.Exists(Path.Combine(nestedScrubbableMountPath, "D"))); }
public MountScrubberTests(ITestOutputHelper output) : base(output) { RegisterEventSource(global::BuildXL.Engine.ETWLogger.Log); RegisterEventSource(global::BuildXL.Scheduler.ETWLogger.Log); RegisterEventSource(global::BuildXL.Processes.ETWLogger.Log); Scrubber = new DirectoryScrubber( new CancellationToken(), LoggingContext, m_loggingConfiguration, maxDegreeParallelism: 2); }
public void ScrubFilesAndDirectories() { // Create a layout with various paths. We will clean at the root dir. // Some files will be in the build, some out, and some paths excluded string rootDirectory = Path.Combine(TestOutputDirectory, nameof(ScrubFilesAndDirectories)); string a = WriteFile(Path.Combine(rootDirectory, "1", "1", "out.txt")); string b = WriteFile(Path.Combine(rootDirectory, "1", "out.txt")); string c = WriteFile(Path.Combine(rootDirectory, "2", "1", "in.txt")); string d = WriteFile(Path.Combine(rootDirectory, "2", "2", "in.txt")); string e = WriteFile(Path.Combine(rootDirectory, "2", "2", "out.txt")); string f = WriteFile(Path.Combine(rootDirectory, "3", "out.txt")); string g = WriteFile(Path.Combine(rootDirectory, "4", "out.txt")); string h = WriteFile(Path.Combine(rootDirectory, "5", "6", "out.txt")); string i = WriteFile(Path.Combine(rootDirectory, "5", "out.txt")); var inBuild = new HashSet <string>(StringComparer.OrdinalIgnoreCase) { c, d, Path.GetDirectoryName(f) }; var scrubber = new DirectoryScrubber( LoggingContext, m_loggingConfiguration, path => inBuild.Contains(path), pathsToScrub: new[] { rootDirectory }, blockedPaths: new[] { Path.Combine(rootDirectory, "1"), Path.Combine(rootDirectory, "5", "6") }, nonDeletableRootDirectories: new string[0], mountPathExpander: null, maxDegreeParallelism: 2); scrubber.RemoveExtraneousFilesAndDirectories(new CancellationToken()); // Files in the "1" directory should still exist even though they were not in the build, since that directory was excluded. XAssert.IsTrue(File.Exists(a)); XAssert.IsTrue(File.Exists(b)); // The files that were in the build should still exist. XAssert.IsTrue(File.Exists(c)); XAssert.IsTrue(File.Exists(d)); XAssert.IsTrue(File.Exists(f)); // File in the blocked path still exists. XAssert.IsTrue(File.Exists(h)); // The file outside of the build should not exist. XAssert.IsFalse(File.Exists(e)); XAssert.IsFalse(Directory.Exists(Path.GetDirectoryName(g))); XAssert.IsFalse(File.Exists(i)); }
private void RunScrubberWithPipGraph( TestEnv env, PipGraph pipGraph, string[] pathsToScrub, MountPathExpander mountPathExpander = null) { var scrubber = new DirectoryScrubber( LoggingContext, m_loggingConfiguration, isPathInBuild: p => pipGraph.IsPathInBuild(env.Paths.CreateAbsolutePath(p)), pathsToScrub: pathsToScrub, blockedPaths: new string[0], nonDeletableRootDirectories: pipGraph.AllDirectoriesContainingOutputs().Select(p => env.Paths.Expand(p)), mountPathExpander: mountPathExpander, maxDegreeParallelism: 2); bool removed = scrubber.RemoveExtraneousFilesAndDirectories(new CancellationToken()); XAssert.IsTrue(removed); }
public void DoNotScrubDeclaredOutputDirectories() { string rootDirectory = Path.Combine(TestOutputDirectory, nameof(ScrubFilesAndDirectories)); string a = WriteFile(Path.Combine(rootDirectory, "1", "1", "out.txt")); var inBuild = new HashSet <string>(StringComparer.OrdinalIgnoreCase) { Path.GetDirectoryName(a) }; var scrubber = new DirectoryScrubber( LoggingContext, m_loggingConfiguration, path => inBuild.Contains(path), pathsToScrub: new[] { Path.GetDirectoryName(a) }, blockedPaths: new string[] { }, nonDeletableRootDirectories: new string[0], mountPathExpander: null, maxDegreeParallelism: 2); scrubber.RemoveExtraneousFilesAndDirectories(new CancellationToken()); XAssert.IsTrue(File.Exists(a)); }
public void DontScrubBlockedPathsEvenIfAskedTo() { string rootDirectory = Path.Combine(TestOutputDirectory, nameof(ScrubFilesAndDirectories)); string a = WriteFile(Path.Combine(rootDirectory, "a", "b", "c", "out.txt")); var inBuild = new HashSet <string>(StringComparer.OrdinalIgnoreCase) { }; var scrubber = new DirectoryScrubber( LoggingContext, m_loggingConfiguration, path => inBuild.Contains(path), pathsToScrub: new[] { rootDirectory }, blockedPaths: new[] { rootDirectory }, nonDeletableRootDirectories: new string[0], mountPathExpander: null, maxDegreeParallelism: 2); scrubber.RemoveExtraneousFilesAndDirectories(new CancellationToken()); // The file should still exist since it is under a blocked path XAssert.IsTrue(File.Exists(a)); }