private void MountAndStartWorkingDirectoryCallbacks(GVFSContext context) { HttpGitObjects httpGitObjects = new HttpGitObjects(context.Tracer, context.Enlistment, Environment.ProcessorCount); if (!httpGitObjects.TryRefreshCredentials()) { this.FailMountAndExit("Failed to obtain git credentials"); } // Checking the disk layout version is done before this point in GVFS.CommandLine.MountVerb.PreExecute RepoMetadata repoMetadata = new RepoMetadata(this.enlistment.DotGVFSRoot); this.gitObjects = new GVFSGitObjects(context, httpGitObjects); this.gvfltCallbacks = this.CreateOrReportAndExit(() => new GVFltCallbacks(context, this.gitObjects, repoMetadata), "Failed to create src folder callbacks"); int persistedVersion; string error; if (!repoMetadata.TryGetOnDiskLayoutVersion(out persistedVersion, out error)) { this.FailMountAndExit("Error: {0}", error); } if (!repoMetadata.OnDiskVersionUsesAlwaysExclude()) { // Want this as close to repoMetadata.SaveCurrentDiskLayoutVersion() as possible to avoid possible corrupt states. this.UpdateToAlwaysExcludeFile(repoMetadata); } try { if (!this.gvfltCallbacks.TryStart(out error)) { this.FailMountAndExit("Error: {0}. \r\nPlease confirm that gvfs clone completed without error.", error); } } catch (Exception e) { this.FailMountAndExit("Failed to initialize src folder callbacks. {0}", e.ToString()); } repoMetadata.SaveCurrentDiskLayoutVersion(); repoMetadata.SetAlwaysExcludeInvalid(false); this.AcquireFolderLocks(context); this.heartbeat = new HeartbeatThread(this.tracer, this.gvfltCallbacks); this.heartbeat.Start(); }
private void UpdateToAlwaysExcludeFile(RepoMetadata repoMetadata) { if (repoMetadata.GetAlwaysExcludeInvalid()) { this.FailMountAndExit("always_exclude left in a corrupt state after failed mount."); } string alwaysExcludePath = Path.Combine(this.enlistment.WorkingDirectoryRoot, GVFSConstants.DotGit.Info.AlwaysExcludePath); if (File.Exists(alwaysExcludePath)) { this.FailMountAndExit("Error migrating to " + alwaysExcludePath + ", file already exists."); } string excludePath = Path.Combine(this.enlistment.WorkingDirectoryRoot, GVFSConstants.DotGit.Info.ExcludePath); if (File.Exists(excludePath)) { try { string[] lines = File.ReadAllLines(excludePath); // To be valid, both exclude and always_exclude must be correctly written to, // and the disk layout version stored on disk must be updated. repoMetadata.SetAlwaysExcludeInvalid(true); string newAlwaysExcludeContents = string.Join("\n", lines.Where(x => !x.StartsWith(GVFSConstants.GitCommentSignString))) + "\n"; string newExcludeContents = string.Join("\n", lines.Where(x => x.StartsWith(GVFSConstants.GitCommentSignString))) + "\n"; File.WriteAllText(alwaysExcludePath, newAlwaysExcludeContents); File.WriteAllText(excludePath, newExcludeContents); } catch (Exception e) { EventMetadata metadata = new EventMetadata(); metadata.Add("Area", "Mount"); metadata.Add("alwaysExcludePath", alwaysExcludePath); metadata.Add("excludePath", excludePath); metadata.Add("Exception", e.ToString()); metadata.Add("ErrorMessage", "Failed to migrate " + excludePath + " to " + alwaysExcludePath); this.tracer.RelatedError(metadata); this.FailMountAndExit("Error migrating " + excludePath + " to " + alwaysExcludePath + ", run 'gvfs log' for details"); } } }