示例#1
0
        private bool TryInitializeUpgrader()
        {
            OperatingSystem os_info = Environment.OSVersion;

            if (os_info.Platform == PlatformID.Win32NT)
            {
                if (this.upgrader == null)
                {
                    JsonTracer jsonTracer  = new JsonTracer(GVFSConstants.GVFSEtwProviderName, "UpgradeVerb");
                    string     logFilePath = GVFSEnlistment.GetNewGVFSLogFileName(
                        ProductUpgrader.GetLogDirectoryPath(),
                        GVFSConstants.LogFileTypes.UpgradeVerb);
                    jsonTracer.AddLogFileEventListener(logFilePath, EventLevel.Informational, Keywords.Any);

                    this.tracer        = jsonTracer;
                    this.prerunChecker = new InstallerPreRunChecker(this.tracer, this.Confirmed ? GVFSConstants.UpgradeVerbMessages.GVFSUpgradeConfirm : GVFSConstants.UpgradeVerbMessages.GVFSUpgrade);
                    this.upgrader      = new ProductUpgrader(ProcessHelper.GetCurrentProcessVersion(), this.tracer);
                }

                return(true);
            }
            else
            {
                this.ReportInfoToConsole($"ERROR: {GVFSConstants.UpgradeVerbMessages.GVFSUpgrade} in only supported on Microsoft Windows Operating System.");
                return(false);
            }
        }
示例#2
0
        private bool TryDownloadUpgrade(out string errorMessage)
        {
            using (ITracer activity = this.tracer.StartActivity("Checking for product upgrades.", EventLevel.Informational))
            {
                ProductUpgrader productUpgrader = new ProductUpgrader(ProcessHelper.GetCurrentProcessVersion(), this.tracer);
                Version         newerVersion    = null;
                string          detailedError   = null;
                if (!productUpgrader.TryGetNewerVersion(out newerVersion, out detailedError))
                {
                    errorMessage = "Could not fetch new version info. " + detailedError;
                    return(false);
                }

                if (newerVersion == null)
                {
                    // Already up-to-date
                    errorMessage = null;
                    return(true);
                }

                if (productUpgrader.TryDownloadNewestVersion(out detailedError))
                {
                    errorMessage = null;
                    return(true);
                }
                else
                {
                    errorMessage = "Could not download product upgrade. " + detailedError;
                    return(false);
                }
            }
        }
示例#3
0
        private bool TryInitialize(out string errorMessage)
        {
            if (this.upgrader == null)
            {
                string gitBinPath = GVFSPlatform.Instance.GitInstallation.GetInstalledGitBinPath();
                if (string.IsNullOrEmpty(gitBinPath))
                {
                    errorMessage = $"nameof(this.TryInitialize): Unable to locate git installation. Ensure git is installed and try again.";
                    return(false);
                }

                ICredentialStore credentialStore = new GitProcess(gitBinPath, workingDirectoryRoot: null, gvfsHooksRoot: null);

                ProductUpgrader upgrader;
                if (!ProductUpgrader.TryCreateUpgrader(this.tracer, this.fileSystem, new LocalGVFSConfig(), credentialStore, this.DryRun, this.NoVerify, out upgrader, out errorMessage))
                {
                    return(false);
                }

                // Configure the upgrader to have installer logs written to the same directory
                // as the upgrader.
                upgrader.UpgradeInstanceId = this.installationId;
                this.upgrader = upgrader;
            }

            errorMessage = null;
            return(true);
        }
示例#4
0
        private bool TryDownloadUpgrade(ProductUpgrader productUpgrader, out string errorMessage)
        {
            using (ITracer activity = this.tracer.StartActivity("Checking for product upgrades.", EventLevel.Informational))
            {
                Version newerVersion = null;
                string detailedError = null;
                if (!productUpgrader.TryGetNewerVersion(out newerVersion, out detailedError))
                {
                    errorMessage = "Could not fetch new version info. " + detailedError;
                    return false;
                }

                if (newerVersion == null)
                {
                    // Already up-to-date
                    // Make sure there a no asset installers remaining in the Downloads directory. This can happen if user
                    // upgraded by manually downloading and running asset installers.
                    productUpgrader.CleanupDownloadDirectory();
                    errorMessage = null;
                    return true;
                }

                if (productUpgrader.TryDownloadNewestVersion(out detailedError))
                {
                    errorMessage = null;
                    return true;
                }
                else
                {
                    errorMessage = "Could not download product upgrade. " + detailedError;
                    return false;
                }
            }
        }
示例#5
0
        private bool TryInitializeUpgrader()
        {
            if (GVFSPlatform.Instance.UnderConstruction.SupportsGVFSUpgrade)
            {
                if (this.upgrader == null)
                {
                    JsonTracer jsonTracer  = new JsonTracer(GVFSConstants.GVFSEtwProviderName, "UpgradeVerb");
                    string     logFilePath = GVFSEnlistment.GetNewGVFSLogFileName(
                        ProductUpgrader.GetLogDirectoryPath(),
                        GVFSConstants.LogFileTypes.UpgradeVerb);
                    jsonTracer.AddLogFileEventListener(logFilePath, EventLevel.Informational, Keywords.Any);

                    this.tracer        = jsonTracer;
                    this.prerunChecker = new InstallerPreRunChecker(this.tracer, this.Confirmed ? GVFSConstants.UpgradeVerbMessages.GVFSUpgradeConfirm : GVFSConstants.UpgradeVerbMessages.GVFSUpgrade);
                    this.upgrader      = new ProductUpgrader(ProcessHelper.GetCurrentProcessVersion(), this.tracer);
                }

                return(true);
            }
            else
            {
                this.ReportInfoToConsole($"ERROR: {GVFSConstants.UpgradeVerbMessages.GVFSUpgrade} is not supported on this operating system.");
                return(false);
            }
        }
示例#6
0
        private bool TryInitializeUpgrader(out string error)
        {
            if (this.DryRun && this.Confirmed)
            {
                error = $"{DryRunOption} and {ConfirmOption} arguments are not compatible.";
                return(false);
            }

            if (GVFSPlatform.Instance.UnderConstruction.SupportsGVFSUpgrade)
            {
                error = null;
                if (this.upgrader == null)
                {
                    this.productUpgraderPlatformStrategy = GVFSPlatform.Instance.CreateProductUpgraderPlatformInteractions(this.fileSystem, tracer: null);
                    if (!this.productUpgraderPlatformStrategy.TryPrepareLogDirectory(out error))
                    {
                        return(false);
                    }

                    JsonTracer jsonTracer  = new JsonTracer(GVFSConstants.GVFSEtwProviderName, "UpgradeVerb");
                    string     logFilePath = GVFSEnlistment.GetNewGVFSLogFileName(
                        ProductUpgraderInfo.GetLogDirectoryPath(),
                        GVFSConstants.LogFileTypes.UpgradeVerb);
                    jsonTracer.AddLogFileEventListener(logFilePath, EventLevel.Informational, Keywords.Any);

                    this.tracer        = jsonTracer;
                    this.prerunChecker = new InstallerPreRunChecker(this.tracer, this.Confirmed ? GVFSPlatform.Instance.Constants.UpgradeConfirmCommandMessage : GVFSConstants.UpgradeVerbMessages.GVFSUpgrade);

                    string gitBinPath = GVFSPlatform.Instance.GitInstallation.GetInstalledGitBinPath();
                    if (string.IsNullOrEmpty(gitBinPath))
                    {
                        error = $"nameof(this.TryInitializeUpgrader): Unable to locate git installation. Ensure git is installed and try again.";
                        return(false);
                    }

                    ICredentialStore credentialStore = new GitProcess(gitBinPath, workingDirectoryRoot: null);

                    ProductUpgrader upgrader;
                    if (ProductUpgrader.TryCreateUpgrader(this.tracer, this.fileSystem, new LocalGVFSConfig(), credentialStore, this.DryRun, this.NoVerify, out upgrader, out error))
                    {
                        this.upgrader = upgrader;
                    }
                    else
                    {
                        error = $"ERROR: {error}";
                    }
                }

                return(this.upgrader != null);
            }
            else
            {
                error = $"ERROR: {GVFSConstants.UpgradeVerbMessages.GVFSUpgrade} is not supported on this operating system.";
                return(false);
            }
        }
 public WindowsUpgradeOrchestrator(
     ProductUpgrader upgrader,
     ITracer tracer,
     PhysicalFileSystem fileSystem,
     InstallerPreRunChecker preRunChecker,
     TextReader input,
     TextWriter output)
     : base(upgrader, tracer, fileSystem, preRunChecker, input, output)
 {
 }
示例#8
0
        private bool TryInitializeUpgrader(out string error)
        {
            if (this.DryRun && this.Confirmed)
            {
                error = $"{DryRunOption} and {ConfirmOption} arguments are not compatible.";
                return(false);
            }

            if (GVFSPlatform.Instance.UnderConstruction.SupportsGVFSUpgrade)
            {
                error = null;
                if (this.upgrader == null)
                {
                    // Under normal circumstances ProductUpgraderInfo.GetLogDirectoryPath will have already been created by GVFS.Service.  If for some reason it
                    // does not (e.g. the service failed to start), we need to create ProductUpgraderInfo.GetLogDirectoryPath() explicity to ensure that
                    // it has the correct ACLs (so that both admin and non-admin users can create log files).
                    // If the logs directory does not already exist, this call could fail when running as a non-elevated user.
                    string createDirectoryError;
                    if (!this.fileSystem.TryCreateDirectoryWithAdminAndUserModifyPermissions(ProductUpgraderInfo.GetLogDirectoryPath(), out createDirectoryError))
                    {
                        error  = $"ERROR: Unable to create directory `{ProductUpgraderInfo.GetLogDirectoryPath()}`";
                        error += $"\n{createDirectoryError}";
                        error += $"\n\nTry running {GVFSConstants.UpgradeVerbMessages.GVFSUpgrade} from an elevated command prompt.";
                        return(false);
                    }

                    JsonTracer jsonTracer  = new JsonTracer(GVFSConstants.GVFSEtwProviderName, "UpgradeVerb");
                    string     logFilePath = GVFSEnlistment.GetNewGVFSLogFileName(
                        ProductUpgraderInfo.GetLogDirectoryPath(),
                        GVFSConstants.LogFileTypes.UpgradeVerb);
                    jsonTracer.AddLogFileEventListener(logFilePath, EventLevel.Informational, Keywords.Any);

                    this.tracer        = jsonTracer;
                    this.prerunChecker = new InstallerPreRunChecker(this.tracer, this.Confirmed ? GVFSConstants.UpgradeVerbMessages.GVFSUpgradeConfirm : GVFSConstants.UpgradeVerbMessages.GVFSUpgrade);

                    ProductUpgrader upgrader;
                    if (ProductUpgrader.TryCreateUpgrader(this.tracer, this.fileSystem, this.DryRun, this.NoVerify, out upgrader, out error))
                    {
                        this.upgrader = upgrader;
                    }
                    else
                    {
                        error = $"ERROR: {error}";
                    }
                }

                return(this.upgrader != null);
            }
            else
            {
                error = $"ERROR: {GVFSConstants.UpgradeVerbMessages.GVFSUpgrade} is not supported on this operating system.";
                return(false);
            }
        }
示例#9
0
 public UpgradeVerb(
     ProductUpgrader upgrader,
     ITracer tracer,
     InstallerPreRunChecker prerunChecker,
     ProcessLauncher processWrapper,
     TextWriter output)
 {
     this.upgrader        = upgrader;
     this.tracer          = tracer;
     this.prerunChecker   = prerunChecker;
     this.processLauncher = processWrapper;
     this.Output          = output;
 }
示例#10
0
        private static void RemindUpgradeAvailable()
        {
            // The idea is to generate a random number between 0 and 100. To make
            // sure that the reminder is displayed only 10% of the times a git
            // command is run, check that the random number is between 0 and 10,
            // which will have a probability of 10/100 == 10%.
            int reminderFrequency = 10;
            int randomValue       = random.Next(0, 100);

            if (randomValue <= reminderFrequency && ProductUpgrader.IsLocalUpgradeAvailable(GVFSHooksPlatform.GetInstallerExtension()))
            {
                Console.WriteLine(Environment.NewLine + GVFSConstants.UpgradeVerbMessages.ReminderNotification);
            }
        }
 public UpgradeOrchestrator(
     ProductUpgrader upgrader,
     ITracer tracer,
     InstallerPreRunChecker preRunChecker,
     TextReader input,
     TextWriter output)
 {
     this.upgrader      = upgrader;
     this.tracer        = tracer;
     this.preRunChecker = preRunChecker;
     this.output        = output;
     this.input         = input;
     this.mount         = false;
     this.ExitCode      = ReturnCode.Success;
 }
示例#12
0
 public UpgradeVerb(
     ProductUpgrader upgrader,
     ITracer tracer,
     PhysicalFileSystem fileSystem,
     InstallerPreRunChecker prerunChecker,
     ProcessLauncher processWrapper,
     TextWriter output)
 {
     this.upgrader        = upgrader;
     this.tracer          = tracer;
     this.fileSystem      = fileSystem;
     this.prerunChecker   = prerunChecker;
     this.processLauncher = processWrapper;
     this.Output          = output;
     this.productUpgraderPlatformStrategy = GVFSPlatform.Instance.CreateProductUpgraderPlatformInteractions(fileSystem, tracer);
 }
示例#13
0
        private bool TryQueryForNewerVersion(ITracer tracer, ProductUpgrader productUpgrader, out Version newVersion, out string errorMessage)
        {
            errorMessage = null;
            tracer.RelatedInfo($"Querying server for latest version...");

            if (!productUpgrader.TryQueryNewestVersion(out newVersion, out string detailedError))
            {
                errorMessage = "Could not fetch new version info. " + detailedError;
                return(false);
            }

            string logMessage = newVersion == null ? "No newer versions available." : $"Newer version available: {newVersion}.";

            tracer.RelatedInfo(logMessage);

            return(true);
        }
 public UpgradeOrchestrator(
     ProductUpgrader upgrader,
     ITracer tracer,
     PhysicalFileSystem fileSystem,
     InstallerPreRunChecker preRunChecker,
     TextReader input,
     TextWriter output)
 {
     this.upgrader       = upgrader;
     this.tracer         = tracer;
     this.fileSystem     = fileSystem;
     this.preRunChecker  = preRunChecker;
     this.output         = output;
     this.input          = input;
     this.ExitCode       = ReturnCode.Success;
     this.installationId = DateTime.Now.ToString("yyyyMMdd_HHmmss");
 }
示例#15
0
        private void TimerCallback(object unusedState)
        {
            string errorMessage = null;

            InstallerPreRunChecker prerunChecker = new InstallerPreRunChecker(this.tracer, string.Empty);
            ProductUpgrader productUpgrader = new ProductUpgrader(ProcessHelper.GetCurrentProcessVersion(), this.tracer);
            if (prerunChecker.TryRunPreUpgradeChecks(out string _) && this.TryDownloadUpgrade(productUpgrader, out errorMessage))
            {
                return;
            }

            productUpgrader.CleanupDownloadDirectory();

            if (errorMessage != null)
            {
                this.tracer.RelatedError(errorMessage);
            }
        }
示例#16
0
        private bool TryInitialize(out string errorMessage)
        {
            if (this.upgrader == null)
            {
                ProductUpgrader upgrader;
                if (!ProductUpgrader.TryCreateUpgrader(this.tracer, this.fileSystem, this.DryRun, this.NoVerify, out upgrader, out errorMessage))
                {
                    return(false);
                }

                // Configure the upgrader to have installer logs written to the same directory
                // as the upgrader.
                upgrader.UpgradeInstanceId = this.installationId;
                this.upgrader = upgrader;
            }

            errorMessage = null;
            return(true);
        }
        public void FailsWithDefaultConfiguration()
        {
            MockLocalScalarConfig scalarConfig = this.ConstructDefaultConfigBuilder()
                                                 .Build();

            bool success = ProductUpgrader.TryCreateUpgrader(
                this.tracer,
                this.fileSystemMock.Object,
                scalarConfig,
                this.credentialStoreMock.Object,
                false,
                false,
                out ProductUpgrader productUpgrader,
                out string error);

            success.ShouldBeFalse();
            productUpgrader.ShouldBeNull();
            error.ShouldNotBeNull();
        }
        public void CreatesGitHubUpgraderWhenConfigured()
        {
            MockLocalGSDConfig gvfsConfig = this.ConstructDefaultGitHubConfigBuilder()
                                            .Build();

            bool success = ProductUpgrader.TryCreateUpgrader(
                this.tracer,
                this.fileSystemMock.Object,
                gvfsConfig,
                this.credentialStoreMock.Object,
                false,
                false,
                out ProductUpgrader productUpgrader,
                out string error);

            success.ShouldBeTrue();
            productUpgrader.ShouldNotBeNull();
            productUpgrader.ShouldBeOfType <GitHubUpgrader>();
            error.ShouldBeNull();
        }
        public void NoUpgraderWhenNuGetPackNameMissing()
        {
            MockLocalGSDConfig gvfsConfig = this.ConstructDefaultMockNuGetConfigBuilder()
                                            .WithNoUpgradeFeedPackageName()
                                            .Build();

            bool success = ProductUpgrader.TryCreateUpgrader(
                this.tracer,
                this.fileSystemMock.Object,
                gvfsConfig,
                this.credentialStoreMock.Object,
                false,
                false,
                out ProductUpgrader productUpgrader,
                out string error);

            success.ShouldBeFalse();
            productUpgrader.ShouldBeNull();
            error.ShouldNotBeNull();
        }
        public void CreatesOrgNuGetUpgrader()
        {
            MockLocalScalarConfig scalarConfig = this.ConstructDefaultMockOrgNuGetConfigBuilder()
                                                 .Build();

            bool success = ProductUpgrader.TryCreateUpgrader(
                this.tracer,
                this.fileSystemMock.Object,
                scalarConfig,
                this.credentialStoreMock.Object,
                false,
                false,
                out ProductUpgrader productUpgrader,
                out string error);

            success.ShouldBeTrue();
            productUpgrader.ShouldNotBeNull();
            productUpgrader.ShouldBeOfType <OrgNuGetUpgrader>();
            error.ShouldBeNull();
        }
        public UpgradeOrchestrator()
        {
            string logFilePath = GVFSEnlistment.GetNewGVFSLogFileName(
                ProductUpgrader.GetLogDirectoryPath(),
                GVFSConstants.LogFileTypes.UpgradeProcess);
            JsonTracer jsonTracer = new JsonTracer(GVFSConstants.GVFSEtwProviderName, "UpgradeProcess");

            jsonTracer.AddLogFileEventListener(
                logFilePath,
                DefaultEventLevel,
                Keywords.Any);

            this.tracer        = jsonTracer;
            this.preRunChecker = new InstallerPreRunChecker(this.tracer, GVFSConstants.UpgradeVerbMessages.GVFSUpgradeConfirm);
            this.upgrader      = new ProductUpgrader(ProcessHelper.GetCurrentProcessVersion(), this.tracer);
            this.output        = Console.Out;
            this.input         = Console.In;
            this.mount         = false;
            this.ExitCode      = ReturnCode.Success;
        }
        public void NoOrgUpgraderWhenNuGetFeedMissing()
        {
            MockLocalScalarConfig scalarConfig = this.ConstructDefaultMockOrgNuGetConfigBuilder()
                                                 .WithNoUpgradeFeedUrl()
                                                 .Build();

            bool success = ProductUpgrader.TryCreateUpgrader(
                this.tracer,
                this.fileSystemMock.Object,
                scalarConfig,
                this.credentialStoreMock.Object,
                false,
                false,
                out ProductUpgrader productUpgrader,
                out string error);

            success.ShouldBeFalse();
            productUpgrader.ShouldBeNull();
            error.ShouldNotBeNull();
        }
示例#23
0
        private bool TryInitializeUpgrader(out string error)
        {
            if (this.DryRun && this.Confirmed)
            {
                error = $"{DryRunOption} and {ConfirmOption} arguments are not compatible.";
                return(false);
            }

            if (GVFSPlatform.Instance.UnderConstruction.SupportsGVFSUpgrade)
            {
                error = null;
                if (this.upgrader == null)
                {
                    JsonTracer jsonTracer  = new JsonTracer(GVFSConstants.GVFSEtwProviderName, "UpgradeVerb");
                    string     logFilePath = GVFSEnlistment.GetNewGVFSLogFileName(
                        ProductUpgraderInfo.GetLogDirectoryPath(),
                        GVFSConstants.LogFileTypes.UpgradeVerb);
                    jsonTracer.AddLogFileEventListener(logFilePath, EventLevel.Informational, Keywords.Any);

                    this.tracer        = jsonTracer;
                    this.prerunChecker = new InstallerPreRunChecker(this.tracer, this.Confirmed ? GVFSConstants.UpgradeVerbMessages.GVFSUpgradeConfirm : GVFSConstants.UpgradeVerbMessages.GVFSUpgrade);

                    ProductUpgrader upgrader;
                    if (ProductUpgrader.TryCreateUpgrader(this.tracer, this.fileSystem, this.DryRun, this.NoVerify, out upgrader, out error))
                    {
                        this.upgrader = upgrader;
                    }
                    else
                    {
                        error = $"ERROR: {error}";
                    }
                }

                return(this.upgrader != null);
            }
            else
            {
                error = $"ERROR: {GVFSConstants.UpgradeVerbMessages.GVFSUpgrade} is not supported on this operating system.";
                return(false);
            }
        }
示例#24
0
        protected override void Execute(GVFSEnlistment enlistment)
        {
            string diagnosticsRoot = Path.Combine(enlistment.DotGVFSRoot, "diagnostics");

            if (!Directory.Exists(diagnosticsRoot))
            {
                Directory.CreateDirectory(diagnosticsRoot);
            }

            string archiveFolderPath = Path.Combine(diagnosticsRoot, "gvfs_" + DateTime.Now.ToString("yyyyMMdd_HHmmss"));

            Directory.CreateDirectory(archiveFolderPath);

            using (FileStream diagnosticLogFile = new FileStream(Path.Combine(archiveFolderPath, "diagnostics.log"), FileMode.CreateNew))
                using (this.diagnosticLogFileWriter = new StreamWriter(diagnosticLogFile))
                {
                    this.WriteMessage("Collecting diagnostic info into temp folder " + archiveFolderPath);

                    this.WriteMessage(string.Empty);
                    this.WriteMessage("gvfs version " + ProcessHelper.GetCurrentProcessVersion());

                    GitVersion gitVersion = null;
                    string     error      = null;
                    if (!string.IsNullOrEmpty(enlistment.GitBinPath) && GitProcess.TryGetVersion(enlistment.GitBinPath, out gitVersion, out error))
                    {
                        this.WriteMessage("git version " + gitVersion.ToString());
                    }
                    else
                    {
                        this.WriteMessage("Could not determine git version. " + error);
                    }

                    this.WriteMessage(enlistment.GitBinPath);
                    this.WriteMessage(string.Empty);
                    this.WriteMessage("Enlistment root: " + enlistment.EnlistmentRoot);
                    this.WriteMessage("Cache Server: " + CacheServerResolver.GetCacheServerFromConfig(enlistment));

                    string localCacheRoot;
                    string gitObjectsRoot;
                    this.GetLocalCachePaths(enlistment, out localCacheRoot, out gitObjectsRoot);
                    string actualLocalCacheRoot = !string.IsNullOrWhiteSpace(localCacheRoot) ? localCacheRoot : gitObjectsRoot;
                    this.WriteMessage("Local Cache: " + actualLocalCacheRoot);
                    this.WriteMessage(string.Empty);

                    this.PrintDiskSpaceInfo(actualLocalCacheRoot, this.EnlistmentRootPathParameter);

                    this.RecordVersionInformation();

                    this.ShowStatusWhileRunning(
                        () =>
                        this.RunAndRecordGVFSVerb <StatusVerb>(archiveFolderPath, "gvfs_status.txt") != ReturnCode.Success ||
                        this.RunAndRecordGVFSVerb <UnmountVerb>(archiveFolderPath, "gvfs_unmount.txt", verb => verb.SkipLock = true) == ReturnCode.Success,
                        "Unmounting",
                        suppressGvfsLogMessage: true);

                    this.ShowStatusWhileRunning(
                        () =>
                    {
                        // .gvfs
                        this.CopyAllFiles(enlistment.EnlistmentRoot, archiveFolderPath, GVFSConstants.DotGVFS.Root, copySubFolders: false);

                        if (GVFSPlatform.Instance.UnderConstruction.SupportsKernelLogs)
                        {
                            // driver
                            this.FlushKernelDriverLogs();
                            string kernelLogsFolderPath = GVFSPlatform.Instance.KernelDriver.LogsFolderPath;

                            // This copy sometimes fails because the OS has an exclusive lock on the etl files. The error is not actionable
                            // for the user so we don't write the error message to stdout, just to our own log file.
                            this.CopyAllFiles(Path.GetDirectoryName(kernelLogsFolderPath), archiveFolderPath, Path.GetFileName(kernelLogsFolderPath), copySubFolders: false, hideErrorsFromStdout: true);
                        }

                        // .git
                        this.CopyAllFiles(enlistment.WorkingDirectoryRoot, archiveFolderPath, GVFSConstants.DotGit.Root, copySubFolders: false);
                        this.CopyAllFiles(enlistment.WorkingDirectoryRoot, archiveFolderPath, GVFSConstants.DotGit.Hooks.Root, copySubFolders: false);
                        this.CopyAllFiles(enlistment.WorkingDirectoryRoot, archiveFolderPath, GVFSConstants.DotGit.Info.Root, copySubFolders: false);
                        this.CopyAllFiles(enlistment.WorkingDirectoryRoot, archiveFolderPath, GVFSConstants.DotGit.Logs.Root, copySubFolders: true);
                        this.CopyAllFiles(enlistment.WorkingDirectoryRoot, archiveFolderPath, GVFSConstants.DotGit.Refs.Root, copySubFolders: true);
                        this.CopyAllFiles(enlistment.WorkingDirectoryRoot, archiveFolderPath, GVFSConstants.DotGit.Objects.Info.Root, copySubFolders: false);
                        this.LogDirectoryEnumeration(enlistment.WorkingDirectoryRoot, Path.Combine(archiveFolderPath, GVFSConstants.DotGit.Objects.Root), GVFSConstants.DotGit.Objects.Pack.Root, "packs-local.txt");
                        this.LogLooseObjectCount(enlistment.WorkingDirectoryRoot, Path.Combine(archiveFolderPath, GVFSConstants.DotGit.Objects.Root), GVFSConstants.DotGit.Objects.Root, "objects-local.txt");

                        // databases
                        this.CopyAllFiles(enlistment.DotGVFSRoot, Path.Combine(archiveFolderPath, GVFSConstants.DotGVFS.Root), GVFSConstants.DotGVFS.Databases.Name, copySubFolders: false);

                        // local cache
                        this.CopyLocalCacheData(archiveFolderPath, localCacheRoot, gitObjectsRoot);

                        // corrupt objects
                        this.CopyAllFiles(enlistment.DotGVFSRoot, Path.Combine(archiveFolderPath, GVFSConstants.DotGVFS.Root), GVFSConstants.DotGVFS.CorruptObjectsName, copySubFolders: false);

                        if (GVFSPlatform.Instance.UnderConstruction.SupportsGVFSService)
                        {
                            // service
                            this.CopyAllFiles(
                                Paths.GetServiceDataRoot(string.Empty),
                                archiveFolderPath,
                                this.ServiceName,
                                copySubFolders: true);
                        }

                        if (GVFSPlatform.Instance.UnderConstruction.SupportsGVFSUpgrade)
                        {
                            // upgrader
                            this.CopyAllFiles(
                                ProductUpgrader.GetUpgradesDirectoryPath(),
                                archiveFolderPath,
                                ProductUpgrader.LogDirectory,
                                copySubFolders: true,
                                targetFolderName: ProductUpgrader.UpgradeDirectoryName);
                            this.LogDirectoryEnumeration(
                                ProductUpgrader.GetUpgradesDirectoryPath(),
                                Path.Combine(archiveFolderPath, ProductUpgrader.UpgradeDirectoryName),
                                ProductUpgrader.DownloadDirectory,
                                "downloaded-assets.txt");
                        }

                        return(true);
                    },
                        "Copying logs");

                    this.ShowStatusWhileRunning(
                        () => this.RunAndRecordGVFSVerb <MountVerb>(archiveFolderPath, "gvfs_mount.txt") == ReturnCode.Success,
                        "Mounting",
                        suppressGvfsLogMessage: true);

                    this.CopyAllFiles(enlistment.DotGVFSRoot, Path.Combine(archiveFolderPath, GVFSConstants.DotGVFS.Root), "logs", copySubFolders: false);
                }

            string zipFilePath = archiveFolderPath + ".zip";

            this.ShowStatusWhileRunning(
                () =>
            {
                ZipFile.CreateFromDirectory(archiveFolderPath, zipFilePath);
                PhysicalFileSystem.RecursiveDelete(archiveFolderPath);

                return(true);
            },
                "Creating zip file",
                suppressGvfsLogMessage: true);

            this.Output.WriteLine();
            this.Output.WriteLine("Diagnostics complete. All of the gathered info, as well as all of the output above, is captured in");
            this.Output.WriteLine(zipFilePath);
        }
        private void TimerCallback(object unusedState)
        {
            string errorMessage = null;

            using (ITracer activity = this.tracer.StartActivity("Checking for product upgrades.", EventLevel.Informational))
            {
                try
                {
                    ProductUpgraderInfo info = new ProductUpgraderInfo(
                        this.tracer,
                        this.fileSystem);

                    ProductUpgrader.TryCreateUpgrader(
                        this.tracer,
                        this.fileSystem,
                        new LocalScalarConfig(),
                        credentialStore: null,
                        dryRun: false,
                        noVerify: false,
                        newUpgrader: out ProductUpgrader productUpgrader,
                        error: out errorMessage);

                    if (productUpgrader == null)
                    {
                        string message = string.Format(
                            "{0}.{1}: failed to create upgrader: {2}",
                            nameof(ProductUpgradeTimer),
                            nameof(this.TimerCallback),
                            errorMessage);

                        activity.RelatedWarning(
                            metadata: new EventMetadata(),
                            message: message,
                            keywords: Keywords.Telemetry);

                        info.RecordHighestAvailableVersion(highestAvailableVersion: null);
                        return;
                    }

                    InstallerPreRunChecker prerunChecker = new InstallerPreRunChecker(this.tracer, string.Empty);
                    if (!prerunChecker.TryRunPreUpgradeChecks(out errorMessage))
                    {
                        string message = string.Format(
                            "{0}.{1}: PreUpgradeChecks failed with: {2}",
                            nameof(ProductUpgradeTimer),
                            nameof(this.TimerCallback),
                            errorMessage);

                        activity.RelatedWarning(
                            metadata: new EventMetadata(),
                            message: message,
                            keywords: Keywords.Telemetry);

                        info.RecordHighestAvailableVersion(highestAvailableVersion: null);
                        return;
                    }

                    if (!productUpgrader.UpgradeAllowed(out errorMessage))
                    {
                        errorMessage = errorMessage ??
                                       $"{nameof(ProductUpgradeTimer)}.{nameof(this.TimerCallback)}: Upgrade is not allowed, but no reason provided.";
                        activity.RelatedWarning(
                            metadata: new EventMetadata(),
                            message: errorMessage,
                            keywords: Keywords.Telemetry);

                        info.RecordHighestAvailableVersion(highestAvailableVersion: null);
                        return;
                    }

                    if (!this.TryQueryForNewerVersion(
                            activity,
                            productUpgrader,
                            out Version newerVersion,
                            out errorMessage))
                    {
                        string message = string.Format(
                            "{0}.{1}: TryQueryForNewerVersion failed with: {2}",
                            nameof(ProductUpgradeTimer),
                            nameof(this.TimerCallback),
                            errorMessage);

                        activity.RelatedWarning(
                            metadata: new EventMetadata(),
                            message: message,
                            keywords: Keywords.Telemetry);

                        info.RecordHighestAvailableVersion(highestAvailableVersion: null);
                        return;
                    }

                    info.RecordHighestAvailableVersion(highestAvailableVersion: newerVersion);

                    this.DisplayUpgradeAvailableToast(newerVersion.ToString());
                }
                catch (Exception ex)
                {
                    this.tracer.RelatedWarning(
                        CreateEventMetadata(ex),
                        "Exception encountered recording highest available version");
                }
            }
        }
示例#26
0
        private void TimerCallback(object unusedState)
        {
            string errorMessage = null;

            using (ITracer activity = this.tracer.StartActivity("Checking for product upgrades.", EventLevel.Informational))
            {
                try
                {
                    ProductUpgraderInfo info = new ProductUpgraderInfo(
                        this.tracer,
                        this.fileSystem);

                    ProductUpgrader.TryCreateUpgrader(
                        this.tracer,
                        this.fileSystem,
                        new LocalScalarConfig(),
                        credentialStore: null,
                        dryRun: false,
                        noVerify: false,
                        newUpgrader: out ProductUpgrader productUpgrader,
                        error: out errorMessage);

                    if (productUpgrader == null)
                    {
                        string message = string.Format(
                            "{0}.{1}: failed to create upgrader: {2}",
                            nameof(ProductUpgradeTimer),
                            nameof(this.TimerCallback),
                            errorMessage);

                        activity.RelatedWarning(
                            metadata: new EventMetadata(),
                            message: message,
                            keywords: Keywords.Telemetry);

                        info.RecordHighestAvailableVersion(highestAvailableVersion: null);
                        return;
                    }

                    if (!productUpgrader.SupportsAnonymousVersionQuery)
                    {
                        // If this is a NuGetUpgrader that does not support anonymous version query,
                        // fall back to using the GitHubUpgrader, to preserve existing behavior.
                        // Once we have completely transitioned to using the anonymous endpoint,
                        // we can remove this code.
                        if (productUpgrader is NuGetUpgrader)
                        {
                            productUpgrader = GitHubUpgrader.Create(
                                this.tracer,
                                this.fileSystem,
                                new LocalScalarConfig(),
                                dryRun: false,
                                noVerify: false,
                                error: out errorMessage);

                            if (productUpgrader == null)
                            {
                                string gitHubUpgraderFailedMessage = string.Format(
                                    "{0}.{1}: GitHubUpgrader.Create failed to create upgrader: {2}",
                                    nameof(ProductUpgradeTimer),
                                    nameof(this.TimerCallback),
                                    errorMessage);

                                activity.RelatedWarning(
                                    metadata: new EventMetadata(),
                                    message: gitHubUpgraderFailedMessage,
                                    keywords: Keywords.Telemetry);

                                info.RecordHighestAvailableVersion(highestAvailableVersion: null);
                                return;
                            }
                        }
                        else
                        {
                            errorMessage = string.Format(
                                "{0}.{1}: Configured Product Upgrader does not support anonymous version queries.",
                                nameof(ProductUpgradeTimer),
                                nameof(this.TimerCallback),
                                errorMessage);

                            activity.RelatedWarning(
                                metadata: new EventMetadata(),
                                message: errorMessage,
                                keywords: Keywords.Telemetry);

                            info.RecordHighestAvailableVersion(highestAvailableVersion: null);
                            return;
                        }
                    }

                    InstallerPreRunChecker prerunChecker = new InstallerPreRunChecker(this.tracer, string.Empty);
                    if (!prerunChecker.TryRunPreUpgradeChecks(out errorMessage))
                    {
                        string message = string.Format(
                            "{0}.{1}: PreUpgradeChecks failed with: {2}",
                            nameof(ProductUpgradeTimer),
                            nameof(this.TimerCallback),
                            errorMessage);

                        activity.RelatedWarning(
                            metadata: new EventMetadata(),
                            message: message,
                            keywords: Keywords.Telemetry);

                        info.RecordHighestAvailableVersion(highestAvailableVersion: null);
                        return;
                    }

                    if (!productUpgrader.UpgradeAllowed(out errorMessage))
                    {
                        errorMessage = errorMessage ??
                                       $"{nameof(ProductUpgradeTimer)}.{nameof(this.TimerCallback)}: Upgrade is not allowed, but no reason provided.";
                        activity.RelatedWarning(
                            metadata: new EventMetadata(),
                            message: errorMessage,
                            keywords: Keywords.Telemetry);

                        info.RecordHighestAvailableVersion(highestAvailableVersion: null);
                        return;
                    }

                    if (!this.TryQueryForNewerVersion(
                            activity,
                            productUpgrader,
                            out Version newerVersion,
                            out errorMessage))
                    {
                        string message = string.Format(
                            "{0}.{1}: TryQueryForNewerVersion failed with: {2}",
                            nameof(ProductUpgradeTimer),
                            nameof(this.TimerCallback),
                            errorMessage);

                        activity.RelatedWarning(
                            metadata: new EventMetadata(),
                            message: message,
                            keywords: Keywords.Telemetry);

                        info.RecordHighestAvailableVersion(highestAvailableVersion: null);
                        return;
                    }

                    info.RecordHighestAvailableVersion(highestAvailableVersion: newerVersion);

                    this.DisplayUpgradeAvailableToast(newerVersion.ToString());
                }
                catch (Exception ex) when(
                    ex is IOException ||
                    ex is UnauthorizedAccessException ||
                    ex is NotSupportedException)
                {
                    this.tracer.RelatedWarning(
                        CreateEventMetadata(ex),
                        "Exception encountered recording highest available version");
                }
                catch (Exception ex)
                {
                    this.tracer.RelatedError(
                        CreateEventMetadata(ex),
                        "Unhanlded exception encountered recording highest available version");
                    Environment.Exit((int)ReturnCode.GenericError);
                }
            }
        }