Skip to content

Commit

Permalink
use platform-specific property for case matching
Browse files Browse the repository at this point in the history
This only applies to on-disk operations like locating the ".git"
directory or ".idx" files, etc. -- the repository contents remain
case-insensitive.

Co-authored-by: Chris Darroch <chrisd8088@github.com>
  • Loading branch information
kivikakk and chrisd8088 committed Aug 23, 2019
1 parent e534dfc commit e6eb054
Show file tree
Hide file tree
Showing 35 changed files with 108 additions and 57 deletions.
4 changes: 2 additions & 2 deletions GVFS/FastFetch/Index.cs
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ private void ParseIndex(Stream indexStream)

this.tracer.RelatedEvent(EventLevel.Informational, "IndexData", new EventMetadata() { { "Index", this.updatedIndexPath }, { "Version", this.IndexVersion }, { "entryCount", this.entryCount } }, Keywords.Telemetry);

this.indexEntryOffsets = new Dictionary<string, long>((int)this.entryCount, StringComparer.OrdinalIgnoreCase);
this.indexEntryOffsets = new Dictionary<string, long>((int)this.entryCount, GVFSPlatform.Instance.Constants.PathComparer);

int previousPathLength = 0;
byte[] pathBuffer = new byte[MaxPathBufferSize];
Expand Down Expand Up @@ -736,4 +736,4 @@ private class IndexEntryTime
}
}
}
}
}
2 changes: 1 addition & 1 deletion GVFS/FastFetch/WorkingTree.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public static void ForAllDirectories(DirectoryInfo dir, Action<string, FileInfo[

Parallel.ForEach(
dir.EnumerateDirectories().Where(subdir =>
(!subdir.Name.Equals(GVFSConstants.DotGit.Root, StringComparison.OrdinalIgnoreCase) &&
(!subdir.Name.Equals(GVFSConstants.DotGit.Root, GVFSPlatform.Instance.Constants.PathComparison) &&
!subdir.Attributes.HasFlag(FileAttributes.ReparsePoint))),
subdir => { ForAllDirectories(subdir, asyncParallelCallback); });
}
Expand Down
2 changes: 1 addition & 1 deletion GVFS/GVFS.Common/FileSystem/HooksInstaller.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public static string MergeHooksData(string[] defaultHooksLines, string filename,
{
IEnumerable<string> valuableHooksLines = defaultHooksLines.Where(line => !string.IsNullOrEmpty(line.Trim()));

if (valuableHooksLines.Contains(GVFSPlatform.Instance.Constants.GVFSHooksExecutableName, StringComparer.OrdinalIgnoreCase))
if (valuableHooksLines.Contains(GVFSPlatform.Instance.Constants.GVFSHooksExecutableName, GVFSPlatform.Instance.Constants.PathComparer))
{
throw new HooksConfigurationException(
$"{GVFSPlatform.Instance.Constants.GVFSHooksExecutableName} should not be specified in the configuration for "
Expand Down
22 changes: 22 additions & 0 deletions GVFS/GVFS.Common/GVFSPlatform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,28 @@ public abstract class GVFSPlatformConstants
/// </summary>
public abstract HashSet<string> UpgradeBlockingProcesses { get; }

public abstract bool CaseSensitiveFileSystem { get; }

public StringComparison PathComparison
{
get
{
return this.CaseSensitiveFileSystem ?
StringComparison.Ordinal :
StringComparison.OrdinalIgnoreCase;
}
}

public StringComparer PathComparer
{
get
{
return this.CaseSensitiveFileSystem ?
StringComparer.Ordinal :
StringComparer.OrdinalIgnoreCase;
}
}

public string GVFSHooksExecutableName
{
get { return "GVFS.Hooks" + this.ExecutableExtension; }
Expand Down
8 changes: 4 additions & 4 deletions GVFS/GVFS.Common/GitHubUpgrader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public class GitHubUpgrader : ProductUpgrader
private const string GitSigner = "Johannes Schindelin";
private const string GitCertIssuer = "COMODO RSA Code Signing CA";

private static readonly HashSet<string> GVFSInstallerFileNamePrefixCandidates = new HashSet<string>(StringComparer.OrdinalIgnoreCase)
private static readonly HashSet<string> GVFSInstallerFileNamePrefixCandidates = new HashSet<string>(GVFSPlatform.Instance.Constants.PathComparer)
{
"SetupGVFS",
"VFSForGit"
Expand Down Expand Up @@ -152,7 +152,7 @@ public override bool TryDownloadNewestVersion(out string errorMessage)

foreach (Asset asset in this.newestRelease.Assets)
{
bool targetOSMatch = string.Equals(Path.GetExtension(asset.Name), GVFSPlatform.Instance.Constants.InstallerExtension, StringComparison.OrdinalIgnoreCase);
bool targetOSMatch = string.Equals(Path.GetExtension(asset.Name), GVFSPlatform.Instance.Constants.InstallerExtension, GVFSPlatform.Instance.Constants.PathComparison);
bool isGitAsset = this.IsGitAsset(asset);
bool isGVFSAsset = isGitAsset ? false : this.IsGVFSAsset(asset);
if (!targetOSMatch || (!isGVFSAsset && !isGitAsset))
Expand Down Expand Up @@ -461,7 +461,7 @@ private bool TryGetLocalInstallerPath(string assetId, out string path, out strin
{
foreach (Asset asset in this.newestRelease.Assets)
{
if (string.Equals(Path.GetExtension(asset.Name), GVFSPlatform.Instance.Constants.InstallerExtension, StringComparison.OrdinalIgnoreCase))
if (string.Equals(Path.GetExtension(asset.Name), GVFSPlatform.Instance.Constants.InstallerExtension, GVFSPlatform.Instance.Constants.PathComparison))
{
path = asset.LocalPath;
if (assetId == GitAssetId && this.IsGitAsset(asset))
Expand Down Expand Up @@ -497,7 +497,7 @@ private bool AssetInstallerNameCompare(Asset asset, IEnumerable<string> expected
{
foreach (string fileNamePrefix in expectedFileNamePrefixes)
{
if (asset.Name.StartsWith(fileNamePrefix, StringComparison.OrdinalIgnoreCase))
if (asset.Name.StartsWith(fileNamePrefix, GVFSPlatform.Instance.Constants.PathComparison))
{
return true;
}
Expand Down
4 changes: 2 additions & 2 deletions GVFS/GVFS.Common/Maintenance/GitMaintenanceStep.cs
Original file line number Diff line number Diff line change
Expand Up @@ -150,12 +150,12 @@ public void GetPackFilesInfo(out int count, out long size, out bool hasKeep)
{
string extension = Path.GetExtension(info.Name);

if (string.Equals(extension, ".pack", StringComparison.OrdinalIgnoreCase))
if (string.Equals(extension, ".pack", GVFSPlatform.Instance.Constants.PathComparison))
{
count++;
size += info.Length;
}
else if (string.Equals(extension, ".keep", StringComparison.OrdinalIgnoreCase))
else if (string.Equals(extension, ".keep", GVFSPlatform.Instance.Constants.PathComparison))
{
hasKeep = true;
}
Expand Down
2 changes: 1 addition & 1 deletion GVFS/GVFS.Common/Maintenance/GitProcessChecker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public virtual IEnumerable<int> GetRunningGitProcessIds()
{
Process[] allProcesses = Process.GetProcesses();
return allProcesses
.Where(x => x.ProcessName.Equals("git", StringComparison.OrdinalIgnoreCase))
.Where(x => x.ProcessName.Equals("git", GVFSPlatform.Instance.Constants.PathComparison))
.Select(x => x.Id);
}
}
Expand Down
2 changes: 1 addition & 1 deletion GVFS/GVFS.Common/Maintenance/PackfileMaintenanceStep.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public List<string> CleanStaleIdxFiles(out int numDeletionBlocked)

foreach (DirectoryItemInfo info in packDirContents)
{
if (string.Equals(Path.GetExtension(info.Name), ".idx", StringComparison.OrdinalIgnoreCase))
if (string.Equals(Path.GetExtension(info.Name), ".idx", GVFSPlatform.Instance.Constants.PathComparison))
{
string pairedPack = Path.ChangeExtension(info.FullName, ".pack");

Expand Down
2 changes: 1 addition & 1 deletion GVFS/GVFS.Common/Maintenance/PrefetchStep.cs
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ private void UpdateKeepPacks()
.FileSystem
.ItemsInDirectory(this.Context.Enlistment.GitPackRoot)
.Where(item => item.Name.StartsWith(prefix)
&& string.Equals(Path.GetExtension(item.Name), ".pack", StringComparison.OrdinalIgnoreCase))
&& string.Equals(Path.GetExtension(item.Name), ".pack", GVFSPlatform.Instance.Constants.PathComparison))
.FirstOrDefault();
if (info == null)
{
Expand Down
2 changes: 1 addition & 1 deletion GVFS/GVFS.Common/RepoMetadata.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public static bool TryInitialize(ITracer tracer, PhysicalFileSystem fileSystem,
string dictionaryPath = Path.Combine(dotGVFSPath, GVFSConstants.DotGVFS.Databases.RepoMetadata);
if (Instance != null)
{
if (!Instance.repoMetadata.DataFilePath.Equals(dictionaryPath, StringComparison.OrdinalIgnoreCase))
if (!Instance.repoMetadata.DataFilePath.Equals(dictionaryPath, GVFSPlatform.Instance.Constants.PathComparison))
{
throw new InvalidOperationException(
string.Format(
Expand Down
2 changes: 2 additions & 0 deletions GVFS/GVFS.Platform.Mac/MacPlatform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,8 @@ public override string RunUpdateMessage
{
get { return $"Run {UpgradeConfirmMessage}."; }
}

public override bool CaseSensitiveFileSystem => false;
}
}
}
2 changes: 1 addition & 1 deletion GVFS/GVFS.Platform.POSIX/POSIXPlatform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ public override string ProgramLocaterCommand

public override HashSet<string> UpgradeBlockingProcesses
{
get { return new HashSet<string>(StringComparer.OrdinalIgnoreCase) { "GVFS.Mount", "git", "wish" }; }
get { return new HashSet<string>(GVFSPlatform.Instance.Constants.PathComparer) { "GVFS.Mount", "git", "wish" }; }
}

public override bool SupportsUpgradeWhileRunning => true;
Expand Down
2 changes: 1 addition & 1 deletion GVFS/GVFS.Platform.Windows/ProjFSFilter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@ public bool TryPrepareFolderForCallbacks(string folderPath, out string error, ou
{
exception = e;

if (e.FileName.Equals(ProjFSManagedLibFileName, StringComparison.OrdinalIgnoreCase))
if (e.FileName.Equals(ProjFSManagedLibFileName, GVFSPlatform.Instance.Constants.PathComparison))
{
error = $"Failed to load {ProjFSManagedLibFileName}. Ensure that ProjFS is installed and enabled";
}
Expand Down
2 changes: 1 addition & 1 deletion GVFS/GVFS.Platform.Windows/WindowsFileSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public bool HydrateFile(string fileName, byte[] buffer)
public bool IsExecutable(string fileName)
{
string fileExtension = Path.GetExtension(fileName);
return string.Equals(fileExtension, ".exe", StringComparison.OrdinalIgnoreCase);
return string.Equals(fileExtension, ".exe", GVFSPlatform.Instance.Constants.PathComparison);
}

public bool IsSocket(string fileName)
Expand Down
4 changes: 3 additions & 1 deletion GVFS/GVFS.Platform.Windows/WindowsPlatform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,7 @@ public override string ProgramLocaterCommand

public override HashSet<string> UpgradeBlockingProcesses
{
get { return new HashSet<string>(StringComparer.OrdinalIgnoreCase) { "GVFS", "GVFS.Mount", "git", "ssh-agent", "wish", "bash" }; }
get { return new HashSet<string>(GVFSPlatform.Instance.Constants.PathComparer) { "GVFS", "GVFS.Mount", "git", "ssh-agent", "wish", "bash" }; }
}

// Tests show that 250 is the max supported pipe name length
Expand All @@ -519,6 +519,8 @@ public override string RunUpdateMessage
{
get { return $"Run {UpgradeConfirmMessage} from an elevated command prompt."; }
}

public override bool CaseSensitiveFileSystem => false;
}
}
}
4 changes: 2 additions & 2 deletions GVFS/GVFS.Service/RepoRegistry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ public void AutoMountRepos(string userId, int sessionId)

public Dictionary<string, RepoRegistration> ReadRegistry()
{
Dictionary<string, RepoRegistration> allRepos = new Dictionary<string, RepoRegistration>(StringComparer.OrdinalIgnoreCase);
Dictionary<string, RepoRegistration> allRepos = new Dictionary<string, RepoRegistration>(GVFSPlatform.Instance.Constants.PathComparer);

using (Stream stream = this.fileSystem.OpenFileStream(
Path.Combine(this.registryParentFolderPath, RegistryName),
Expand Down Expand Up @@ -233,7 +233,7 @@ public Dictionary<string, RepoRegistration> ReadRegistry()
string normalizedEnlistmentRootPath = registration.EnlistmentRoot;
if (this.fileSystem.TryGetNormalizedPath(registration.EnlistmentRoot, out normalizedEnlistmentRootPath, out errorMessage))
{
if (!normalizedEnlistmentRootPath.Equals(registration.EnlistmentRoot, StringComparison.OrdinalIgnoreCase))
if (!normalizedEnlistmentRootPath.Equals(registration.EnlistmentRoot, GVFSPlatform.Instance.Constants.PathComparison))
{
EventMetadata metadata = new EventMetadata();
metadata.Add("registration.EnlistmentRoot", registration.EnlistmentRoot);
Expand Down
1 change: 1 addition & 0 deletions GVFS/GVFS.UnitTests/Category/CategoryConstants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
public static class CategoryConstants
{
public const string ExceptionExpected = "ExceptionExpected";
public const string CaseInsensitiveFileSystemOnly = "CaseInsensitiveFileSystemOnly";
}
}
8 changes: 4 additions & 4 deletions GVFS/GVFS.UnitTests/Common/FileBasedDictionaryTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ public override bool FileExists(string path)
if (this.maxFileExistsFailures > 0)
{
if (this.fileExistsFailureCount < this.maxFileExistsFailures &&
string.Equals(path, this.fileExistsFailurePath, System.StringComparison.OrdinalIgnoreCase))
string.Equals(path, this.fileExistsFailurePath, GVFSPlatform.Instance.Constants.PathComparison))
{
if (this.ExpectedFiles.ContainsKey(path))
{
Expand All @@ -342,7 +342,7 @@ public override bool FileExists(string path)
else if (this.failuresAcrossOpenExistsAndOverwritePath != null)
{
if (this.failuresAcrossOpenExistsAndOverwriteCount == 1 &&
string.Equals(path, this.failuresAcrossOpenExistsAndOverwritePath, System.StringComparison.OrdinalIgnoreCase))
string.Equals(path, this.failuresAcrossOpenExistsAndOverwritePath, GVFSPlatform.Instance.Constants.PathComparison))
{
if (this.ExpectedFiles.ContainsKey(path))
{
Expand Down Expand Up @@ -391,7 +391,7 @@ public override Stream OpenFileStream(string path, FileMode fileMode, FileAccess
if (this.maxOpenFileStreamFailures > 0)
{
if (this.openFileStreamFailureCount < this.maxOpenFileStreamFailures &&
string.Equals(path, this.openFileStreamFailurePath, System.StringComparison.OrdinalIgnoreCase))
string.Equals(path, this.openFileStreamFailurePath, GVFSPlatform.Instance.Constants.PathComparison))
{
++this.openFileStreamFailureCount;

Expand All @@ -408,7 +408,7 @@ public override Stream OpenFileStream(string path, FileMode fileMode, FileAccess
else if (this.failuresAcrossOpenExistsAndOverwritePath != null)
{
if (this.failuresAcrossOpenExistsAndOverwriteCount == 0 &&
string.Equals(path, this.failuresAcrossOpenExistsAndOverwritePath, System.StringComparison.OrdinalIgnoreCase))
string.Equals(path, this.failuresAcrossOpenExistsAndOverwritePath, GVFSPlatform.Instance.Constants.PathComparison))
{
++this.failuresAcrossOpenExistsAndOverwriteCount;
throw new IOException();
Expand Down
5 changes: 4 additions & 1 deletion GVFS/GVFS.UnitTests/Mock/Common/MockPlatform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using System.Collections.Generic;
using System.IO;
using System.IO.Pipes;
using System.Runtime.InteropServices;

namespace GVFS.UnitTests.Mock.Common
{
Expand Down Expand Up @@ -237,7 +238,7 @@ public override string ProgramLocaterCommand

public override HashSet<string> UpgradeBlockingProcesses
{
get { return new HashSet<string>(StringComparer.OrdinalIgnoreCase) { "GVFS", "GVFS.Mount", "git", "wish", "bash" }; }
get { return new HashSet<string>(this.PathComparer) { "GVFS", "GVFS.Mount", "git", "wish", "bash" }; }
}

public override bool SupportsUpgradeWhileRunning => false;
Expand All @@ -263,6 +264,8 @@ public override string RunUpdateMessage
{
get { return "MockRunUpdateMessage"; }
}

public override bool CaseSensitiveFileSystem => RuntimeInformation.IsOSPlatform(OSPlatform.Linux);
}
}
}
2 changes: 1 addition & 1 deletion GVFS/GVFS.UnitTests/Mock/FileSystem/MockFileSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ public override bool TryCreateOrUpdateDirectoryToAdminModifyPermissions(ITracer
// if it's called for one of those paths remap the paths to be inside the mock: root
string mockDirectoryPath = directoryPath;
string gvfsProgramData = @"C:\ProgramData\GVFS";
if (directoryPath.StartsWith(gvfsProgramData, StringComparison.OrdinalIgnoreCase))
if (directoryPath.StartsWith(gvfsProgramData, GVFSPlatform.Instance.Constants.PathComparison))
{
mockDirectoryPath = mockDirectoryPath.Substring(gvfsProgramData.Length);
mockDirectoryPath = "mock:" + mockDirectoryPath;
Expand Down
12 changes: 6 additions & 6 deletions GVFS/GVFS.UnitTests/Mock/MockGitHubUpgrader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,15 +124,15 @@ protected override bool TryCreateAndConfigureDownloadDirectory(ITracer tracer, o
protected override bool TryDownloadAsset(Asset asset, out string errorMessage)
{
bool validAsset = true;
if (this.expectedGVFSAssetName.Equals(asset.Name, StringComparison.OrdinalIgnoreCase))
if (this.expectedGVFSAssetName.Equals(asset.Name, GVFSPlatform.Instance.Constants.PathComparison))
{
if (this.failActionTypes.HasFlag(ActionType.GVFSDownload))
{
errorMessage = "Error downloading GVFS from GitHub";
return false;
}
}
else if (this.expectedGitAssetName.Equals(asset.Name, StringComparison.OrdinalIgnoreCase))
else if (this.expectedGitAssetName.Equals(asset.Name, GVFSPlatform.Instance.Constants.PathComparison))
{
if (this.failActionTypes.HasFlag(ActionType.GitDownload))
{
Expand Down Expand Up @@ -161,7 +161,7 @@ protected override bool TryDownloadAsset(Asset asset, out string errorMessage)

protected override bool TryDeleteDownloadedAsset(Asset asset, out Exception exception)
{
if (this.expectedGVFSAssetName.Equals(asset.Name, StringComparison.OrdinalIgnoreCase))
if (this.expectedGVFSAssetName.Equals(asset.Name, GVFSPlatform.Instance.Constants.PathComparison))
{
if (this.failActionTypes.HasFlag(ActionType.GVFSCleanup))
{
Expand All @@ -172,7 +172,7 @@ protected override bool TryDeleteDownloadedAsset(Asset asset, out Exception exce
exception = null;
return true;
}
else if (this.expectedGitAssetName.Equals(asset.Name, StringComparison.OrdinalIgnoreCase))
else if (this.expectedGitAssetName.Equals(asset.Name, GVFSPlatform.Instance.Constants.PathComparison))
{
if (this.failActionTypes.HasFlag(ActionType.GitCleanup))
{
Expand Down Expand Up @@ -215,7 +215,7 @@ protected override void RunInstaller(string path, string args, string certCN, st
exitCode = 0;
error = null;

if (fileName.Equals(this.expectedGitAssetName, StringComparison.OrdinalIgnoreCase))
if (fileName.Equals(this.expectedGitAssetName, GVFSPlatform.Instance.Constants.PathComparison))
{
this.InstallerArgs.Add("Git", installationInfo);
this.InstallerExeLaunched = true;
Expand All @@ -234,7 +234,7 @@ protected override void RunInstaller(string path, string args, string certCN, st
return;
}

if (fileName.Equals(this.expectedGVFSAssetName, StringComparison.OrdinalIgnoreCase))
if (fileName.Equals(this.expectedGVFSAssetName, GVFSPlatform.Instance.Constants.PathComparison))
{
this.InstallerArgs.Add("GVFS", installationInfo);
this.InstallerExeLaunched = true;
Expand Down
Loading

0 comments on commit e6eb054

Please sign in to comment.