private static void AcquireLock(string enlistmentPipename) { using (NamedPipeClient pipeClient = new NamedPipeClient(enlistmentPipename)) { if (!pipeClient.Connect()) { throw new Exception("The repo does not appear to be mounted. Use 'gvfs status' to check."); } int pid = Process.GetCurrentProcess().Id; string result; if (!GVFSLock.TryAcquireGVFSLockForProcess( unattended: false, pipeClient: pipeClient, fullCommand: AcquireGVFSLockVerb.fullCommand, pid: pid, isElevated: false, isConsoleOutputRedirectedToFile: false, checkAvailabilityOnly: false, gvfsEnlistmentRoot: null, gitCommandSessionId: string.Empty, result: out result)) { throw new Exception(result); } } }
public void Mount(EventLevel verbosity, Keywords keywords) { this.currentState = MountState.Mounting; if (Environment.CurrentDirectory != this.enlistment.EnlistmentRoot) { Environment.CurrentDirectory = this.enlistment.EnlistmentRoot; } using (NamedPipeServer pipeServer = this.StartNamedPipe()) { this.AcquireRepoMutex(); GVFSContext context = this.CreateContext(); this.ValidateMountPoints(); this.UpdateHooks(); this.gvfsLock = context.Repository.GVFSLock; this.MountAndStartWorkingDirectoryCallbacks(context); Console.Title = "GVFS " + ProcessHelper.GetCurrentProcessVersion() + " - " + this.enlistment.EnlistmentRoot; this.tracer.RelatedEvent( EventLevel.Critical, "Mount", new EventMetadata { { "Message", "Virtual repo is ready" }, }); this.currentState = MountState.Ready; this.unmountEvent.WaitOne(); } }
public void ReleaseLockHeldByGVFS_WhenExternalHasLockShouldThrow() { MockPlatform mockPlatform = (MockPlatform)GVFSPlatform.Instance; GVFSLock gvfsLock = this.AcquireDefaultLock(mockPlatform); Assert.Throws <InvalidOperationException>(() => gvfsLock.ReleaseLockHeldByGVFS()); }
public void ReleaseLockHeldByGVFS_WhenNoLock() { GVFSLock gvfsLock = new GVFSLock(new MockTracer()); this.ValidateLockIsFree(gvfsLock); Assert.Throws <InvalidOperationException>(() => gvfsLock.ReleaseLockHeldByGVFS()); }
public void ReleaseLockHeldByExternalProcess_WhenGVFSHasLock() { GVFSLock gvfsLock = this.AcquireGVFSLock(); gvfsLock.ReleaseLockHeldByExternalProcess(DefaultLockData.PID).ShouldBeFalse(); this.ValidateLockHeldByGVFS(gvfsLock); }
private void AcquireLock(string enlistmentRoot) { string pipeName = Paths.GetNamedPipeName(enlistmentRoot); using (NamedPipeClient pipeClient = new NamedPipeClient(pipeName)) { try { if (!pipeClient.Connect()) { this.ReportErrorAndExit("Unable to connect to GVFS while acquiring lock to unmount. Try 'gvfs status' to verify if the repo is mounted."); return; } Process currentProcess = Process.GetCurrentProcess(); string result = null; if (!GVFSLock.TryAcquireGVFSLockForProcess( pipeClient, "gvfs unmount", currentProcess.Id, currentProcess, enlistmentRoot, out result)) { this.ReportErrorAndExit("Unable to acquire the lock prior to unmount. " + result); } } catch (BrokenPipeException) { this.ReportErrorAndExit("Unable to acquire the lock prior to unmount. Try 'gvfs status' to verify if the repo is mounted."); } } }
private void AcquireLock(string enlistmentRoot) { string pipeName = Paths.GetNamedPipeName(enlistmentRoot); using (NamedPipeClient pipeClient = new NamedPipeClient(pipeName)) { try { if (!pipeClient.Connect()) { this.ReportErrorAndExit("Unable to connect to GVFS while acquiring lock to unmount. Try 'gvfs status' to verify if the repo is mounted."); return; } Process currentProcess = Process.GetCurrentProcess(); string result = null; if (!GVFSLock.TryAcquireGVFSLockForProcess( this.Unattended, pipeClient, "gvfs unmount", currentProcess.Id, GVFSPlatform.Instance.IsElevated(), checkAvailabilityOnly: false, gvfsEnlistmentRoot: enlistmentRoot, result: out result)) { this.ReportErrorAndExit("Unable to acquire the lock prior to unmount. " + result); } } catch (BrokenPipeException) { this.ReportErrorAndExit("Unable to acquire the lock prior to unmount. Try 'gvfs status' to verify if the repo is mounted."); } } }
public void TryAcquireLockForGVFS_WhenExternalLock() { MockPlatform mockPlatform = (MockPlatform)GVFSPlatform.Instance; GVFSLock gvfsLock = this.AcquireDefaultLock(mockPlatform); gvfsLock.TryAcquireLockForGVFS().ShouldBeFalse(); mockPlatform.ActiveProcesses.Remove(DefaultLockData.PID); }
public void ReleaseLockHeldByExternalProcess_WhenNoLock() { GVFSLock gvfsLock = new GVFSLock(new MockTracer()); this.ValidateLockIsFree(gvfsLock); gvfsLock.ReleaseLockHeldByExternalProcess(DefaultLockData.PID).ShouldBeFalse(); this.ValidateLockIsFree(gvfsLock); }
public void ReleaseLockHeldByExternalProcess_DifferentPID() { MockPlatform mockPlatform = (MockPlatform)GVFSPlatform.Instance; GVFSLock gvfsLock = this.AcquireDefaultLock(mockPlatform); gvfsLock.ReleaseLockHeldByExternalProcess(4321).ShouldBeFalse(); this.ValidateLockHeld(gvfsLock, DefaultLockData); }
public void TryAcquireLockForExternalRequestor_WhenGVFSLock() { GVFSLock gvfsLock = this.AcquireGVFSLock(); NamedPipeMessages.LockData existingExternalHolder; gvfsLock.TryAcquireLockForExternalRequestor(DefaultLockData, out existingExternalHolder).ShouldBeFalse(); this.ValidateLockHeldByGVFS(gvfsLock); existingExternalHolder.ShouldBeNull(); }
private GVFSLock AcquireGVFSLock(ITracer mockTracer) { GVFSLock gvfsLock = new GVFSLock(mockTracer); this.ValidateLockIsFree(gvfsLock); gvfsLock.TryAcquireLockForGVFS().ShouldBeTrue(); this.ValidateLockHeldByGVFS(gvfsLock); return(gvfsLock); }
public void ReleaseLockHeldByGVFS_WhenNoLock() { Mock <ITracer> mockTracer = new Mock <ITracer>(MockBehavior.Strict); GVFSLock gvfsLock = new GVFSLock(mockTracer.Object); this.ValidateLockIsFree(gvfsLock); Assert.Throws <InvalidOperationException>(() => gvfsLock.ReleaseLockHeldByGVFS()); mockTracer.VerifyAll(); }
public void TryAcquireAndReleaseLockForExternalRequestor() { MockPlatform mockPlatform = (MockPlatform)GVFSPlatform.Instance; GVFSLock gvfsLock = this.AcquireDefaultLock(mockPlatform); mockPlatform.ActiveProcesses.Remove(DefaultLockData.PID); gvfsLock.ReleaseLockHeldByExternalProcess(DefaultLockData.PID); this.ValidateLockIsFree(gvfsLock); }
public void TryAcquireLockForGVFS() { GVFSLock gvfsLock = this.AcquireGVFSLock(); // Should be able to call again when GVFS has the lock gvfsLock.TryAcquireLockForGVFS().ShouldBeTrue(); this.ValidateLockHeldByGVFS(gvfsLock); gvfsLock.ReleaseLockHeldByGVFS(); this.ValidateLockIsFree(gvfsLock); }
public void ReleaseLockHeldByGVFS_WhenExternalHasLockShouldThrow() { Mock <ITracer> mockTracer = new Mock <ITracer>(MockBehavior.Strict); mockTracer.Setup(x => x.RelatedEvent(EventLevel.Informational, "TryAcquireLockExternal", It.IsAny <EventMetadata>())); MockPlatform mockPlatform = (MockPlatform)GVFSPlatform.Instance; GVFSLock gvfsLock = this.AcquireDefaultLock(mockPlatform, mockTracer.Object); Assert.Throws <InvalidOperationException>(() => gvfsLock.ReleaseLockHeldByGVFS()); mockTracer.VerifyAll(); }
private GVFSLock AcquireDefaultLock(MockPlatform mockPlatform, ITracer mockTracer) { GVFSLock gvfsLock = new GVFSLock(mockTracer); this.ValidateLockIsFree(gvfsLock); NamedPipeMessages.LockData existingExternalHolder; gvfsLock.TryAcquireLockForExternalRequestor(DefaultLockData, out existingExternalHolder).ShouldBeTrue(); existingExternalHolder.ShouldBeNull(); mockPlatform.ActiveProcesses.Add(DefaultLockData.PID); this.ValidateLockHeld(gvfsLock, DefaultLockData); return(gvfsLock); }
public void ReleaseLockHeldByExternalProcess_WhenGVFSHasLock() { Mock <ITracer> mockTracer = new Mock <ITracer>(MockBehavior.Strict); mockTracer.Setup(x => x.RelatedEvent(EventLevel.Verbose, "TryAcquireLockInternal", It.IsAny <EventMetadata>())); mockTracer.Setup(x => x.RelatedEvent(EventLevel.Informational, "ReleaseLockHeldByExternalProcess", It.IsAny <EventMetadata>(), Keywords.Telemetry)); GVFSLock gvfsLock = this.AcquireGVFSLock(mockTracer.Object); gvfsLock.ReleaseLockHeldByExternalProcess(DefaultLockData.PID).ShouldBeFalse(); this.ValidateLockHeldByGVFS(gvfsLock); mockTracer.VerifyAll(); }
public void TryAcquireLockForExternalRequestor_WhenExternalLock() { MockPlatform mockPlatform = (MockPlatform)GVFSPlatform.Instance; GVFSLock gvfsLock = this.AcquireDefaultLock(mockPlatform); NamedPipeMessages.LockData newLockData = new NamedPipeMessages.LockData(4321, false, false, "git new"); NamedPipeMessages.LockData existingExternalHolder; gvfsLock.TryAcquireLockForExternalRequestor(newLockData, out existingExternalHolder).ShouldBeFalse(); this.ValidateLockHeld(gvfsLock, DefaultLockData); this.ValidateExistingExternalHolder(DefaultLockData, existingExternalHolder); mockPlatform.ActiveProcesses.Remove(DefaultLockData.PID); }
public void TryAcquireLockForGVFS_WhenExternalLock() { Mock <ITracer> mockTracer = new Mock <ITracer>(MockBehavior.Strict); mockTracer.Setup(x => x.RelatedEvent(EventLevel.Informational, "TryAcquireLockExternal", It.IsAny <EventMetadata>())); mockTracer.Setup(x => x.RelatedEvent(EventLevel.Verbose, "TryAcquireLockInternal", It.IsAny <EventMetadata>())); MockPlatform mockPlatform = (MockPlatform)GVFSPlatform.Instance; GVFSLock gvfsLock = this.AcquireDefaultLock(mockPlatform, mockTracer.Object); gvfsLock.TryAcquireLockForGVFS().ShouldBeFalse(); mockPlatform.ActiveProcesses.Remove(DefaultLockData.PID); mockTracer.VerifyAll(); }
public void ReleaseLockHeldByExternalProcess_DifferentPID() { Mock <ITracer> mockTracer = new Mock <ITracer>(MockBehavior.Strict); mockTracer.Setup(x => x.RelatedEvent(EventLevel.Informational, "ReleaseLockHeldByExternalProcess", It.IsAny <EventMetadata>(), Keywords.Telemetry)); mockTracer.Setup(x => x.RelatedEvent(EventLevel.Informational, "TryAcquireLockExternal", It.IsAny <EventMetadata>())); MockPlatform mockPlatform = (MockPlatform)GVFSPlatform.Instance; GVFSLock gvfsLock = this.AcquireDefaultLock(mockPlatform, mockTracer.Object); gvfsLock.ReleaseLockHeldByExternalProcess(4321).ShouldBeFalse(); this.ValidateLockHeld(gvfsLock, DefaultLockData); mockTracer.VerifyAll(); }
public void TryAcquireAndReleaseLockForExternalRequestor() { Mock <ITracer> mockTracer = new Mock <ITracer>(MockBehavior.Strict); mockTracer.Setup(x => x.RelatedEvent(EventLevel.Informational, "TryAcquireLockExternal", It.IsAny <EventMetadata>())); mockTracer.Setup(x => x.RelatedEvent(EventLevel.Informational, "ReleaseLockHeldByExternalProcess", It.IsAny <EventMetadata>(), Keywords.Telemetry)); MockPlatform mockPlatform = (MockPlatform)GVFSPlatform.Instance; GVFSLock gvfsLock = this.AcquireDefaultLock(mockPlatform, mockTracer.Object); mockPlatform.ActiveProcesses.Remove(DefaultLockData.PID); gvfsLock.ReleaseLockHeldByExternalProcess(DefaultLockData.PID); this.ValidateLockIsFree(gvfsLock); mockTracer.VerifyAll(); }
public void Dispose() { if (this.libgit2RepoPool != null) { this.libgit2RepoPool.Dispose(); this.libgit2RepoPool = null; } if (this.GVFSLock != null) { this.GVFSLock.Dispose(); this.GVFSLock = null; } }
public void TryAcquireLockForExternalRequestor_WhenGVFSLock() { Mock <ITracer> mockTracer = new Mock <ITracer>(MockBehavior.Strict); mockTracer.Setup(x => x.RelatedEvent(EventLevel.Verbose, "TryAcquireLockInternal", It.IsAny <EventMetadata>())); mockTracer.Setup(x => x.RelatedEvent(EventLevel.Verbose, "TryAcquireLockExternal", It.IsAny <EventMetadata>())); GVFSLock gvfsLock = this.AcquireGVFSLock(mockTracer.Object); NamedPipeMessages.LockData existingExternalHolder; gvfsLock.TryAcquireLockForExternalRequestor(DefaultLockData, out existingExternalHolder).ShouldBeFalse(); this.ValidateLockHeldByGVFS(gvfsLock); existingExternalHolder.ShouldBeNull(); mockTracer.VerifyAll(); }
private void ValidateLock( GVFSLock gvfsLock, NamedPipeMessages.LockData expected, string expectedStatus, string expectedGitCommand, bool expectedIsAvailable) { gvfsLock.GetStatus().ShouldEqual(expectedStatus); NamedPipeMessages.LockData existingHolder; gvfsLock.IsLockAvailableForExternalRequestor(out existingHolder).ShouldEqual(expectedIsAvailable); this.ValidateExistingExternalHolder(expected, existingHolder); gvfsLock.GetLockedGitCommand().ShouldEqual(expectedGitCommand); NamedPipeMessages.LockData externalHolder = gvfsLock.GetExternalHolder(); this.ValidateExistingExternalHolder(expected, externalHolder); }
private static void AcquireGVFSLockForProcess(string fullCommand, int pid, Process parentProcess, NamedPipeClient pipeClient) { string result; if (!GVFSLock.TryAcquireGVFSLockForProcess( pipeClient, fullCommand, pid, parentProcess, null, // gvfsEnlistmentRoot out result)) { ExitWithError(result); } }
public void TryAcquireLockForGVFS() { Mock <ITracer> mockTracer = new Mock <ITracer>(MockBehavior.Strict); mockTracer.Setup(x => x.RelatedEvent(EventLevel.Verbose, "TryAcquireLockInternal", It.IsAny <EventMetadata>())); mockTracer.Setup(x => x.RelatedEvent(EventLevel.Verbose, "ReleaseLockHeldByGVFS", It.IsAny <EventMetadata>())); GVFSLock gvfsLock = this.AcquireGVFSLock(mockTracer.Object); // Should be able to call again when GVFS has the lock gvfsLock.TryAcquireLockForGVFS().ShouldBeTrue(); this.ValidateLockHeldByGVFS(gvfsLock); gvfsLock.ReleaseLockHeldByGVFS(); this.ValidateLockIsFree(gvfsLock); mockTracer.VerifyAll(); }
public void TryAcquireLockForExternalRequestor_WhenExternalLock() { Mock <ITracer> mockTracer = new Mock <ITracer>(MockBehavior.Strict); mockTracer.Setup(x => x.RelatedEvent(EventLevel.Informational, "TryAcquireLockExternal", It.IsAny <EventMetadata>())); mockTracer.Setup(x => x.RelatedEvent(EventLevel.Verbose, "TryAcquireLockExternal", It.IsAny <EventMetadata>())); MockPlatform mockPlatform = (MockPlatform)GVFSPlatform.Instance; GVFSLock gvfsLock = this.AcquireDefaultLock(mockPlatform, mockTracer.Object); NamedPipeMessages.LockData newLockData = new NamedPipeMessages.LockData(4321, false, false, "git new", "123"); NamedPipeMessages.LockData existingExternalHolder; gvfsLock.TryAcquireLockForExternalRequestor(newLockData, out existingExternalHolder).ShouldBeFalse(); this.ValidateLockHeld(gvfsLock, DefaultLockData); this.ValidateExistingExternalHolder(DefaultLockData, existingExternalHolder); mockPlatform.ActiveProcesses.Remove(DefaultLockData.PID); mockTracer.VerifyAll(); }
private static void AcquireGVFSLockForProcess(bool unattended, string fullCommand, int pid, Process parentProcess, NamedPipeClient pipeClient) { string result; if (!GVFSLock.TryAcquireGVFSLockForProcess( unattended, pipeClient, fullCommand, pid, ProcessHelper.IsAdminElevated(), parentProcess, null, // gvfsEnlistmentRoot out result)) { ExitWithError(result); } }
public void Mount(EventLevel verbosity, Keywords keywords) { this.currentState = MountState.Mounting; // We must initialize repo metadata before starting the pipe server so it // can immediately handle status requests string error; if (!RepoMetadata.TryInitialize(this.tracer, this.enlistment.DotGVFSRoot, out error)) { this.FailMountAndExit("Failed to load repo metadata: {0}", error); } using (NamedPipeServer pipeServer = this.StartNamedPipe()) { GVFSContext context = this.CreateContext(); if (context.Unattended) { this.tracer.RelatedEvent(EventLevel.Critical, GVFSConstants.UnattendedEnvironmentVariable, null); } this.ValidateMountPoints(); this.UpdateHooks(); this.SetVisualStudioRegistryKey(); this.gvfsLock = context.Repository.GVFSLock; this.MountAndStartWorkingDirectoryCallbacks(context, this.cacheServer); Console.Title = "GVFS " + ProcessHelper.GetCurrentProcessVersion() + " - " + this.enlistment.EnlistmentRoot; this.tracer.RelatedEvent( EventLevel.Critical, "Mount", new EventMetadata { // Use TracingConstants.MessageKey.InfoMessage rather than TracingConstants.MessageKey.CriticalMessage // as this message should not appear as an error { TracingConstants.MessageKey.InfoMessage, "Virtual repo is ready" }, }); this.currentState = MountState.Ready; this.unmountEvent.WaitOne(); } }