From 53f00adedd011df7a56f2d2142c91c716ae0807b Mon Sep 17 00:00:00 2001 From: Jameson Miller Date: Mon, 20 Aug 2018 16:05:47 -0400 Subject: [PATCH] Update name of file created by installer to indicate installation version Update name of file that GVFS installer creates when an on disk version 16 capable installation is first installed. (cherry picked from commit 120eeba149a78de3ed616dc5db3e11efc974b48a) --- GVFS/GVFS.Common/GVFSConstants.cs | 5 +++ GVFS/GVFS.Installer/Setup.iss | 14 ++++---- GVFS/GVFS.Service/GvfsService.cs | 53 ++++++++++++++----------------- 3 files changed, 35 insertions(+), 37 deletions(-) diff --git a/GVFS/GVFS.Common/GVFSConstants.cs b/GVFS/GVFS.Common/GVFSConstants.cs index f498773f1..ece894ef8 100644 --- a/GVFS/GVFS.Common/GVFSConstants.cs +++ b/GVFS/GVFS.Common/GVFSConstants.cs @@ -192,6 +192,11 @@ public static class Heads } } + public static class InstallationCapabilityFiles + { + public const string OnDiskVersion16CapableInstallation = "OnDiskVersion16CapableInstallation.dat"; + } + public static class VerbParameters { public static class Mount diff --git a/GVFS/GVFS.Installer/Setup.iss b/GVFS/GVFS.Installer/Setup.iss index 36bff4d3c..f2875b699 100644 --- a/GVFS/GVFS.Installer/Setup.iss +++ b/GVFS/GVFS.Installer/Setup.iss @@ -283,15 +283,15 @@ begin end; end; -procedure WriteGitStatusCacheAvailableFile(); +procedure WriteOnDiskVersion16CapableFile(); var - TokenFilePath: string; + FilePath: string; begin - TokenFilePath := ExpandConstant('{app}\GitStatusCacheAvailable'); - if not FileExists(TokenFilePath) then + FilePath := ExpandConstant('{app}\OnDiskVersion16CapableInstallation.dat'); + if not FileExists(FilePath) then begin - Log('WritingGitStatusCacheAvailableFile: Writing file ' + TokenFilePath); - SaveStringToFile(TokenFilePath, '', False); + Log('WriteOnDiskVersion16CapableFile: Writing file ' + FilePath); + SaveStringToFile(FilePath, '', False); end end; @@ -319,7 +319,7 @@ begin end; end; - WriteGitStatusCacheAvailableFile(); + WriteOnDiskVersion16CapableFile(); finally WizardForm.StatusLabel.Caption := StatusText; WizardForm.ProgressGauge.Style := npbstNormal; diff --git a/GVFS/GVFS.Service/GvfsService.cs b/GVFS/GVFS.Service/GvfsService.cs index bacab0457..0134cd244 100644 --- a/GVFS/GVFS.Service/GvfsService.cs +++ b/GVFS/GVFS.Service/GvfsService.cs @@ -287,28 +287,37 @@ private void CheckEnableGitStatusCacheTokenFile() try { string statusCacheVersionTokenPath = Path.Combine(Paths.GetServiceDataRoot(GVFSConstants.Service.ServiceName), GVFSConstants.GitStatusCache.EnableGitStatusCacheTokenFile); - - if (!File.Exists(statusCacheVersionTokenPath)) + if (File.Exists(statusCacheVersionTokenPath)) { - DateTime lastRebootTime = NativeMethods.GetLastRebootTime(); + this.tracer.RelatedInfo($"CheckEnableGitStatusCache: EnableGitStatusCacheToken file already exists at {statusCacheVersionTokenPath}."); + return; + } + + DateTime lastRebootTime = NativeMethods.GetLastRebootTime(); + + // GitStatusCache was included with GVFS on disk version 16. The 1st time GVFS that is at or above on disk version + // is installed, it will write out a file indicating that the installation is "OnDiskVersion16Capable". + // We can query the properties of this file to get the installation time, and compare this with the last reboot time for + // this machine. + string fileToCheck = Path.Combine(Configuration.AssemblyPath, GVFSConstants.InstallationCapabilityFiles.OnDiskVersion16CapableInstallation); - // When a version of GVFS that supports the GitStatusCache is installed, it will create - // the following file. By checking the time the file was created, we know when that - // version of GVFS was installed. - string fileToCheck = Path.Combine(Configuration.AssemblyPath, "GitStatusCacheAvailable"); - if (File.Exists(fileToCheck)) + if (File.Exists(fileToCheck)) + { + DateTime installTime = File.GetCreationTime(fileToCheck); + if (lastRebootTime > installTime) { - DateTime installTime = File.GetCreationTime(fileToCheck); - if (lastRebootTime > installTime) - { - File.WriteAllText(statusCacheVersionTokenPath, string.Empty); - } + this.tracer.RelatedInfo($"CheckEnableGitStatusCache: Writing out EnableGitStatusCacheToken file. GVFS installation time: {installTime}, last Reboot time: {lastRebootTime}."); + File.WriteAllText(statusCacheVersionTokenPath, string.Empty); } else { - this.tracer.RelatedError($"Unable to determine GVFS installation time: {fileToCheck} does not exist."); + this.tracer.RelatedInfo($"CheckEnableGitStatusCache: Not writing EnableGitStatusCacheToken file - machine has not been rebooted since OnDiskVersion16Capable installation. GVFS installation time: {installTime}, last reboot time: {lastRebootTime}"); } } + else + { + this.tracer.RelatedError($"Unable to determine GVFS installation time: {fileToCheck} does not exist."); + } } catch (Exception ex) { @@ -318,22 +327,6 @@ private void CheckEnableGitStatusCacheTokenFile() } } - private bool TryGetGVFSInstallTime(out DateTime installTime) - { - installTime = DateTime.Now; - - // Get the time of a file that was created by the GVFS installer (for a version of GVFS that supports the - // GitStatusCache). The expected path is written by the installer. - string fileToCheck = Path.Combine(Configuration.AssemblyPath, "GitStatusCacheAvailable"); - if (File.Exists(fileToCheck)) - { - installTime = File.GetCreationTime(fileToCheck); - return true; - } - - return false; - } - private void LogExceptionAndExit(Exception e, string method) { EventMetadata metadata = new EventMetadata();