Skip to content

Commit

Permalink
Cleanup ContainsParentDirectory and add checks in tests for unexpecte…
Browse files Browse the repository at this point in the history
…d paths
  • Loading branch information
Kevin Willford committed Oct 1, 2018
1 parent 8c8c06f commit 8eddf8b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 19 deletions.
12 changes: 5 additions & 7 deletions GVFS/GVFS.Common/ModifiedPathsDatabase.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using GVFS.Common.FileSystem;
using GVFS.Common.Tracing;

Expand Down Expand Up @@ -187,12 +185,12 @@ private bool TryParseRemoveLine(string line, out string key, out string error)

private bool ContainsParentDirectory(string modifiedPath)
{
string[] pathParts = modifiedPath.Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries);
StringBuilder parentFolder = new StringBuilder();
foreach (string pathPart in pathParts.Take(pathParts.Length - 1))
string[] pathParts = modifiedPath.Split(new char[] { GVFSConstants.GitPathSeparator }, StringSplitOptions.RemoveEmptyEntries);
string parentFolder = string.Empty;
for (int i = 0; i < pathParts.Length - 1; i++)
{
parentFolder.Append(pathPart + "/");
if (this.modifiedPaths.Contains(parentFolder.ToString()))
parentFolder += pathParts[i] + GVFSConstants.GitPathSeparatorString;
if (this.modifiedPaths.Contains(parentFolder))
{
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ public void CreateFileInFolderTest()
this.Enlistment.WaitForBackgroundOperations().ShouldEqual(true, "Background operations failed to complete.");

GVFSHelpers.ModifiedPathsShouldContain(this.fileSystem, this.Enlistment.DotGVFSRoot, folderName + "/");
GVFSHelpers.ModifiedPathsShouldNotContain(this.fileSystem, this.Enlistment.DotGVFSRoot, folderName + "/" + fileName);
}

[TestCase, Order(4)]
Expand All @@ -97,6 +98,7 @@ public void RenameEmptyFolderTest()
this.Enlistment.WaitForBackgroundOperations().ShouldEqual(true, "Background operations failed to complete.");

GVFSHelpers.ModifiedPathsShouldContain(this.fileSystem, this.Enlistment.DotGVFSRoot, expectedModifiedEntries);
GVFSHelpers.ModifiedPathsShouldNotContain(this.fileSystem, this.Enlistment.DotGVFSRoot, folderName + "/");
}

[TestCase, Order(5)]
Expand All @@ -111,6 +113,17 @@ public void RenameFolderTest()
renamedFolderName + "/",
};

string[] unexpectedModifiedEntries =
{
renamedFolderName + "/" + fileNames[0],
renamedFolderName + "/" + fileNames[1],
renamedFolderName + "/" + fileNames[2],
folderName + "/",
folderName + "/" + fileNames[0],
folderName + "/" + fileNames[1],
folderName + "/" + fileNames[2],
};

this.Enlistment.GetVirtualPathTo(folderName).ShouldNotExistOnDisk(this.fileSystem);
this.fileSystem.CreateDirectory(this.Enlistment.GetVirtualPathTo(folderName));
foreach (string fileName in fileNames)
Expand All @@ -125,6 +138,7 @@ public void RenameFolderTest()
this.Enlistment.WaitForBackgroundOperations().ShouldEqual(true, "Background operations failed to complete.");

GVFSHelpers.ModifiedPathsShouldContain(this.fileSystem, this.Enlistment.DotGVFSRoot, expectedModifiedEntries);
GVFSHelpers.ModifiedPathsShouldNotContain(this.fileSystem, this.Enlistment.DotGVFSRoot, unexpectedModifiedEntries);
}

[TestCase, Order(6)]
Expand All @@ -136,26 +150,17 @@ public void CaseOnlyRenameOfNewFolderKeepsModifiedPathsEntries()
Assert.Ignore("Powershell does not support case only renames.");
}

string[] expectedModifiedPathsEntriesAfterCreate =
{
"A Folder/",
};

string[] expectedModifiedPathsEntriesAfterRename =
{
"A folder/",
};

this.fileSystem.CreateDirectory(Path.Combine(this.Enlistment.RepoRoot, "Folder"));
this.fileSystem.CreateEmptyFile(Path.Combine(this.Enlistment.RepoRoot, "Folder", "testfile"));
this.Enlistment.WaitForBackgroundOperations().ShouldEqual(true, "Background operations failed to complete.");

GVFSHelpers.ModifiedPathsShouldContain(this.fileSystem, this.Enlistment.DotGVFSRoot, expectedModifiedPathsEntriesAfterCreate);
GVFSHelpers.ModifiedPathsShouldContain(this.fileSystem, this.Enlistment.DotGVFSRoot, "A Folder/");

this.fileSystem.RenameDirectory(this.Enlistment.RepoRoot, "Folder", "folder");
this.Enlistment.WaitForBackgroundOperations().ShouldEqual(true, "Background operations failed to complete.");

GVFSHelpers.ModifiedPathsShouldContain(this.fileSystem, this.Enlistment.DotGVFSRoot, expectedModifiedPathsEntriesAfterRename);
GVFSHelpers.ModifiedPathsShouldContain(this.fileSystem, this.Enlistment.DotGVFSRoot, "A folder/");
GVFSHelpers.ModifiedPathsShouldNotContain(this.fileSystem, this.Enlistment.DotGVFSRoot, "A folder/testfile");
}

[TestCase, Order(7)]
Expand Down

0 comments on commit 8eddf8b

Please sign in to comment.