Ejemplo n.º 1
0
        private static bool TryGetGVFSEnlistmentRootImplementation(string directory, out string enlistmentRoot, out string errorMessage)
        {
            if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
            {
                return(POSIXPlatform.TryGetGVFSEnlistmentRootImplementation(directory, out enlistmentRoot, out errorMessage));
            }

            // Not able to use WindowsPlatform here - because of its dependency on WindowsIdentity (and also kernel32.dll).
            enlistmentRoot = null;

            string finalDirectory;

            if (!WindowsFileSystem.TryGetNormalizedPathImplementation(directory, out finalDirectory, out errorMessage))
            {
                return(false);
            }

            enlistmentRoot = Paths.GetRoot(finalDirectory, GVFSConstants.DotGVFS.Root);
            if (enlistmentRoot == null)
            {
                errorMessage = $"Failed to find the root directory for {GVFSConstants.DotGVFS.Root} in {finalDirectory}";
                return(false);
            }

            return(true);
        }
Ejemplo n.º 2
0
        public void Execute()
        {
            string normalizedCurrentDirectory;
            string errorMessage;

            if (!WindowsFileSystem.TryGetNormalizedPathImplementation(Environment.CurrentDirectory, out normalizedCurrentDirectory, out errorMessage))
            {
                throw new Exception("Unable to get normalized path: " + errorMessage);
            }

            string enlistmentRoot;

            if (!WindowsPlatform.TryGetGVFSEnlistmentRootImplementation(Environment.CurrentDirectory, out enlistmentRoot, out errorMessage))
            {
                throw new Exception("Unable to get GVFS Enlistment root: " + errorMessage);
            }

            string enlistmentPipename = Paths.GetNamedPipeName(enlistmentRoot);

            AcquireLock(enlistmentPipename);

            Console.ReadLine();

            if (!this.NoReleaseLock)
            {
                ReleaseLock(enlistmentPipename, enlistmentRoot);
            }
        }
Ejemplo n.º 3
0
        public static void Main(string[] args)
        {
            try
            {
                if (args.Length < 2)
                {
                    ExitWithError("Usage: gvfs.hooks.exe --git-pid=<pid> <hook> <git verb> [<other arguments>]");
                }

                bool unattended = GVFSEnlistment.IsUnattended(tracer: null);

                string errorMessage;
                string normalizedCurrentDirectory;
                if (!WindowsFileSystem.TryGetNormalizedPathImplementation(Environment.CurrentDirectory, out normalizedCurrentDirectory, out errorMessage))
                {
                    ExitWithError($"Failed to determine final path for current directory {Environment.CurrentDirectory}. Error: {errorMessage}");
                }

                if (!WindowsPlatform.TryGetGVFSEnlistmentRootImplementation(Environment.CurrentDirectory, out enlistmentRoot, out errorMessage))
                {
                    // 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 = Paths.GetNamedPipeName(enlistmentRoot);

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

                case PostCommandHook:
                    // Do not release the lock if this request was only run to see if it could acquire the GVFSLock,
                    // but did not actually acquire it.
                    if (!CheckGVFSLockAvailabilityOnly(args))
                    {
                        RunLockRequest(args, unattended, ReleaseGVFSLock);
                    }

                    break;

                default:
                    ExitWithError("Unrecognized hook: " + string.Join(" ", args));
                    break;
                }
            }
            catch (Exception ex)
            {
                ExitWithError("Unexpected exception: " + ex.ToString());
            }
        }
Ejemplo n.º 4
0
        private static bool TryGetGVFSEnlistmentRootImplementation(string directory, out string enlistmentRoot, out string errorMessage)
        {
            // Not able to use WindowsPlatform here - because of its dependency on WindowsIdentity (and also kernel32.dll).
            enlistmentRoot = null;

            string finalDirectory;

            if (!WindowsFileSystem.TryGetNormalizedPathImplementation(directory, out finalDirectory, out errorMessage))
            {
                return(false);
            }

            const string dotGVFSRoot = ".gvfs";

            enlistmentRoot = Paths.GetRoot(finalDirectory, dotGVFSRoot);
            if (enlistmentRoot == null)
            {
                errorMessage = $"Failed to find the root directory for {dotGVFSRoot} in {finalDirectory}";
                return(false);
            }

            return(true);
        }
Ejemplo n.º 5
0
 public static bool TryGetNormalizedPath(string path, out string normalizedPath, out string errorMessage)
 {
     return(WindowsFileSystem.TryGetNormalizedPathImplementation(path, out normalizedPath, out errorMessage));
 }