Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions GVFS/GVFS.Common/GVFSConstants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 7 additions & 7 deletions GVFS/GVFS.Installer/Setup.iss
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -319,7 +319,7 @@ begin
end;
end;

WriteGitStatusCacheAvailableFile();
WriteOnDiskVersion16CapableFile();
finally
WizardForm.StatusLabel.Caption := StatusText;
WizardForm.ProgressGauge.Style := npbstNormal;
Expand Down
53 changes: 23 additions & 30 deletions GVFS/GVFS.Service/GvfsService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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();
Expand Down