Example #1
0
        public override void Execute()
        {
            this.EnlistmentRootPath =
                !string.IsNullOrWhiteSpace(this.EnlistmentRootPath)
                ? this.EnlistmentRootPath
                : Environment.CurrentDirectory;
            string root = null;

            if (Directory.Exists(this.EnlistmentRootPath))
            {
                root = EnlistmentUtils.GetEnlistmentRoot(this.EnlistmentRootPath);
            }

            if (root == null)
            {
                this.ReportErrorAndExit(
                    "Error: '{0}' is not a valid GVFS enlistment",
                    this.EnlistmentRootPath);
            }

            string errorMessage = null;

            if (!this.ShowStatusWhileRunning(
                    () => { return(this.RequestUnmount(root, out errorMessage)); },
                    "Unmounting"))
            {
                this.ReportErrorAndExit(errorMessage);
            }
        }
Example #2
0
        private void CheckNotInsideExistingRepo()
        {
            string enlistmentRootPath = this.EnlistmentRootPath;

            if (string.IsNullOrWhiteSpace(enlistmentRootPath))
            {
                enlistmentRootPath = Environment.CurrentDirectory;
            }

            string enlistmentRoot = EnlistmentUtils.GetEnlistmentRoot(enlistmentRootPath);

            if (enlistmentRoot != null)
            {
                this.ReportErrorAndExit("Error: You can't clone inside an existing GVFS repo ({0})", enlistmentRoot);
            }
        }
Example #3
0
        public static void Main(string[] args)
        {
            args = ReadAndRemoveSpecialArgValues(args);

            try
            {
                if (args.Length < 2)
                {
                    ExitWithError("Usage: gvfs.hooks <hook> <git verb> [<other arguments>]");
                }

                enlistmentRoot = EnlistmentUtils.GetEnlistmentRoot(Environment.CurrentDirectory);
                if (string.IsNullOrEmpty(enlistmentRoot))
                {
                    // Nothing to hook when being run outside of a GVFS repo.
                    // This is also the path when run with --git-dir outside of a GVFS directory, see Story #949665
                    Environment.Exit(0);
                }

                enlistmentPipename = EnlistmentUtils.GetNamedPipeName(enlistmentRoot);

                switch (GetHookType(args))
                {
                case PreCommandHook:
                    CheckForLegalCommands(args);
                    RunLockRequest(args, AcquireGVFSLockForProcess);
                    RunPreCommands(args);
                    break;

                case PostCommandHook:
                    RunLockRequest(args, ReleaseGVFSLock);
                    break;

                default:
                    ExitWithError("Unrecognized hook: " + string.Join(" ", args));
                    break;
                }
            }
            catch (Exception ex)
            {
                ExitWithError("Unexpected exception: " + ex.ToString());
            }
        }
Example #4
0
        protected override void PreExecute(string enlistmentRootPath)
        {
            this.CheckElevated();
            this.CheckGVFltRunning();

            if (string.IsNullOrWhiteSpace(enlistmentRootPath))
            {
                enlistmentRootPath = Environment.CurrentDirectory;
            }

            string enlistmentRoot = null;

            if (Directory.Exists(enlistmentRootPath))
            {
                enlistmentRoot = EnlistmentUtils.GetEnlistmentRoot(enlistmentRootPath);
            }

            if (enlistmentRoot == null)
            {
                this.ReportErrorAndExit("Error: '{0}' is not a valid GVFS enlistment", enlistmentRootPath);
            }

            if (!this.SkipMountedCheck)
            {
                using (NamedPipeClient pipeClient = new NamedPipeClient(EnlistmentUtils.GetNamedPipeName(enlistmentRoot)))
                {
                    if (pipeClient.Connect(500))
                    {
                        this.ReportErrorAndExit(ReturnCode.Success, "This repo is already mounted.");
                    }
                }
            }

            bool   allowUpgrade = true;
            string error;

            if (!RepoMetadata.CheckDiskLayoutVersion(Path.Combine(enlistmentRoot, GVFSConstants.DotGVFSPath), allowUpgrade, out error))
            {
                this.ReportErrorAndExit("Error: " + error);
            }
        }
Example #5
0
        private bool RequestUnmount(string rootPath, out string errorMessage)
        {
            try
            {
                string pipeName = EnlistmentUtils.GetNamedPipeName(rootPath);
                using (NamedPipeClient pipeClient = new NamedPipeClient(pipeName))
                {
                    if (!pipeClient.Connect())
                    {
                        errorMessage = "Unable to connect to GVFS";
                        return(false);
                    }

                    pipeClient.SendRequest(NamedPipeMessages.GetStatus.Request);
                    string rawGetStatusResponse = pipeClient.ReadRawResponse();
                    NamedPipeMessages.GetStatus.Response getStatusResponse =
                        NamedPipeMessages.GetStatus.Response.FromJson(rawGetStatusResponse);

                    switch (getStatusResponse.MountStatus)
                    {
                    case NamedPipeMessages.GetStatus.Mounting:
                        errorMessage = "Still mounting, please try again later";
                        return(false);

                    case NamedPipeMessages.GetStatus.Unmounting:
                        errorMessage = "Already unmounting, please wait";
                        return(false);

                    case NamedPipeMessages.GetStatus.Ready:
                        break;

                    case NamedPipeMessages.GetStatus.MountFailed:
                        break;

                    default:
                        errorMessage = "Unrecognized response to GetStatus: " + rawGetStatusResponse;
                        return(false);
                    }

                    pipeClient.SendRequest(NamedPipeMessages.Unmount.Request);
                    string unmountResponse = pipeClient.ReadRawResponse();

                    switch (unmountResponse)
                    {
                    case NamedPipeMessages.Unmount.Acknowledged:
                        string finalResponse = pipeClient.ReadRawResponse();
                        if (finalResponse == NamedPipeMessages.Unmount.Completed)
                        {
                            errorMessage = null;
                            return(true);
                        }
                        else
                        {
                            errorMessage = "Unrecognized final response to unmount: " + finalResponse;
                            return(false);
                        }

                    case NamedPipeMessages.Unmount.NotMounted:
                        errorMessage = "Unable to unmount, repo was not mounted";
                        return(false);

                    case NamedPipeMessages.Unmount.MountFailed:
                        errorMessage = "Unable to unmount, previous mount attempt failed";
                        return(false);

                    default:
                        errorMessage = "Unrecognized response to unmount: " + unmountResponse;
                        return(false);
                    }
                }
            }
            catch (BrokenPipeException e)
            {
                errorMessage = "Unable to communicate with GVFS: " + e.ToString();
                return(false);
            }
        }