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();