Skip to content
Permalink
Browse files

Merge pull request #1503 from github/case-sensitive-followups

restore mixed-case prefetch folder list tests and tidy MirrorProviders

On case-insensitive filesystems, we can restore the use of
non-case-matching mixed-case file and folder paths in several
PrefetchVerbTests, while retaining case-sensitive exact matches
on Linux.

We also use the PathComparison we set in our MirrorProviders to
actually perform path comparisons, and add a PathComparer for
use on Windows in particular.
  • Loading branch information...
chrisd8088 committed Sep 18, 2019
2 parents 2769949 + 90b15fb commit 8db7e38e69c571a5e1ecaaf944385d91204a1cac
@@ -17,6 +17,19 @@ public class PrefetchVerbTests : TestsWithEnlistmentPerFixture
private const string PrefetchCommitsAndTreesLock = "prefetch-commits-trees.lock";
private const string LsTreeTypeInPathBranchName = "FunctionalTests/20181105_LsTreeTypeInPath";

// on case-insensitive filesystems, test case-blind matching in
// folder lists using "gvfs/" instead of "GVFS/"
private static readonly string PrefetchGVFSFolder = FileSystemHelpers.CaseSensitiveFileSystem ? "GVFS" : "gvfs";
private static readonly string PrefetchGVFSFolderPath = PrefetchGVFSFolder + "/";
private static readonly string[] PrefetchFolderList = new string[]
{
"# A comment",
" ",
PrefetchGVFSFolderPath, // "GVFS/" or "gvfs/"
PrefetchGVFSFolderPath + PrefetchGVFSFolder, // "GVFS/GVFS" or "gvfs/gvfs"
PrefetchGVFSFolderPath,
};

private FileSystemRunner fileSystem;

public PrefetchVerbTests()
@@ -82,17 +95,7 @@ public void PrefetchIsAllowedToDoNothing()
public void PrefetchFolderListFromFile()
{
string tempFilePath = Path.Combine(Path.GetTempPath(), "temp.file");
File.WriteAllLines(
tempFilePath,
new[]
{
"# A comment",
" ",
"GVFS/",
"GVFS/GVFS",
"GVFS/"
});

File.WriteAllLines(tempFilePath, PrefetchFolderList);
this.ExpectBlobCount(this.Enlistment.Prefetch("--folders-list \"" + tempFilePath + "\""), 279);
File.Delete(tempFilePath);
}
@@ -161,12 +164,14 @@ public void PrefetchFilesFromFileListFile()
[TestCase, Order(13)]
public void PrefetchFilesFromFileListStdIn()
{
// on case-insensitive filesystems, test case-blind matching
// using "App.config" instead of "app.config"
string input = string.Join(
Environment.NewLine,
new[]
{
Path.Combine("GVFS", "GVFS", "packages.config"),
Path.Combine("GVFS", "GVFS.FunctionalTests", "app.config")
Path.Combine("GVFS", "GVFS.FunctionalTests", FileSystemHelpers.CaseSensitiveFileSystem ? "app.config" : "App.config")
});

this.ExpectBlobCount(this.Enlistment.Prefetch("--stdin-files-list", standardInput: input), 2);
@@ -175,17 +180,7 @@ public void PrefetchFilesFromFileListStdIn()
[TestCase, Order(14)]
public void PrefetchFolderListFromStdin()
{
string input = string.Join(
Environment.NewLine,
new[]
{
"# A comment",
" ",
"GVFS/",
"GVFS/GVFS",
"GVFS/"
});

string input = string.Join(Environment.NewLine, PrefetchFolderList);
this.ExpectBlobCount(this.Enlistment.Prefetch("--stdin-folders-list", standardInput: input), 279);
}

@@ -44,7 +44,7 @@ public abstract class GitRepoTests
"foo.cpp", // Changes to a folder in one test
"FilenameEncoding",
"GitCommandsTests",
"GVFLT_MultiThreadTest",
"GVFLT_MultiThreadTest", // Required by DeleteFolderAndChangeBranchToFolderWithDifferentCase test in sparse mode
"GVFlt_BugRegressionTest",
"GVFlt_DeleteFileTest",
"GVFlt_DeleteFolderTest",
@@ -10,8 +10,9 @@ public class MacFileSystemVirtualizer : FileSystemVirtualizer
{
private VirtualizationInstance virtualizationInstance = new VirtualizationInstance();

protected override StringComparison PathComparison => StringComparison.OrdinalIgnoreCase;

protected override StringComparison PathComparison => StringComparison.OrdinalIgnoreCase;
protected override StringComparer PathComparer => StringComparer.OrdinalIgnoreCase;

public override bool TryConvertVirtualizationRoot(string directory, out string error)
{
Result result = VirtualizationInstance.ConvertDirectoryToVirtualizationRoot(directory);
@@ -243,7 +244,7 @@ private bool TryGetSymLinkTarget(string relativePath, out string symLinkTarget)
targetBuffer[bytesRead] = 0;
symLinkTarget = Encoding.UTF8.GetString(targetBuffer);

if (symLinkTarget.StartsWith(this.Enlistment.MirrorRoot, StringComparison.OrdinalIgnoreCase))
if (symLinkTarget.StartsWith(this.Enlistment.MirrorRoot, PathComparison))
{
// Link target is an absolute path inside the MirrorRoot.
// The target needs to be adjusted to point inside the src root
@@ -13,6 +13,7 @@ public class WindowsFileSystemVirtualizer : FileSystemVirtualizer, IRequiredCall
private ConcurrentDictionary<Guid, ActiveEnumeration> activeEnumerations = new ConcurrentDictionary<Guid, ActiveEnumeration>();

protected override StringComparison PathComparison => StringComparison.OrdinalIgnoreCase;
protected override StringComparer PathComparer => StringComparer.OrdinalIgnoreCase;

public override bool TryConvertVirtualizationRoot(string directory, out string error)
{
@@ -76,7 +77,7 @@ public HResult StartDirectoryEnumerationCallback(int commandId, Guid enumeration
// what is on disk, and it assumes that both lists are already sorted.
ActiveEnumeration activeEnumeration = new ActiveEnumeration(
this.GetChildItems(relativePath)
.OrderBy(file => file.Name, StringComparer.OrdinalIgnoreCase)
.OrderBy(file => file.Name, PathComparer)
.ToList());

if (!this.activeEnumerations.TryAdd(enumerationId, activeEnumeration))
@@ -272,7 +273,7 @@ private HResult QueryFileName(string relativePath)

string parentDirectory = Path.GetDirectoryName(relativePath);
string childName = Path.GetFileName(relativePath);
if (this.GetChildItems(parentDirectory).Any(child => child.Name.Equals(childName, StringComparison.OrdinalIgnoreCase)))
if (this.GetChildItems(parentDirectory).Any(child => child.Name.Equals(childName, PathComparison)))
{
return HResult.Ok;
}
@@ -8,8 +8,9 @@ namespace MirrorProvider
public abstract class FileSystemVirtualizer
{
protected Enlistment Enlistment { get; private set; }

protected abstract StringComparison PathComparison { get; }

protected abstract StringComparison PathComparison { get; }
protected abstract StringComparer PathComparer { get; }

public abstract bool TryConvertVirtualizationRoot(string directory, out string error);
public virtual bool TryStartVirtualizationInstance(Enlistment enlistment, out string error)

0 comments on commit 8db7e38

Please sign in to comment.
You can’t perform that action at this time.