diff --git a/GVFS/GVFS.Common/GVFSLock.cs b/GVFS/GVFS.Common/GVFSLock.cs index 0a1307a2e..ef910e2c0 100644 --- a/GVFS/GVFS.Common/GVFSLock.cs +++ b/GVFS/GVFS.Common/GVFSLock.cs @@ -196,13 +196,22 @@ public NamedPipeMessages.LockData GetLockHolderForCallbacks(out long? processSta } } - public bool TryAcquirePlaceholderCreation(Func canCreate, out IDisposable lease, out string command) + public bool TryAcquirePlaceholderCreation(Func canCreate, out IDisposable lease, out string command) { + NamedPipeMessages.LockData holder = this.GetLockHolderForCallbacks(out long? ownerStartTime); + lease = null; + command = holder?.ParsedCommand; + // Process ancestry checks must not block lock acquisition or release. + if (!canCreate(holder, ownerStartTime)) + { + return false; + } + lock (this.acquisitionLock) { - lease = null; - command = this.GetLockedGitCommand(); - if (!canCreate(command)) + NamedPipeMessages.LockData current = this.currentLockHolder.GetExternalHolder(); + command = current?.ParsedCommand; + if (!ReferenceEquals(holder, current) || ownerStartTime != this.currentLockHolder.ExternalStartTime) { return false; } diff --git a/GVFS/GVFS.Common/GitCommandLineParser.cs b/GVFS/GVFS.Common/GitCommandLineParser.cs index ec7f6672e..2463a6d78 100644 --- a/GVFS/GVFS.Common/GitCommandLineParser.cs +++ b/GVFS/GVFS.Common/GitCommandLineParser.cs @@ -43,6 +43,7 @@ public enum Verbs UpdateIndex = 1 << 7, Restore = 1 << 8, Switch = 1 << 9, + Apply = 1 << 10, } public bool IsValidGitCommand @@ -130,6 +131,7 @@ private Verbs StringToVerbs(string verb) switch (verb) { case "add": return Verbs.AddOrStage; + case "apply": return Verbs.Apply; case "checkout": return Verbs.Checkout; case "commit": return Verbs.Commit; case "mv": return Verbs.Move; diff --git a/GVFS/GVFS.FunctionalTests.LockHolder/Program.cs b/GVFS/GVFS.FunctionalTests.LockHolder/Program.cs index cb96d703b..83addef82 100644 --- a/GVFS/GVFS.FunctionalTests.LockHolder/Program.cs +++ b/GVFS/GVFS.FunctionalTests.LockHolder/Program.cs @@ -9,8 +9,9 @@ public class Program { public static void Main(string[] args) { - if (args.Length > 0 && args[0] == "--read-placeholder") + if (args.Length > 0 && (args[0] == "--read-placeholder" || args[0] == "--read-placeholder-success")) { + bool expectSuccess = args[0] == "--read-placeholder-success"; string path = Environment.GetEnvironmentVariable("GVFS_TEST_PLACEHOLDER_PATH"); string eventName = Environment.GetEnvironmentVariable("GVFS_TEST_PLACEHOLDER_EVENT_NAME"); if (string.IsNullOrEmpty(path) || string.IsNullOrEmpty(eventName)) @@ -22,14 +23,18 @@ public static void Main(string[] args) try { File.ReadAllText(path); - Console.Error.WriteLine("The child unexpectedly opened the placeholder."); - Environment.Exit(1); + if (!expectSuccess) + { + Console.Error.WriteLine("The child unexpectedly opened the placeholder."); + Environment.Exit(1); + } } catch (FileNotFoundException) { - using (EventWaitHandle rejected = EventWaitHandle.OpenExisting(eventName)) + if (expectSuccess) { - rejected.Set(); + Console.Error.WriteLine("The child could not open the placeholder."); + Environment.Exit(1); } } catch (IOException e) @@ -38,6 +43,11 @@ public static void Main(string[] args) Environment.Exit(1); } + using (EventWaitHandle completed = EventWaitHandle.OpenExisting(eventName)) + { + completed.Set(); + } + return; } diff --git a/GVFS/GVFS.FunctionalTests/Tests/GitCommands/ApplyTests.cs b/GVFS/GVFS.FunctionalTests/Tests/GitCommands/ApplyTests.cs new file mode 100644 index 000000000..c59a52bfa --- /dev/null +++ b/GVFS/GVFS.FunctionalTests/Tests/GitCommands/ApplyTests.cs @@ -0,0 +1,406 @@ +using GVFS.FunctionalTests.Properties; +using GVFS.FunctionalTests.Should; +using GVFS.FunctionalTests.Tools; +using GVFS.Tests.Should; +using Microsoft.Win32.SafeHandles; +using NUnit.Framework; +using System; +using System.Diagnostics; +using System.IO; +using System.Linq; +using System.Runtime.InteropServices; +using System.Threading; +using System.Threading.Tasks; + +namespace GVFS.FunctionalTests.Tests.GitCommands +{ + [TestFixture] + [Category(Categories.GitCommands)] + public class ApplyTests : GitRepoTests + { + private const uint FileReadAttributes = 0x80; + private static readonly string FileToPatch = Path.Combine("GVFS", "GVFS", "Program.cs"); + + public ApplyTests() + : base(enlistmentPerTest: true, validateWorkingTree: Settings.ValidateWorkingTreeMode.None) + { + } + + public enum ProjectedFileState + { + Virtual, + Placeholder, + Hydrated, + } + + [TestCase(ProjectedFileState.Virtual, false, false, "")] + [TestCase(ProjectedFileState.Placeholder, false, false, "")] + [TestCase(ProjectedFileState.Hydrated, false, false, "")] + [TestCase(ProjectedFileState.Virtual, true, false, "")] + [TestCase(ProjectedFileState.Virtual, false, true, "")] + [TestCase(ProjectedFileState.Virtual, false, false, "--check")] + public void ApplyToProjectedFile(ProjectedFileState state, bool waitForPlaceholders, bool stdin, string options) + { + this.AssertFilesAreVirtual(waitForPlaceholders ? 2000 : 0, FileToPatch); + string virtualPath = this.Enlistment.GetVirtualPathTo(FileToPatch); + + if (state == ProjectedFileState.Placeholder) + { + using (SafeFileHandle handle = NativeMethods.CreateFile( + virtualPath, + FileReadAttributes, + FileShare.ReadWrite | FileShare.Delete, + IntPtr.Zero, + FileMode.Open, + 0, + IntPtr.Zero)) + { + handle.IsInvalid.ShouldBeFalse("Could not open file metadata. Error: " + Marshal.GetLastWin32Error()); + } + + ((int)File.GetAttributes(virtualPath) & FileSystemShouldExtensions.FileAttributeRecallOnDataAccess) + .ShouldNotEqual(0, "The file must have no hydrated contents before apply."); + } + else if (state == ProjectedFileState.Hydrated) + { + this.FileContentsShouldMatch(FileToPatch); + } + + string gitPath = GitHelpers.ConvertPathToGitFormat(FileToPatch); + GVFSHelpers.ModifiedPathsShouldNotContain(this.Enlistment, this.FileSystem, gitPath); + GitProcess.InvokeProcess(this.Enlistment.RepoRoot, $"ls-files -v -- {gitPath}") + .Output.Trim().ShouldEqual("S " + gitPath); + + string controlPath = Path.Combine(this.ControlGitRepo.RootPath, FileToPatch); + File.AppendAllText(controlPath, "\n// Apply functional test\n"); + string patch = this.CreatePatch("apply.patch"); + this.ApplyPatch(options, patch, stdin); + this.FileContentsShouldMatch(FileToPatch); + this.ValidateGitCommand("diff --cached --binary"); + this.ValidateGitCommand("status --porcelain"); + + if (options == "--check") + { + this.ValidateGitCommand("diff --exit-code"); + } + } + + [TestCase(false, false)] + [TestCase(false, true)] + [TestCase(true, true)] + public void ApplyOwnerCanOpenAfterAnotherRequesterIsRejected(bool waitForPlaceholders, bool probeOtherRequester) + { + this.AssertFilesAreVirtual(waitForPlaceholders ? 2000 : 0, FileToPatch); + File.AppendAllText(Path.Combine(this.ControlGitRepo.RootPath, FileToPatch), "\n// Owner-scoped apply\n"); + string patch = this.CreatePatch("owner.patch"); + using (Process git = new Process()) + { + git.StartInfo = new ProcessStartInfo(Settings.Default.PathToGit, "apply -") + { + WorkingDirectory = this.Enlistment.RepoRoot, + UseShellExecute = false, + RedirectStandardInput = true, + RedirectStandardOutput = true, + RedirectStandardError = true, + }; + git.Start().ShouldBeTrue(); + Task output = git.StandardOutput.ReadToEndAsync(); + Task errors = git.StandardError.ReadToEndAsync(); + try + { + this.Enlistment.WaitForLock("git apply -").ShouldBeTrue(); + if (probeOtherRequester) + { + IOException rejected = Assert.Throws( + () => File.ReadAllText(this.Enlistment.GetVirtualPathTo(FileToPatch))); + rejected.HResult.ShouldEqual(unchecked((int)0x80070020)); + using (SafeFileHandle handle = NativeMethods.CreateFile( + this.Enlistment.GetVirtualPathTo(FileToPatch), + FileReadAttributes, + FileShare.ReadWrite | FileShare.Delete, + IntPtr.Zero, + FileMode.Open, + 0, + IntPtr.Zero)) + { + int error = Marshal.GetLastWin32Error(); + handle.IsInvalid.ShouldBeTrue("An unrelated reader must not create the placeholder."); + error.ShouldEqual(32, "Apply rejection must not cache a false absence."); + } + } + + using (FileStream input = File.OpenRead(Path.Combine(this.Enlistment.RepoRoot, patch))) + { + input.CopyTo(git.StandardInput.BaseStream); + } + + git.StandardInput.Close(); + git.WaitForExit(15000).ShouldBeTrue("Apply did not finish after it received the patch."); + git.ExitCode.ShouldEqual(0, errors.GetAwaiter().GetResult()); + ProcessResult expected = GitProcess.InvokeProcess(this.ControlGitRepo.RootPath, $"apply {patch}"); + expected.ExitCode.ShouldEqual(0, expected.Errors); + output.GetAwaiter().GetResult().ShouldEqual(expected.Output); + this.FileContentsShouldMatch(FileToPatch); + this.ValidateGitCommand("status --porcelain"); + } + finally + { + if (!git.HasExited) + { + git.StandardInput.Close(); + if (!git.WaitForExit(10000)) + { + git.Kill(entireProcessTree: true); + git.WaitForExit(10000).ShouldBeTrue(); + } + } + } + } + } + + [TestCase(false)] + [TestCase(true)] + public void ApplyAllowsPlaceholderCreationForAChildHook(bool waitForPlaceholders) + { + string childFile = Path.Combine("GVFS", "GVFS.Common", "GVFSConstants.cs"); + this.AssertFilesAreVirtual(waitForPlaceholders ? 2000 : 0, FileToPatch, childFile); + File.AppendAllText(Path.Combine(this.ControlGitRepo.RootPath, FileToPatch), "\n// Apply with child hook\n"); + string patch = this.CreatePatch("child-hook.patch"); + string hooks = this.Enlistment.GetVirtualPathTo(".git", "hooks", "post-command.hooks"); + string original = File.ReadAllText(hooks); + string eventName = "GVFS.ApplyChild." + Guid.NewGuid().ToString("N"); + using (EventWaitHandle opened = new EventWaitHandle(false, EventResetMode.ManualReset, eventName)) + using (Process git = new Process()) + { + git.StartInfo = new ProcessStartInfo(Settings.Default.PathToGit, "apply " + patch) + { + WorkingDirectory = this.Enlistment.RepoRoot, + UseShellExecute = false, + RedirectStandardOutput = true, + RedirectStandardError = true, + }; + git.StartInfo.Environment["GVFS_TEST_PLACEHOLDER_PATH"] = this.Enlistment.GetVirtualPathTo(childFile); + git.StartInfo.Environment["GVFS_TEST_PLACEHOLDER_EVENT_NAME"] = eventName; + bool started = false; + try + { + File.WriteAllText(hooks, $"\"{GitHelpers.LockHolderCommandPath}\" --read-placeholder-success" + Environment.NewLine + original); + started = git.Start(); + started.ShouldBeTrue(); + Task errors = git.StandardError.ReadToEndAsync(); + git.WaitForExit(15000).ShouldBeTrue("The apply child hook did not finish."); + git.ExitCode.ShouldEqual(0, errors.GetAwaiter().GetResult()); + opened.WaitOne(TimeSpan.FromSeconds(1)).ShouldBeTrue("The child did not open the virtual file under the apply lock."); + ProcessResult expected = GitProcess.InvokeProcess(this.ControlGitRepo.RootPath, "apply " + patch); + expected.ExitCode.ShouldEqual(0, expected.Errors); + git.StandardOutput.ReadToEnd().ShouldEqual(expected.Output); + } + finally + { + if (started && !git.HasExited) + { + git.Kill(entireProcessTree: true); + git.WaitForExit(10000).ShouldBeTrue(); + } + + File.WriteAllText(hooks, original); + } + } + + this.FileContentsShouldMatch(FileToPatch); + this.FileContentsShouldMatch(childFile); + this.ValidateGitCommand("status --porcelain"); + } + + [TestCase] + public void ApplyOwnerCanReadWhileAnotherRequesterWaits() + { + this.AssertFilesAreVirtual(30000, FileToPatch); + string controlPath = Path.Combine(this.ControlGitRepo.RootPath, FileToPatch); + string originalContents = File.ReadAllText(controlPath); + File.AppendAllText(controlPath, "\n// Overlapping apply reader\n"); + string patch = this.CreatePatch("overlapping-reader.patch"); + using (Process git = new Process()) + { + git.StartInfo = new ProcessStartInfo(Settings.Default.PathToGit, "apply -") + { + WorkingDirectory = this.Enlistment.RepoRoot, + UseShellExecute = false, + RedirectStandardInput = true, + RedirectStandardOutput = true, + RedirectStandardError = true, + }; + git.Start().ShouldBeTrue(); + Task output = git.StandardOutput.ReadToEndAsync(); + Task errors = git.StandardError.ReadToEndAsync(); + Task otherRead = null; + try + { + this.Enlistment.WaitForLock("git apply -").ShouldBeTrue(); + otherRead = Task.Factory.StartNew( + () => File.ReadAllText(this.Enlistment.GetVirtualPathTo(FileToPatch)), + TaskCreationOptions.LongRunning); + SpinWait.SpinUntil( + () => Directory.GetFiles(this.Enlistment.GVFSLogsRoot, "gvfs_mount_*.log") + .Any(path => GVFSHelpers.ReadAllTextFromWriteLockedFile(path) + .Split('\n').Any(line => line.Contains("PlaceholderLockWait") && + line.Contains("\"outcome\":\"Queued\"") && + line.Contains(FileToPatch.Replace("\\", "\\\\")))), + TimeSpan.FromSeconds(10)).ShouldBeTrue("The unrelated reader did not enter the wait queue."); + otherRead.IsCompleted.ShouldBeFalse("The unrelated reader must still wait before Git receives the patch."); + + using (FileStream input = File.OpenRead(Path.Combine(this.Enlistment.RepoRoot, patch))) + { + input.CopyTo(git.StandardInput.BaseStream); + } + + git.StandardInput.Close(); + git.WaitForExit(10000).ShouldBeTrue("The owner did not finish before the unrelated reader's wait budget."); + git.ExitCode.ShouldEqual(0, errors.GetAwaiter().GetResult()); + Task.WhenAny(otherRead, Task.Delay(10000)).GetAwaiter().GetResult().ShouldEqual(otherRead); + string concurrentContents = otherRead.GetAwaiter().GetResult(); + ProcessResult expected = GitProcess.InvokeProcess(this.ControlGitRepo.RootPath, $"apply {patch}"); + expected.ExitCode.ShouldEqual(0, expected.Errors); + output.GetAwaiter().GetResult().ShouldEqual(expected.Output); + bool readPreimage = concurrentContents == originalContents; + (readPreimage || concurrentContents == File.ReadAllText(controlPath)) + .ShouldBeTrue("The concurrent reader must read a complete preimage or postimage."); + TestContext.WriteLine("ConcurrentReadImage=" + (readPreimage ? "preimage" : "postimage")); + this.FileContentsShouldMatch(FileToPatch); + this.ValidateGitCommand("status --porcelain"); + } + finally + { + if (!git.HasExited) + { + git.StandardInput.Close(); + git.Kill(entireProcessTree: true); + git.WaitForExit(10000).ShouldBeTrue(); + ProcessResult cleanup = GitProcess.InvokeProcess( + this.Enlistment.RepoRoot, "status --porcelain", timeoutMs: 10000); + cleanup.ExitCode.ShouldEqual(0, cleanup.Errors); + } + + if (otherRead != null) + { + Task.WhenAny(otherRead, Task.Delay(10000)).GetAwaiter().GetResult().ShouldEqual(otherRead); + otherRead.GetAwaiter().GetResult(); + } + } + } + } + + [TestCase] + public void ApplyAndReverseMixedPatch() + { + string deleted = Path.Combine("GVFS", "GVFS", "GVFS.csproj"); + string renamed = Path.Combine("GVFS", "GVFS.Common", "GVFSConstants.cs"); + string destination = Path.Combine("GVFS", "GVFS.Common", "renamed file \u00e9.cs"); + string added = Path.Combine("GVFS", "GVFS", "apply-added.txt"); + this.AssertFilesAreVirtual(0, FileToPatch, deleted, renamed); + + File.AppendAllText(Path.Combine(this.ControlGitRepo.RootPath, FileToPatch), "\n// Mixed patch\n"); + File.Delete(Path.Combine(this.ControlGitRepo.RootPath, deleted)); + File.Move(Path.Combine(this.ControlGitRepo.RootPath, renamed), Path.Combine(this.ControlGitRepo.RootPath, destination)); + File.WriteAllText(Path.Combine(this.ControlGitRepo.RootPath, added), "Added by apply\n"); + string patch = this.CreatePatch("mixed.patch"); + + this.ApplyPatch(string.Empty, patch); + this.FileContentsShouldMatch(FileToPatch); + this.FileContentsShouldMatch(destination); + this.FileContentsShouldMatch(added); + this.Enlistment.GetVirtualPathTo(deleted).ShouldNotExistOnDisk(this.FileSystem); + this.Enlistment.GetVirtualPathTo(renamed).ShouldNotExistOnDisk(this.FileSystem); + this.ValidateGitCommand("diff --cached --binary"); + this.ValidateGitCommand("status --porcelain"); + + this.ApplyPatch("--reverse", patch); + this.Enlistment.UnmountGVFS(); + this.Enlistment.MountGVFS(); + this.FileContentsShouldMatch(FileToPatch); + this.FileContentsShouldMatch(deleted); + this.FileContentsShouldMatch(renamed); + this.Enlistment.GetVirtualPathTo(destination).ShouldNotExistOnDisk(this.FileSystem); + this.Enlistment.GetVirtualPathTo(added).ShouldNotExistOnDisk(this.FileSystem); + this.ValidateGitCommand("status --porcelain"); + } + + [TestCase] + public void ApplyDoesNotOverwriteAnExistingVirtualFileWithANewFilePatch() + { + this.AssertFilesAreVirtual(0, FileToPatch); + string gitPath = GitHelpers.ConvertPathToGitFormat(FileToPatch); + string patch = $"diff --git a/{gitPath} b/{gitPath}\nnew file mode 100644\n--- /dev/null\n+++ b/{gitPath}\n@@ -0,0 +1 @@\n+Do not overwrite the tracked file.\n"; + string patchPath = ".git/new-file.patch"; + File.WriteAllText(Path.Combine(this.ControlGitRepo.RootPath, patchPath), patch); + File.WriteAllText(Path.Combine(this.Enlistment.RepoRoot, patchPath), patch); + ProcessResult expected = GitProcess.InvokeProcess(this.ControlGitRepo.RootPath, "apply " + patchPath); + expected.ExitCode.ShouldEqual(1, expected.Errors); + ProcessResult actual = GitProcess.InvokeProcess(this.Enlistment.RepoRoot, "apply " + patchPath); + actual.ExitCode.ShouldEqual(expected.ExitCode, actual.Errors); + actual.Errors.ShouldEqual(expected.Errors); + this.FileContentsShouldMatch(FileToPatch); + this.ValidateGitCommand("status --porcelain"); + } + + [TestCase] + public void ApplyDoesNotRecreateFileDeletedByEarlierPatch() + { + this.AssertFilesAreVirtual(0, FileToPatch); + string controlPath = Path.Combine(this.ControlGitRepo.RootPath, FileToPatch); + File.AppendAllText(controlPath, "\n// Modification after deletion\n"); + string modification = this.CreatePatch("modification.patch"); + File.Delete(controlPath); + string deletion = this.CreatePatch("deletion.patch"); + + ProcessResult expected = GitProcess.InvokeProcess(this.ControlGitRepo.RootPath, $"apply {deletion} {modification}"); + expected.ExitCode.ShouldEqual(1, expected.Errors); + ProcessResult actual = GitProcess.InvokeProcess(this.Enlistment.RepoRoot, $"apply {deletion} {modification}"); + actual.ExitCode.ShouldEqual(expected.ExitCode, actual.Errors); + actual.Errors.ShouldEqual(expected.Errors); + this.Enlistment.GetVirtualPathTo(FileToPatch).ShouldNotExistOnDisk(this.FileSystem); + this.ValidateGitCommand("status --porcelain"); + } + + private void AssertFilesAreVirtual(int placeholderWaitMs, params string[] paths) + { + GitProcess.InvokeProcess(this.Enlistment.RepoRoot, "config gvfs.placeholder-lock-wait-ms " + placeholderWaitMs).ExitCode.ShouldEqual(0); + + this.Enlistment.UnmountGVFS(); + foreach (string path in paths) + { + this.Enlistment.GetVirtualPathTo(path).ShouldNotExistOnDisk(this.FileSystem); + } + + this.Enlistment.MountGVFS(); + } + + private string CreatePatch(string name) + { + ProcessResult add = GitProcess.InvokeProcess(this.ControlGitRepo.RootPath, "add -A"); + add.ExitCode.ShouldEqual(0, add.Errors); + ProcessResult diff = GitProcess.InvokeProcess(this.ControlGitRepo.RootPath, "diff --cached --binary --find-renames"); + diff.ExitCode.ShouldEqual(0, diff.Errors); + string.IsNullOrWhiteSpace(diff.Output).ShouldBeFalse("The control repo must produce a patch."); + ProcessResult reset = GitProcess.InvokeProcess(this.ControlGitRepo.RootPath, "reset --hard HEAD"); + reset.ExitCode.ShouldEqual(0, reset.Errors); + File.WriteAllText(Path.Combine(this.ControlGitRepo.RootPath, ".git", name), diff.Output); + File.WriteAllText(this.Enlistment.GetVirtualPathTo(".git", name), diff.Output); + return ".git/" + name; + } + + private void ApplyPatch(string options, string patch, bool stdin = false) + { + string command = $"apply {options} {(stdin ? "-" : patch)}"; + using (FileStream expectedInput = stdin ? File.OpenRead(Path.Combine(this.ControlGitRepo.RootPath, patch)) : null) + using (FileStream actualInput = stdin ? File.OpenRead(Path.Combine(this.Enlistment.RepoRoot, patch)) : null) + { + ProcessResult expected = GitProcess.InvokeProcess(this.ControlGitRepo.RootPath, command, inputStream: expectedInput); + expected.ExitCode.ShouldEqual(0, expected.Errors); + ProcessResult actual = GitProcess.InvokeProcess(this.Enlistment.RepoRoot, command, inputStream: actualInput); + actual.ExitCode.ShouldEqual(0, actual.Errors); + actual.Output.ShouldEqual(expected.Output); + } + } + } +} diff --git a/GVFS/GVFS.Platform.Windows/PlaceholderRequestProcessTree.cs b/GVFS/GVFS.Platform.Windows/PlaceholderRequestProcessTree.cs index 861ed9afe..d483226f6 100644 --- a/GVFS/GVFS.Platform.Windows/PlaceholderRequestProcessTree.cs +++ b/GVFS/GVFS.Platform.Windows/PlaceholderRequestProcessTree.cs @@ -37,11 +37,6 @@ internal PlaceholderRequestProcessTree(Func getStartTime, Func getStartTime, Func this.GetPlaceholderInformationAsyncHandler( @@ -49,10 +68,10 @@ private HResult DeferPlaceholderCreation(int commandId, string virtualPath, uint request.BlockingReason = "GitCommand"; if (this.ShouldRejectDependentRequest(request, holder, ownerStartTime)) { - request.Result = HResult.FileNotFound; + request.Result = GetPlaceholderRejectionResult(holder); this.FileSystemCallbacks.OnPlaceholderCreateBlockedForGit(); this.TracePlaceholderWait(request, request.BlockingReason); - this.TryCompleteCommand(commandId, HResult.FileNotFound); + this.TryCompleteCommand(commandId, request.Result.Value); cancellation.Dispose(); } else if (!this.placeholderWaitQueue.TryEnqueue(request, out bool stopping)) @@ -194,20 +213,19 @@ private void Run() stop = this.stopping; } - bool ready = false; - bool commandAllowsCreation = false; + bool projectionReady = false; NamedPipeMessages.LockData holder = null; long? ownerStartTime = null; if (!stop && snapshot.Count > 0) { holder = this.owner.Context.Repository.GVFSLock.GetLockHolderForCallbacks(out ownerStartTime); - commandAllowsCreation = CanCreatePlaceholderForCommand(holder?.ParsedCommand); - ready = commandAllowsCreation && - this.owner.FileSystemCallbacks.GitIndexProjection.IsProjectionParseComplete(); + projectionReady = this.owner.FileSystemCallbacks.GitIndexProjection.IsProjectionParseComplete(); } foreach (Request request in snapshot) { + bool commandAllowsCreation = this.owner.CanCreatePlaceholderForRequest(holder, ownerStartTime, request.ProcessId); + bool ready = commandAllowsCreation && projectionReady; bool schedule = false; string outcome = null; bool rejectDependent = !stop && !request.Scheduled && !request.Token.IsCancellationRequested && @@ -238,7 +256,7 @@ private void Run() { this.requests.Remove(request.CommandId); request.Terminated = true; - request.Result = HResult.FileNotFound; + request.Result = GetPlaceholderRejectionResult(holder); outcome = request.BlockingReason; } else @@ -281,7 +299,7 @@ private void Run() this.owner.TryCompleteCommand( request.CommandId, - rejectDependent ? HResult.FileNotFound : + rejectDependent ? request.Result.Value : stop ? (HResult)HResultExtensions.HResultFromNtStatus.DeviceNotReady : (HResult)HResultExtensions.HResultFromNtStatus.FileNotAvailable); } diff --git a/GVFS/GVFS.Platform.Windows/WindowsFileSystemVirtualizer.cs b/GVFS/GVFS.Platform.Windows/WindowsFileSystemVirtualizer.cs index b4f0ee592..7d917d697 100644 --- a/GVFS/GVFS.Platform.Windows/WindowsFileSystemVirtualizer.cs +++ b/GVFS/GVFS.Platform.Windows/WindowsFileSystemVirtualizer.cs @@ -742,22 +742,24 @@ public HResult GetPlaceholderInfoCallback( return HResult.FileNotFound; } + NamedPipeMessages.LockData holder = this.Context.Repository.GVFSLock.GetLockHolderForCallbacks(out long? ownerStartTime); if (!isFolder && !this.IsSpecialGitFile(fileName) && - !this.CanCreatePlaceholder()) + !this.CanCreatePlaceholderForRequest(holder, ownerStartTime, triggeringProcessId)) { + HResult rejectionResult = GetPlaceholderRejectionResult(holder); EventMetadata metadata = this.CreateEventMetadata(virtualPath); metadata.Add("commandId", commandId); metadata.Add("triggeringProcessId", triggeringProcessId); metadata.Add("triggeringProcessImageFileName", triggeringProcessImageFileName); + metadata.Add("lockedGitCommand", holder?.ParsedCommand); + metadata.Add("completionResult", rejectionResult.ToString("X")); metadata.Add(TracingConstants.MessageKey.VerboseMessage, $"{nameof(this.GetPlaceholderInfoCallback)}: Not allowed to create placeholder"); this.Context.Tracer.RelatedEvent(EventLevel.Verbose, nameof(this.GetPlaceholderInfoCallback), metadata); this.FileSystemCallbacks.OnPlaceholderCreateBlockedForGit(); - // Another process is modifying the working directory so we cannot modify it - // until they are done. - return HResult.FileNotFound; + return rejectionResult; } CancellationTokenSource cancellationSource; @@ -911,9 +913,9 @@ public override bool TryStart(out string error) { error = string.Empty; + this.IsRequestDescendant ??= new PlaceholderRequestProcessTree(this.Context.Tracer).IsDescendant; if (this.placeholderLockWaitMs > 0) { - this.IsRequestDescendant ??= new PlaceholderRequestProcessTree(this.Context.Tracer).IsDescendant; this.placeholderWaitQueue = new PlaceholderCreationWaitQueue(this); } @@ -1372,7 +1374,8 @@ private bool GetPlaceholderInformationAsyncHandler( else { if (!this.Context.Repository.GVFSLock.TryAcquirePlaceholderCreation( - CanCreatePlaceholderForCommand, out IDisposable lease, out string blockingCommand)) + (holder, ownerStartTime) => this.CanCreatePlaceholderForRequest(holder, ownerStartTime, triggeringProcessId), + out IDisposable lease, out string blockingCommand)) { deferredRequest.BlockingReason = "GitCommand"; deferredRequest.BlockingCommand = blockingCommand; diff --git a/GVFS/GVFS.UnitTests/Common/GVFSLockTests.cs b/GVFS/GVFS.UnitTests/Common/GVFSLockTests.cs index ea29c5d5f..1233c42b6 100644 --- a/GVFS/GVFS.UnitTests/Common/GVFSLockTests.cs +++ b/GVFS/GVFS.UnitTests/Common/GVFSLockTests.cs @@ -8,6 +8,7 @@ using Moq; using NUnit.Framework; using System; +using System.Threading.Tasks; namespace GVFS.UnitTests.Common { @@ -187,8 +188,8 @@ public void LockRetriesContinueWhileAnotherOwnerHoldsTheLock(string firstDenial, public void PlaceholderCreationLeasesBlockNewOwnersUntilEveryLeaseEnds() { GVFSLock gvfsLock = new GVFSLock(new MockTracer()); - gvfsLock.TryAcquirePlaceholderCreation(_ => true, out IDisposable first, out _).ShouldBeTrue(); - gvfsLock.TryAcquirePlaceholderCreation(_ => true, out IDisposable second, out _).ShouldBeTrue(); + gvfsLock.TryAcquirePlaceholderCreation((_, _) => true, out IDisposable first, out _).ShouldBeTrue(); + gvfsLock.TryAcquirePlaceholderCreation((_, _) => true, out IDisposable second, out _).ShouldBeTrue(); try { gvfsLock.TryAcquireLockForExternalRequestor(DefaultLockData, out _).ShouldBeFalse(); @@ -206,11 +207,11 @@ public void PlaceholderCreationLeasesBlockNewOwnersUntilEveryLeaseEnds() } gvfsLock.TryAcquireLockForGVFS().ShouldBeTrue(); - gvfsLock.TryAcquirePlaceholderCreation(_ => true, out IDisposable duringBackgroundWork, out _).ShouldBeTrue(); + gvfsLock.TryAcquirePlaceholderCreation((_, _) => true, out IDisposable duringBackgroundWork, out _).ShouldBeTrue(); gvfsLock.TryAcquireLockForGVFS().ShouldBeTrue(); duringBackgroundWork.Dispose(); gvfsLock.ReleaseLockHeldByGVFS(); - gvfsLock.TryAcquirePlaceholderCreation(_ => false, out _, out _).ShouldBeFalse(); + gvfsLock.TryAcquirePlaceholderCreation((_, _) => false, out _, out _).ShouldBeFalse(); } [TestCase] @@ -220,7 +221,7 @@ public void PlaceholderLeaseKeepsTheExistingAllowedCommandAsTheReportedOwner() GVFSLock gvfsLock = new GVFSLock(new MockTracer()); NamedPipeMessages.LockData owner = new NamedPipeMessages.LockData(1234, false, false, "git status", string.Empty); gvfsLock.TryAcquireLockForExternalRequestor(owner, out _).ShouldBeTrue(); - gvfsLock.TryAcquirePlaceholderCreation(command => command == "git status", out IDisposable lease, out _).ShouldBeTrue(); + gvfsLock.TryAcquirePlaceholderCreation((holder, _) => holder?.ParsedCommand == "git status", out IDisposable lease, out _).ShouldBeTrue(); using (lease) { gvfsLock.IsLockAvailableForExternalRequestor(out NamedPipeMessages.LockData reported).ShouldBeFalse(); @@ -235,6 +236,39 @@ public void PlaceholderLeaseKeepsTheExistingAllowedCommandAsTheReportedOwner() gvfsLock.GetStatus().ShouldEqual("Free"); } + [TestCase] + public void PlaceholderLeaseChecksAncestryOutsideAcquisitionLockAndRejectsAReplacementOwner() + { + ((MockPlatform)GVFSPlatform.Instance).ActiveProcesses.Add(1234); + GVFSLock gvfsLock = new GVFSLock(new MockTracer()); + NamedPipeMessages.LockData owner = new NamedPipeMessages.LockData(1234, false, false, "git apply -", string.Empty); + gvfsLock.TryAcquireLockForExternalRequestor(owner, out _).ShouldBeTrue(); + try + { + gvfsLock.TryAcquirePlaceholderCreation((holder, start) => + { + ReferenceEquals(holder, owner).ShouldBeTrue(); + start.ShouldEqual((long?)1234); + Task replacement = Task.Factory.StartNew(() => + { + gvfsLock.ReleaseLockHeldByExternalProcess(1234).ShouldBeTrue(); + gvfsLock.TryAcquireLockForExternalRequestor( + new NamedPipeMessages.LockData(1234, false, false, "git apply -", string.Empty), out _).ShouldBeTrue(); + }, TaskCreationOptions.LongRunning); + replacement.Wait(TimeSpan.FromSeconds(10)).ShouldBeTrue("The ancestry check blocked lock acquisition or release."); + return true; + }, out IDisposable lease, out _).ShouldBeFalse(); + lease.ShouldBeNull(); + gvfsLock.ReleaseLockHeldByExternalProcess(1234).ShouldBeTrue(); + gvfsLock.TryAcquireLockForGVFS().ShouldBeTrue(); + gvfsLock.ReleaseLockHeldByGVFS(); + } + finally + { + gvfsLock.ReleaseLockHeldByExternalProcess(1234); + } + } + [TestCase] public void TryAcquireAndReleaseLockForExternalRequestor() { diff --git a/GVFS/GVFS.UnitTests/Windows/Mock/WindowsFileSystemVirtualizerTester.cs b/GVFS/GVFS.UnitTests/Windows/Mock/WindowsFileSystemVirtualizerTester.cs index a94cc00fc..99110a3e6 100644 --- a/GVFS/GVFS.UnitTests/Windows/Mock/WindowsFileSystemVirtualizerTester.cs +++ b/GVFS/GVFS.UnitTests/Windows/Mock/WindowsFileSystemVirtualizerTester.cs @@ -63,7 +63,7 @@ protected override FileSystemVirtualizer CreateVirtualizer(CommonRepoSetup repo) repo.Context.Tracer, () => repo.Context.Repository.TryGetConfigValue(GVFS.Common.GVFSConstants.GitConfig.PlaceholderLockWaitMs, out string value) ? value : null)) { - IsRequestDescendant = (_, _, _) => false, + IsRequestDescendant = (id, holder, _) => id == holder.PID, }; return this.WindowsVirtualizer; } diff --git a/GVFS/GVFS.UnitTests/Windows/Virtualization/WindowsFileSystemVirtualizerTests.cs b/GVFS/GVFS.UnitTests/Windows/Virtualization/WindowsFileSystemVirtualizerTests.cs index 1fa853872..f3c108c4d 100644 --- a/GVFS/GVFS.UnitTests/Windows/Virtualization/WindowsFileSystemVirtualizerTests.cs +++ b/GVFS/GVFS.UnitTests/Windows/Virtualization/WindowsFileSystemVirtualizerTests.cs @@ -561,6 +561,171 @@ public void PlaceholderWaitPreservesOwnerDependentAndUnknownRejections(uint proc } } + [TestCase(false, "git apply patch.diff", 1234u, false)] + [TestCase(false, "git apply patch.diff", 2345u, true)] + [TestCase(false, "git apply patch.diff", 2345u, false)] + [TestCase(false, "git apply patch.diff", 2345u, null)] + [TestCase(true, "git apply patch.diff", 1234u, false)] + [TestCase(true, "git apply patch.diff", 2345u, true)] + [TestCase(true, "git apply patch.diff", 2345u, false)] + [TestCase(true, "git apply patch.diff", 2345u, null)] + [TestCase(false, "git checkout-index --stdin", 1234u, false)] + [TestCase(true, "git checkout-index --stdin", 1234u, false)] + [TestCase(false, "git checkout-index --stdin", 2345u, true)] + [TestCase(true, "git checkout-index --stdin", 2345u, true)] + public void PlaceholderAdmissionPermitsOnlyTheApplyProcessFamily( + bool waitEnabled, string command, uint processId, bool? related) + { + using (WindowsFileSystemVirtualizerTester tester = new WindowsFileSystemVirtualizerTester(this.Repo, waitEnabled)) + { + PlaceholderRequestProcessTree tree = new PlaceholderRequestProcessTree(id => id, (_, _, _) => related); + tester.WindowsVirtualizer.IsRequestDescendant = tree.IsDescendant; + ((MockPlatform)GVFSPlatform.Instance).ActiveProcesses.Add(1234); + this.Repo.Repository.GVFSLock.TryAcquireLockForExternalRequestor( + new NamedPipeMessages.LockData(1234, false, false, command, string.Empty), out _).ShouldBeTrue(); + try + { + HResult result = tester.MockVirtualization.RequiredCallbacks.GetPlaceholderInfoCallback( + 1, "test.txt", processId, "reader"); + bool apply = command.StartsWith("git apply"); + bool allowed = apply && (processId == 1234 || related == true); + HResult rejected = apply ? (HResult)HResultExtensions.HResultFromNtStatus.FileNotAvailable : HResult.FileNotFound; + if (allowed) + { + result.ShouldEqual(HResult.Pending); + tester.MockVirtualization.WaitForCompletionStatus().ShouldEqual(HResult.Ok); + tester.MockVirtualization.CreatedPlaceholders.ShouldContain(path => path == "test.txt"); + ((MockTracer)this.Repo.Context.Tracer).SnapshotRelatedEvents() + .Any(entry => entry.Name == "PlaceholderLockWait").ShouldBeFalse(); + } + else if (!waitEnabled) + { + result.ShouldEqual(rejected); + tester.MockVirtualization.CreatedPlaceholders.Count.ShouldEqual(0); + } + else if (processId == 1234 || related != false) + { + result.ShouldEqual(HResult.Pending); + tester.MockVirtualization.WaitForCompletionStatus().ShouldEqual(rejected); + tester.MockVirtualization.CreatedPlaceholders.Count.ShouldEqual(0); + EventMetadata metadata = new EventMetadata(); + tester.WindowsVirtualizer.AddHeartbeatMetadata(metadata); + ((long)metadata["PlaceholderLockWaitStarted"]).ShouldEqual(0); + } + else + { + result.ShouldEqual(HResult.Pending); + ((MockTracer)this.Repo.Context.Tracer).SnapshotRelatedEvents() + .Any(entry => entry.Name == "PlaceholderLockWait").ShouldBeTrue(); + tester.GitIndexProjection.FileInfoRequests.ShouldEqual(0); + this.Repo.Repository.GVFSLock.ReleaseLockHeldByExternalProcess(1234).ShouldBeTrue(); + tester.MockVirtualization.WaitForCompletionStatus().ShouldEqual(HResult.Ok); + } + } + finally + { + this.Repo.Repository.GVFSLock.ReleaseLockHeldByExternalProcess(1234); + } + } + } + + [TestCase] + public void PlaceholderAncestryValidatesTheOwnerIdentityBeforeGrantingPermission() + { + long? activeStart = 10; + PlaceholderRequestProcessTree tree = new PlaceholderRequestProcessTree( + _ => activeStart, (_, _, _) => throw new AssertionException("Owner checks do not require a process snapshot.")); + NamedPipeMessages.LockData holder = new NamedPipeMessages.LockData(1234, false, false, "git apply -", string.Empty); + tree.IsDescendant(1234, holder, 10).ShouldEqual(true); + tree.IsDescendant(1234, holder, null).ShouldEqual(null); + activeStart = 20; + tree.IsDescendant(1234, holder, 10).ShouldEqual(null); + activeStart = null; + tree.IsDescendant(1234, holder, 10).ShouldEqual(null); + } + + [TestCase(false, null)] + [TestCase(true, null)] + [TestCase(false, 4321L)] + [TestCase(true, 4321L)] + public void ApplyRejectsAnUnverifiedOwnerWithoutWaitingOrCachingAbsence(bool waitEnabled, long? activeStart) + { + using (WindowsFileSystemVirtualizerTester tester = new WindowsFileSystemVirtualizerTester(this.Repo, waitEnabled)) + { + PlaceholderRequestProcessTree tree = new PlaceholderRequestProcessTree(_ => activeStart, (_, _, _) => true); + tester.WindowsVirtualizer.IsRequestDescendant = tree.IsDescendant; + ((MockPlatform)GVFSPlatform.Instance).ActiveProcesses.Add(1234); + this.Repo.Repository.GVFSLock.TryAcquireLockForExternalRequestor( + new NamedPipeMessages.LockData(1234, false, false, "git apply -", string.Empty), out _).ShouldBeTrue(); + try + { + HResult result = tester.MockVirtualization.RequiredCallbacks.GetPlaceholderInfoCallback(1, "test.txt", 1234, "owner"); + if (waitEnabled) + { + result.ShouldEqual(HResult.Pending); + result = tester.MockVirtualization.WaitForCompletionStatus(); + EventMetadata metadata = new EventMetadata(); + tester.WindowsVirtualizer.AddHeartbeatMetadata(metadata); + ((long)metadata["PlaceholderLockWaitStarted"]).ShouldEqual(0); + } + + result.ShouldEqual((HResult)HResultExtensions.HResultFromNtStatus.FileNotAvailable); + tester.MockVirtualization.CreatedPlaceholders.Count.ShouldEqual(0); + } + finally + { + this.Repo.Repository.GVFSLock.ReleaseLockHeldByExternalProcess(1234); + } + } + } + + [TestCase] + public void QueuedPlaceholderAdmissionUsesEachRequestersApplyProcessFamily() + { + using (WindowsFileSystemVirtualizerTester tester = new WindowsFileSystemVirtualizerTester(this.Repo, true)) + { + tester.WindowsVirtualizer.IsRequestDescendant = (id, holder, _) => + holder.PID == 1 && id == 4 ? null : holder.PID == id || (holder.PID == 1 && id == 3); + tester.GitIndexProjection.ProjectionParseComplete = false; + this.HoldCheckoutLock(); + tester.MockVirtualization.RequiredCallbacks.GetPlaceholderInfoCallback(1, "test.txt", 1, "owner").ShouldEqual(HResult.Pending); + tester.MockVirtualization.RequiredCallbacks.GetPlaceholderInfoCallback(2, "test.txt", 2, "reader").ShouldEqual(HResult.Pending); + tester.MockVirtualization.RequiredCallbacks.GetPlaceholderInfoCallback(3, "test.txt", 3, "descendant").ShouldEqual(HResult.Pending); + tester.MockVirtualization.RequiredCallbacks.GetPlaceholderInfoCallback(4, "test.txt", 4, "unknown").ShouldEqual(HResult.Pending); + this.Repo.Repository.GVFSLock.ReleaseLockHeldByExternalProcess(1234).ShouldBeTrue(); + ((MockPlatform)GVFSPlatform.Instance).ActiveProcesses.Add(1); + this.Repo.Repository.GVFSLock.TryAcquireLockForExternalRequestor( + new NamedPipeMessages.LockData(1, false, false, "git apply patch.diff", string.Empty), out _).ShouldBeTrue(); + try + { + tester.GitIndexProjection.ProjectionParseComplete = true; + SpinWait.SpinUntil( + () => tester.MockVirtualization.CommandCompletions.Any(entry => entry.CommandId == 1), + TimeSpan.FromSeconds(10)).ShouldBeTrue(); + tester.MockVirtualization.CommandCompletions.Single(entry => entry.CommandId == 1).Result.ShouldEqual(HResult.Ok); + SpinWait.SpinUntil( + () => tester.MockVirtualization.CommandCompletions.Any(entry => entry.CommandId == 3), + TimeSpan.FromSeconds(10)).ShouldBeTrue(); + tester.MockVirtualization.CommandCompletions.Single(entry => entry.CommandId == 3).Result.ShouldEqual(HResult.Ok); + SpinWait.SpinUntil( + () => tester.MockVirtualization.CommandCompletions.Any(entry => entry.CommandId == 4), + TimeSpan.FromSeconds(10)).ShouldBeTrue(); + tester.MockVirtualization.CommandCompletions.Single(entry => entry.CommandId == 4).Result + .ShouldEqual((HResult)HResultExtensions.HResultFromNtStatus.FileNotAvailable); + SpinWait.SpinUntil( + () => tester.MockVirtualization.CommandCompletions.Any(entry => entry.CommandId == 2), + TimeSpan.FromSeconds(10)).ShouldBeTrue(); + tester.MockVirtualization.CommandCompletions.Single(entry => entry.CommandId == 2).Result + .ShouldEqual((HResult)HResultExtensions.HResultFromNtStatus.FileNotAvailable); + tester.GitIndexProjection.FileInfoRequests.ShouldEqual(2); + } + finally + { + this.Repo.Repository.GVFSLock.ReleaseLockHeldByExternalProcess(1); + } + } + } + [TestCase] public void PlaceholderRequestAncestryHandlesDescendantsUnrelatedAndUnknownChains() { @@ -598,6 +763,7 @@ public void PlaceholderRequestAncestryRejectsMissingOrReusedSharedParents(long? [TestCase("none")] [TestCase("gvfs")] [TestCase("status")] + [TestCase("apply")] public void UncontendedAndAllowedFirstOpensDoNotUseTheWaitQueue(string holder) { using (WindowsFileSystemVirtualizerTester tester = new WindowsFileSystemVirtualizerTester(this.Repo, true)) @@ -606,19 +772,20 @@ public void UncontendedAndAllowedFirstOpensDoNotUseTheWaitQueue(string holder) { this.Repo.Repository.GVFSLock.TryAcquireLockForGVFS().ShouldBeTrue(); } - else if (holder == "status") + else if (holder == "status" || holder == "apply") { ((MockPlatform)GVFSPlatform.Instance).ActiveProcesses.Add(1234); this.Repo.Repository.GVFSLock.TryAcquireLockForExternalRequestor( - new NamedPipeMessages.LockData(1234, false, false, "git status", string.Empty), out _).ShouldBeTrue(); + new NamedPipeMessages.LockData(1234, false, false, "git " + holder, string.Empty), out _).ShouldBeTrue(); } tester.GitIndexProjection.BlockGetProjectedFileInfo(willWaitForRequest: true); try { + uint processId = holder == "apply" ? 1234u : 1u; for (int id = 1; id <= 129; ++id) { - tester.MockVirtualization.RequiredCallbacks.GetPlaceholderInfoCallback(id, "test.txt", 1, "reader").ShouldEqual(HResult.Pending); + tester.MockVirtualization.RequiredCallbacks.GetPlaceholderInfoCallback(id, "test.txt", processId, "reader").ShouldEqual(HResult.Pending); } tester.GitIndexProjection.WaitForGetProjectedFileInfo(); @@ -636,7 +803,7 @@ public void UncontendedAndAllowedFirstOpensDoNotUseTheWaitQueue(string holder) { this.Repo.Repository.GVFSLock.ReleaseLockHeldByGVFS(); } - else if (holder == "status") + else if (holder == "status" || holder == "apply") { this.Repo.Repository.GVFSLock.ReleaseLockHeldByExternalProcess(1234); } @@ -1086,8 +1253,10 @@ public void PlaceholderLockWaitStopsWithoutWaitingForGit() } } - [TestCase] - public void PlaceholderLockWaitRevalidatesOwnerAfterMetadataLookup() + [TestCase("git checkout-index --stdin", false)] + [TestCase("git apply patch.diff", false)] + [TestCase("git apply patch.diff", true)] + public void PlaceholderLockWaitRevalidatesOwnerAfterMetadataLookup(string nextCommand, bool descendant) { using (WindowsFileSystemVirtualizerTester tester = new WindowsFileSystemVirtualizerTester(this.Repo, true)) { @@ -1096,11 +1265,14 @@ public void PlaceholderLockWaitRevalidatesOwnerAfterMetadataLookup() tester.MockVirtualization.RequiredCallbacks.GetPlaceholderInfoCallback(1, "test.txt", 1, "reader").ShouldEqual(HResult.Pending); this.Repo.Repository.GVFSLock.ReleaseLockHeldByExternalProcess(1234).ShouldBeTrue(); tester.GitIndexProjection.WaitForGetProjectedFileInfo(); - this.HoldCheckoutLock(); + this.Repo.Repository.GVFSLock.TryAcquireLockForExternalRequestor( + new NamedPipeMessages.LockData(1234, false, false, nextCommand, string.Empty), out _).ShouldBeTrue(); + tester.WindowsVirtualizer.IsRequestDescendant = (_, _, _) => descendant; tester.GitIndexProjection.UnblockGetProjectedFileInfo(); - tester.MockVirtualization.WaitForCompletionStatus().ShouldEqual((HResult)HResultExtensions.HResultFromNtStatus.FileNotAvailable); - tester.MockVirtualization.CreatedPlaceholders.Count.ShouldEqual(0); - tester.GitIndexProjection.CreationAttempts.ShouldEqual(0); + tester.MockVirtualization.WaitForCompletionStatus().ShouldEqual( + descendant ? HResult.Ok : (HResult)HResultExtensions.HResultFromNtStatus.FileNotAvailable); + tester.MockVirtualization.CreatedPlaceholders.Count.ShouldEqual(descendant ? 1 : 0); + tester.GitIndexProjection.CreationAttempts.ShouldEqual(descendant ? 1 : 0); this.Repo.Repository.GVFSLock.ReleaseLockHeldByExternalProcess(1234).ShouldBeTrue(); } } diff --git a/GVFS/GVFS.Virtualization/FileSystem/FileSystemVirtualizer.cs b/GVFS/GVFS.Virtualization/FileSystem/FileSystemVirtualizer.cs index 67fb3177e..017c8e7fe 100644 --- a/GVFS/GVFS.Virtualization/FileSystem/FileSystemVirtualizer.cs +++ b/GVFS/GVFS.Virtualization/FileSystem/FileSystemVirtualizer.cs @@ -147,11 +147,6 @@ protected static byte GetPlaceholderVersionFromProviderId(byte[] providerId) /// /// git-mv is also allowed to defer since it needs to create the files it moves. /// - protected bool CanCreatePlaceholder() - { - return CanCreatePlaceholderForCommand(this.Context.Repository.GVFSLock.GetLockedGitCommand()); - } - protected static bool CanCreatePlaceholderForCommand(string command) { GitCommandLineParser gitCommand = new GitCommandLineParser(command);