protected override void OnSessionChange(SessionChangeDescription changeDescription)
        {
            try
            {
                base.OnSessionChange(changeDescription);

                if (!GVFSEnlistment.IsUnattended(tracer: null))
                {
                    if (changeDescription.Reason == SessionChangeReason.SessionLogon)
                    {
                        this.tracer.RelatedInfo("SessionLogon detected, sessionId: {0}", changeDescription.SessionId);

                        this.LaunchServiceUIIfNotRunning(changeDescription.SessionId);

                        using (ITracer activity = this.tracer.StartActivity("LogonAutomount", EventLevel.Informational))
                        {
                            this.repoRegistry.AutoMountRepos(
                                GVFSPlatform.Instance.GetUserIdFromLoginSessionId(changeDescription.SessionId, this.tracer),
                                changeDescription.SessionId);
                            this.repoRegistry.TraceStatus();
                        }
                    }
                    else if (changeDescription.Reason == SessionChangeReason.SessionLogoff)
                    {
                        this.tracer.RelatedInfo("SessionLogoff detected");
                    }
                }
            }
            catch (Exception e)
            {
                this.LogExceptionAndExit(e, nameof(this.OnSessionChange));
            }
        }
Esempio n. 2
0
        public static bool TrySetRequiredGitConfigSettings(Enlistment enlistment)
        {
            string expectedHooksPath = Path.Combine(enlistment.WorkingDirectoryRoot, GVFSConstants.DotGit.Hooks.Root);

            expectedHooksPath = Paths.ConvertPathToGitFormat(expectedHooksPath);

            string gitStatusCachePath = null;

            if (!GVFSEnlistment.IsUnattended(tracer: null) && GVFSPlatform.Instance.IsGitStatusCacheSupported())
            {
                gitStatusCachePath = Path.Combine(
                    enlistment.EnlistmentRoot,
                    GVFSConstants.DotGVFS.Root,
                    GVFSConstants.DotGVFS.GitStatusCache.CachePath);

                gitStatusCachePath = Paths.ConvertPathToGitFormat(gitStatusCachePath);
            }

            // These settings are required for normal GVFS functionality.
            // They will override any existing local configuration values.
            Dictionary <string, string> requiredSettings = new Dictionary <string, string>
            {
                { "am.keepcr", "true" },
                { "core.autocrlf", "false" },
                { "core.commitGraph", "true" },
                { "core.fscache", "true" },
                { "core.gvfs", "true" },
                { "core.multiPackIndex", "true" },
                { "core.preloadIndex", "true" },
                { "core.safecrlf", "false" },
                { "core.untrackedCache", "false" },
                { "core.repositoryformatversion", "0" },
                { "core.filemode", "false" },
                { "core.bare", "false" },
                { "core.logallrefupdates", "true" },
                { GitConfigSetting.CoreVirtualizeObjectsName, "true" },
                { GitConfigSetting.CoreVirtualFileSystemName, Paths.ConvertPathToGitFormat(GVFSConstants.DotGit.Hooks.VirtualFileSystemPath) },
                { "core.hookspath", expectedHooksPath },
                { GitConfigSetting.CredentialUseHttpPath, "true" },
                { "credential.validate", "false" },
                { "diff.autoRefreshIndex", "false" },
                { "gc.auto", "0" },
                { "gui.gcwarning", "false" },
                { "index.version", "4" },
                { "merge.stat", "false" },
                { "merge.renames", "false" },
                { "pack.useBitmaps", "false" },
                { "receive.autogc", "false" },
                { "status.deserializePath", gitStatusCachePath },
            };

            if (!TrySetConfig(enlistment, requiredSettings, isRequired: true))
            {
                return(false);
            }

            return(true);
        }
Esempio 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 (!GVFSHooksPlatform.TryGetNormalizedPath(Environment.CurrentDirectory, out normalizedCurrentDirectory, out errorMessage))
                {
                    ExitWithError($"Failed to determine final path for current directory {Environment.CurrentDirectory}. Error: {errorMessage}");
                }

                if (!GVFSHooksPlatform.TryGetGVFSEnlistmentRoot(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 = GVFSHooksPlatform.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);
                    }

                    RunPostCommands(args, unattended);
                    break;

                default:
                    ExitWithError("Unrecognized hook: " + string.Join(" ", args));
                    break;
                }
            }
            catch (Exception ex)
            {
                ExitWithError("Unexpected exception: " + ex.ToString());
            }
        }
Esempio n. 4
0
        public GVFSVerb()
        {
            this.Output      = Console.Out;
            this.ReturnCode  = ReturnCode.Success;
            this.ServiceName = GVFSConstants.Service.ServiceName;

            this.Unattended = GVFSEnlistment.IsUnattended(tracer: null);

            this.InitializeDefaultParameterValues();
        }
Esempio n. 5
0
        public GVFSVerb(bool validateOrigin = true)
        {
            this.Output            = Console.Out;
            this.ReturnCode        = ReturnCode.Success;
            this.validateOriginURL = validateOrigin;
            this.ServiceName       = GVFSConstants.Service.ServiceName;
            this.StartedByService  = false;
            this.Unattended        = GVFSEnlistment.IsUnattended(tracer: null);

            this.InitializeDefaultParameterValues();
        }
Esempio n. 6
0
        public void Start()
        {
            if (!GVFSEnlistment.IsUnattended(this.tracer))
            {
                TimeSpan startTime = TimeSpan.Zero;

                this.tracer.RelatedInfo("Starting auto upgrade checks.");
                this.timer = new Timer(
                    this.TimerCallback,
                    state: null,
                    dueTime: startTime,
                    period: TimeInterval);
            }
            else
            {
                this.tracer.RelatedInfo("No upgrade checks scheduled, GVFS is running in unattended mode.");
            }
        }
Esempio n. 7
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);

                enlistmentRoot = Paths.GetGVFSEnlistmentRoot(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 = Paths.GetNamedPipeName(enlistmentRoot);

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

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

                default:
                    ExitWithError("Unrecognized hook: " + string.Join(" ", args));
                    break;
                }
            }
            catch (Exception ex)
            {
                ExitWithError("Unexpected exception: " + ex.ToString());
            }
        }
Esempio n. 8
0
        public BackgroundPrefetcher(ITracer tracer, GVFSEnlistment enlistment, PhysicalFileSystem fileSystem, GitObjects gitObjects)
        {
            this.tracer     = tracer;
            this.enlistment = enlistment;
            this.fileSystem = fileSystem;
            this.gitObjects = gitObjects;

            this.prefetchJobThread = null;

            if (gitObjects.IsUsingCacheServer() && !GVFSEnlistment.IsUnattended(tracer))
            {
                this.prefetchJobTimer = new Timer((state) => this.LaunchPrefetchJobIfIdle(), null, this.timerPeriod, this.timerPeriod);
                this.tracer.RelatedInfo(nameof(BackgroundPrefetcher) + ": starting background prefetch timer");
            }
            else
            {
                this.tracer.RelatedInfo(nameof(BackgroundPrefetcher) + ": no configured cache server or enlistment is unattended, not starting background prefetch timer");
            }
        }
        public void Start()
        {
            if (!GVFSEnlistment.IsUnattended(this.tracer))
            {
                // Adding 60 seconds wait time here. This gives VFSForGit installer/upgrader
                // sufficient enough time to launch GVFS.Service.UI that is needed to display
                // Upgrade available toaster.
                TimeSpan startTime = TimeSpan.FromSeconds(60);

                this.tracer.RelatedInfo("Starting auto upgrade checks.");
                this.timer = new Timer(
                    this.TimerCallback,
                    state: null,
                    dueTime: startTime,
                    period: TimeInterval);
            }
            else
            {
                this.tracer.RelatedInfo("No upgrade checks scheduled, GVFS is running in unattended mode.");
            }
        }
Esempio n. 10
0
 protected virtual bool IsUnattended()
 {
     return(GVFSEnlistment.IsUnattended(this.tracer));
 }