Skip to content

Commit

Permalink
VFSForGit reminds of updates when there is none
Browse files Browse the repository at this point in the history
1. GVFS.Service does its periodic upgrade check. When it finds that the current version is up-to-date, it deletes the previously downloaded releases. In between the user may see reminder messaging while running git commands.
2. User manually runs `gvfs upgrade`. When gvfs cli finds that the current version is up-to-date it deletes the un-needed release downloads. User would no longer see reminders.

Fixes #502
  • Loading branch information
alameenshah committed Nov 26, 2018
1 parent fda95db commit cb19b42
Show file tree
Hide file tree
Showing 4 changed files with 105 additions and 23 deletions.
12 changes: 12 additions & 0 deletions GVFS/GVFS.Common/ProductUpgrader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,18 @@ public virtual bool TryLoadRingConfig(out string error)
return false;
}

public void DeletePreviousDownloads()
{
try
{
this.fileSystem.DeleteDirectory(GetAssetDownloadsPath());
}
catch (Exception ex)
{
this.TraceException(ex, nameof(this.DeletePreviousDownloads), $"Could not remove directory: {GetAssetDownloadsPath()}");
}
}

protected virtual bool TryDeleteDownloadedAsset(Asset asset, out Exception exception)
{
return this.fileSystem.TryDeleteFile(asset.LocalPath, out exception);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System;
using System.IO;
using System.Linq;
using System.Threading;

namespace GVFS.FunctionalTests.Tests.EnlistmentPerFixture
{
Expand All @@ -16,6 +17,8 @@ public class UpgradeReminderTests : TestsWithEnlistmentPerFixture
{
private const string GVFSInstallerName = "VFSForGit.1.0.18234.1.exe";
private const string GitInstallerName = "Git-2.17.1.gvfs.2.5.g2962052-64-bit.exe";
private const string UpgradeRingKey = "upgrade.ring";
private const string AlwaysUpToDateRing = "None";

private string upgradeDirectory;
private FileSystemRunner fileSystem;
Expand Down Expand Up @@ -49,30 +52,17 @@ public void NoReminderWhenUpgradeNotAvailable()
public void RemindWhenUpgradeAvailable()
{
this.CreateUpgradeInstallers();

string errors = string.Empty;
for (int count = 0; count < 50; count++)
{
ProcessResult result = GitHelpers.InvokeGitAgainstGVFSRepo(
this.Enlistment.RepoRoot,
"status",
removeWaitingMessages: true,
removeUpgradeMessages: false);

if (!string.IsNullOrEmpty(result.Errors))
{
errors += result.Errors;
}
}

errors.ShouldContain(new string[]
{
"A new version of GVFS is available."
});

this.ReminderMessagingEnabled().ShouldBeTrue();
this.EmptyDownloadDirectory();
}

[TestCase]
public void NoReminderForLeftOverDownloads()
{
this.VerifyServiceRestartStopsReminder();
this.VerifyUpgradeVerbStopsReminder();
}

private void EmptyDownloadDirectory()
{
if (Directory.Exists(this.upgradeDirectory))
Expand All @@ -97,5 +87,77 @@ private void CreateUpgradeInstallers()
this.fileSystem.FileExists(gvfsInstallerPath).ShouldBeTrue();
this.fileSystem.FileExists(gitInstallerPath).ShouldBeTrue();
}

private void SetUpgradeRing(string value)
{
this.RunGVFS($"config {UpgradeRingKey} {value}");
}

private string RunUpgradeCommand()
{
return this.RunGVFS("upgrade");
}

private string RunGVFS(string argument)
{
ProcessResult result = ProcessHelper.Run(GVFSTestConfig.PathToGVFS, argument);
result.ExitCode.ShouldEqual(0, result.Errors);

return result.Output;
}

private void RestartService()
{
GVFSServiceProcess.StopService();
GVFSServiceProcess.StartService();
}

private bool ReminderMessagingEnabled()
{
for (int count = 0; count < 50; count++)
{
ProcessResult result = GitHelpers.InvokeGitAgainstGVFSRepo(
this.Enlistment.RepoRoot,
"status",
removeWaitingMessages:true,
removeUpgradeMessages:false);

if (!string.IsNullOrEmpty(result.Errors) &&
result.Errors.Contains("A new version of GVFS is available."))
{
return true;
}
}

return false;
}

private void VerifyServiceRestartStopsReminder()
{
this.CreateUpgradeInstallers();
this.ReminderMessagingEnabled().ShouldBeTrue();
this.SetUpgradeRing(AlwaysUpToDateRing);
this.RestartService();

// Wait for sometime so service can detect product is up-to-date and delete left over downloads
TimeSpan timeToWait = TimeSpan.FromMinutes(1);
bool reminderMessagingEnabled = true;
while ((reminderMessagingEnabled = this.ReminderMessagingEnabled()) && timeToWait > TimeSpan.Zero)
{
Thread.Sleep(TimeSpan.FromSeconds(5));
timeToWait = timeToWait.Subtract(TimeSpan.FromSeconds(5));
}

reminderMessagingEnabled.ShouldBeFalse();
}

private void VerifyUpgradeVerbStopsReminder()
{
this.SetUpgradeRing(AlwaysUpToDateRing);
this.CreateUpgradeInstallers();
this.ReminderMessagingEnabled().ShouldBeTrue();
this.RunUpgradeCommand();
this.ReminderMessagingEnabled().ShouldBeFalse();
}
}
}
}
3 changes: 3 additions & 0 deletions GVFS/GVFS.Service/ProductUpgradeTimer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ private bool TryDownloadUpgrade(out string errorMessage)
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.DeletePreviousDownloads();
errorMessage = null;
return true;
}
Expand Down
7 changes: 6 additions & 1 deletion GVFS/GVFS/CommandLine/UpgradeVerb.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ private bool TryRunProductUpgrade()
this.tracer.RelatedInfo($"{nameof(this.TryRunProductUpgrade)}: {GVFSConstants.UpgradeVerbMessages.NoneRingConsoleAlert}");
this.ReportInfoToConsole(ring == ProductUpgrader.RingType.None ? GVFSConstants.UpgradeVerbMessages.NoneRingConsoleAlert : GVFSConstants.UpgradeVerbMessages.NoRingConfigConsoleAlert);
this.ReportInfoToConsole(GVFSConstants.UpgradeVerbMessages.SetUpgradeRingCommand);
this.upgrader.DeletePreviousDownloads();
return true;
}

Expand All @@ -128,9 +129,13 @@ private bool TryRunProductUpgrade()
if (newestVersion == null)
{
this.ReportInfoToConsole($"Great news, you're all caught up on upgrades in the {this.upgrader.Ring} ring!");

// 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.
this.upgrader.DeletePreviousDownloads();
return true;
}

string upgradeAvailableMessage = $"New GVFS version {newestVersion.ToString()} available in ring {ring}";
if (this.Confirmed)
{
Expand Down

0 comments on commit cb19b42

Please sign in to comment.