Skip to content

Commit c4af872

Browse files
committed
Read upgrade ring from feedurl
Upgrade feedurl contains upgrade ring specification as a substring. Github upgrader now attempts to parse feedurl and read the ring info specified. If the feedurl is set, but if it does not contain the ring info, then that would be interpreted as a None ring - meaning GVFS.Service would not be able to do upgrade checks in the background. But if feedurl is not set at all, then regular uprade.ring config would be used.
1 parent 6cfe721 commit c4af872

3 files changed

Lines changed: 122 additions & 16 deletions

File tree

GVFS/GVFS.Common/GitHubUpgrader.cs

Lines changed: 51 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -529,29 +529,65 @@ public bool TryLoad(out string error)
529529
this.UpgradeRing = RingType.NoConfig;
530530

531531
string ringConfig = null;
532-
if (this.LocalConfig.TryGetConfig(GVFSConstants.LocalGVFSConfig.UpgradeRing, out ringConfig, out error))
532+
string upgradeFeedUrl = null;
533+
string loadError = "Could not read GVFS Config." + Environment.NewLine + GVFSConstants.UpgradeVerbMessages.SetUpgradeRingCommand;
534+
535+
// There are couple config settings that contain info about Upgrade rings.
536+
// upgrade.ring and upgrade.feedURL. upgrade.feedURL will override upgrade.ring
537+
// config. If upgrade.feedURL is set, but does not contain valid ring info then
538+
// upgrade ring would be set to NoConfig and auto upgrade checks will fail.
539+
if (!this.LocalConfig.TryGetConfig(GVFSConstants.LocalGVFSConfig.UpgradeFeedUrl, out upgradeFeedUrl, out error))
533540
{
534-
RingType ringType;
535-
if (Enum.TryParse(ringConfig, ignoreCase: true, result: out ringType) &&
536-
Enum.IsDefined(typeof(RingType), ringType) &&
537-
ringType != RingType.Invalid)
538-
{
539-
this.UpgradeRing = ringType;
540-
}
541-
else
541+
error = loadError;
542+
return false;
543+
}
544+
545+
// If upgradeFeedUrl is available then use it for the ring config, if not use regular
546+
// upgrade.ring.
547+
if (!string.IsNullOrEmpty(upgradeFeedUrl))
548+
{
549+
this.UpgradeRing = RingType.None;
550+
551+
string[] expectedRings = new string[] { RingType.Slow.ToString(), RingType.Fast.ToString() };
552+
foreach (string ring in expectedRings)
542553
{
543-
if (!string.IsNullOrEmpty(ringConfig))
554+
string ringSubstring = $"@{ring}/";
555+
if (upgradeFeedUrl.IndexOf(ringSubstring, StringComparison.OrdinalIgnoreCase) != -1)
544556
{
545-
this.UpgradeRing = RingType.Invalid;
557+
ringConfig = ring;
558+
break;
546559
}
547560
}
561+
}
562+
else if (!this.LocalConfig.TryGetConfig(GVFSConstants.LocalGVFSConfig.UpgradeRing, out ringConfig, out error))
563+
{
564+
error = loadError;
565+
return false;
566+
}
548567

549-
return true;
568+
this.ParseUpgradeRing(ringConfig);
569+
return true;
570+
}
571+
572+
public void ParseUpgradeRing(string ringConfig)
573+
{
574+
if (string.IsNullOrEmpty(ringConfig))
575+
{
576+
this.UpgradeRing = RingType.None;
577+
return;
550578
}
551579

552-
error = "Could not read GVFS Config." + Environment.NewLine;
553-
error += GVFSConstants.UpgradeVerbMessages.SetUpgradeRingCommand;
554-
return false;
580+
RingType ringType;
581+
if (Enum.TryParse(ringConfig, ignoreCase: true, result: out ringType) &&
582+
Enum.IsDefined(typeof(RingType), ringType) &&
583+
ringType != RingType.Invalid)
584+
{
585+
this.UpgradeRing = ringType;
586+
}
587+
else
588+
{
589+
this.UpgradeRing = RingType.Invalid;
590+
}
555591
}
556592

557593
public bool ConfigError()

GVFS/GVFS.UnitTests.Windows/Windows/Mock/MockLocalGVFSConfig.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ public override bool TryGetConfig(
2727
{
2828
error = null;
2929

30-
return this.Settings.TryGetValue(name, out value);
30+
this.Settings.TryGetValue(name, out value);
31+
return true;
3132
}
3233

3334
public override bool TrySetConfig(

GVFS/GVFS.UnitTests.Windows/Windows/Upgrader/ProductUpgraderTests.cs

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,75 @@ public void UpgradeAvailableOnSlowWhileOnLocalFastRing()
8080
expectedUpgradeVersion:UpgradeTests.NewerThanLocalVersion);
8181
}
8282

83+
[TestCase]
84+
public void RingInNugetFeedURLOverridesUpgradeRing()
85+
{
86+
// Pretend there is an upgrade available in Fast ring. Set upgrade.ring
87+
// to fast and verify that Upgrader returns the new version.
88+
Version newVersion;
89+
string error;
90+
this.SetUpgradeRing(GitHubUpgrader.GitHubUpgraderConfig.RingType.Fast.ToString());
91+
92+
// Replace pretend upgrade Release set by UpgradeTests.Setup() method
93+
this.Upgrader.PretendNewReleaseAvailableAtRemote(UpgradeTests.NewerThanLocalVersion, GitHubUpgrader.GitHubUpgraderConfig.RingType.Fast);
94+
95+
this.Upgrader.TryQueryNewestVersion(out newVersion, out error).ShouldBeTrue();
96+
newVersion.ShouldNotBeNull();
97+
newVersion.ToString().ShouldEqual(UpgradeTests.NewerThanLocalVersion);
98+
99+
// Now add upgrade.feedurl with Slow ring info. The Slow ring in upgrade.feedurl should
100+
// override the Fast that is set already (in the steps above) in upgrade.ring. Since
101+
// there is no upgrade available in Slow, Verify that Upgrader returns Null upgrade
102+
// this time.
103+
string feedUrlWithSlowRing = "https://foo.bar.visualstudio.com/helloworld/_packaging/GVFS@Slow/nuget/v3/index.json";
104+
this.LocalConfig.TrySetConfig("upgrade.feedurl", feedUrlWithSlowRing, out error);
105+
this.Upgrader.Config.TryLoad(out error).ShouldBeTrue();
106+
107+
this.Upgrader.TryQueryNewestVersion(out newVersion, out error).ShouldBeTrue();
108+
newVersion.ShouldBeNull();
109+
error.ShouldContain("Great news");
110+
}
111+
112+
[TestCase]
113+
public void FastUpgradeRingAndNoRingInNugetFeedURLReturnsNoUpgrade()
114+
{
115+
// Pretend there is an upgrade available in Fast ring. Set upgrade.ring
116+
// to fast and verify that Upgrader returns the new version.
117+
Version newVersion;
118+
string error;
119+
this.SetUpgradeRing(GitHubUpgrader.GitHubUpgraderConfig.RingType.Fast.ToString());
120+
121+
// Replace pretend upgrade Release set by UpgradeTests.Setup() method
122+
this.Upgrader.PretendNewReleaseAvailableAtRemote(UpgradeTests.NewerThanLocalVersion, GitHubUpgrader.GitHubUpgraderConfig.RingType.Fast);
123+
124+
this.Upgrader.TryQueryNewestVersion(out newVersion, out error).ShouldBeTrue();
125+
newVersion.ShouldNotBeNull();
126+
127+
// Now add upgrade.feedurl with no ring info. The presence of upgrade.feedurl config
128+
// should force upgrader to reset its ring to the one specified in upgrade.feedurl.
129+
// But since there is no ring specified in upgrade.feedurl, upgrader should have no valid
130+
// ring now. Verify that Upgrader returns Null upgrade this time.
131+
string feedUrlWithNoRing = "https://foo.bar.visualstudio.com/helloworld/GVFS/nuget/v3/index.json";
132+
this.LocalConfig.TrySetConfig("upgrade.feedurl", feedUrlWithNoRing, out error);
133+
this.Upgrader.Config.TryLoad(out error).ShouldBeTrue();
134+
135+
this.Upgrader.TryQueryNewestVersion(out newVersion, out error).ShouldBeTrue();
136+
newVersion.ShouldBeNull();
137+
}
138+
139+
[TestCase]
140+
public void NoRingInNugetFeedURLReturnsNullUpgrade()
141+
{
142+
string error;
143+
string feedUrlWithNoRing = "https://foo.bar.visualstudio.com/helloworld/_packaging/GVFS/nuget/v3/index.json";
144+
this.LocalConfig.TrySetConfig("upgrade.feedurl", feedUrlWithNoRing, out error);
145+
this.Upgrader.Config.TryLoad(out error).ShouldBeTrue();
146+
147+
Version newVersion;
148+
this.Upgrader.TryQueryNewestVersion(out newVersion, out error).ShouldBeTrue();
149+
newVersion.ShouldBeNull();
150+
}
151+
83152
public override void NoneLocalRing()
84153
{
85154
throw new NotSupportedException();

0 commit comments

Comments
 (0)