Exemple #1
0
        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();
            }
        }
Exemple #2
0
        private void HandleUnmountRequest(NamedPipeServer.Connection connection)
        {
            switch (this.currentState)
            {
            case MountState.Mounting:
                connection.TrySendResponse(NamedPipeMessages.Unmount.NotMounted);
                break;

            // Even if the previous mount failed, attempt to unmount anyway.  Otherwise the user has no
            // recourse but to kill the process.
            case MountState.MountFailed:
                goto case MountState.Ready;

            case MountState.Ready:
                this.currentState = MountState.Unmounting;

                connection.TrySendResponse(NamedPipeMessages.Unmount.Acknowledged);
                this.UnmountAndStopWorkingDirectoryCallbacks();
                connection.TrySendResponse(NamedPipeMessages.Unmount.Completed);

                this.unmountEvent.Set();
                Environment.Exit((int)ReturnCode.Success);
                break;

            case MountState.Unmounting:
                connection.TrySendResponse(NamedPipeMessages.Unmount.AlreadyUnmounting);
                break;

            default:
                connection.TrySendResponse(NamedPipeMessages.UnknownGVFSState);
                break;
            }
        }
        private void FailMountAndExit(string error, params object[] args)
        {
            this.currentState = MountState.MountFailed;

            this.tracer.RelatedError(error, args);
            if (this.showDebugWindow)
            {
                Console.WriteLine("\nPress Enter to Exit");
                Console.ReadLine();
            }

            Environment.Exit((int)ReturnCode.GenericError);
        }
Exemple #4
0
        private void SetMountState(MountState state)
        {
            CheckStateInitialized();
            for (int i = 0; i < m_MountState.Count; i++)
            {
                var item = m_MountState[i];

                if (item.accessory == state.accessory)
                {
                    m_MountState[i] = state;
                    return;
                }
            }

            m_MountState.Add(state);
        }
Exemple #5
0
        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();
            }
        }
Exemple #6
0
        public static bool WaitForStatus(CommandSender sender, MountState stat, int timeout)
        {
            //Wait for a certain status to be obtained for a specified number of seconds
            int t = timeout * 4;

            while (t > 0)
            {
                var s = new StatusCommand(sender).Execute();
                if (s != stat)
                {
                    Thread.Sleep(250);
                    t -= 1;
                }
                else
                {
                    break;
                }
            }

            return(t > 0);
        }
Exemple #7
0
        public void Mount(EventLevel verbosity, Keywords keywords)
        {
            this.currentState = MountState.Mounting;
            if (Environment.CurrentDirectory != this.enlistment.EnlistmentRoot)
            {
                Environment.CurrentDirectory = this.enlistment.EnlistmentRoot;
            }

            this.StartNamedPipe();
            this.AcquireRepoMutex();

            // Checking the disk layout version is done before this point in GVFS.CommandLine.MountVerb.PreExecute
            using (RepoMetadata repoMetadata = new RepoMetadata(this.enlistment.DotGVFSRoot))
            {
                repoMetadata.SaveCurrentDiskLayoutVersion();
            }

            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;
        }
Exemple #8
0
        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: " + error);
            }

            string gitObjectsRoot;

            if (!RepoMetadata.Instance.TryGetGitObjectsRoot(out gitObjectsRoot, out error))
            {
                this.FailMountAndExit("Failed to determine git objects root from repo metadata: " + error);
            }

            string localCacheRoot;

            if (!RepoMetadata.Instance.TryGetLocalCacheRoot(out localCacheRoot, out error))
            {
                this.FailMountAndExit("Failed to determine local cache path from repo metadata: " + error);
            }

            string blobSizesRoot;

            if (!RepoMetadata.Instance.TryGetBlobSizesRoot(out blobSizesRoot, out error))
            {
                this.FailMountAndExit("Failed to determine blob sizes root from repo metadata: " + error);
            }

            this.tracer.RelatedEvent(
                EventLevel.Informational,
                "CachePathsLoaded",
                new EventMetadata
            {
                { "gitObjectsRoot", gitObjectsRoot },
                { "localCacheRoot", localCacheRoot },
                { "blobSizesRoot", blobSizesRoot },
            });

            this.enlistment.InitializeCachePaths(localCacheRoot, gitObjectsRoot, blobSizesRoot);

            using (NamedPipeServer pipeServer = this.StartNamedPipe())
            {
                this.tracer.RelatedEvent(
                    EventLevel.Informational,
                    $"{nameof(this.Mount)}_StartedNamedPipe",
                    new EventMetadata {
                    { "NamedPipeName", this.enlistment.NamedPipeName }
                });

                this.context = this.CreateContext();

                if (this.context.Unattended)
                {
                    this.tracer.RelatedEvent(EventLevel.Critical, GVFSConstants.UnattendedEnvironmentVariable, null);
                }

                this.ValidateMountPoints();

                string errorMessage;
                if (!HooksInstaller.TryUpdateHooks(this.context, out errorMessage))
                {
                    this.FailMountAndExit(errorMessage);
                }

                GVFSPlatform.Instance.ConfigureVisualStudio(this.enlistment.GitBinPath, this.tracer);

                this.MountAndStartWorkingDirectoryCallbacks(this.cacheServer);

                Console.Title = "GVFS " + ProcessHelper.GetCurrentProcessVersion() + " - " + this.enlistment.EnlistmentRoot;

                this.tracer.RelatedEvent(
                    EventLevel.Informational,
                    "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" },
                },
                    Keywords.Telemetry);

                this.currentState = MountState.Ready;

                this.unmountEvent.WaitOne();
            }
        }