Skip to content

Commit

Permalink
Add workaround for legacy package managers
Browse files Browse the repository at this point in the history
  • Loading branch information
alnlarsen committed Nov 30, 2023
1 parent a09f3c1 commit e2551af
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions Package/Repositories/HttpPackageRepository.cs
Expand Up @@ -53,14 +53,18 @@ private static HttpClient GetHttpClient(string url)
/// <summary>
/// Get or set the version of the repository
/// </summary>
[Obsolete("This is the version of the repository, and is not related to the API version it supports. You should not rely on this version for the purposes of API compatibility.")]
public SemanticVersion Version
{
get
{
if (_version == null)
CheckRepoApiVersion();

return _version;
CheckDeployedRepoVersion();
// The version of the repo is not important.
// The primary purpose of the check is to see if the repo is available.
// Return version 3.10 to mitigate old package managers that use a faulty
// compatibility check that relies on this property.
return new SemanticVersion(3, 11, 0, "legacy", null);
}
}

Expand Down Expand Up @@ -173,7 +177,7 @@ private string downloadPackagesString(string args, string data = null, string co
catch (Exception ex)
{
if (ex is WebException)
CheckRepoApiVersion();
CheckDeployedRepoVersion();

var exception = new WebException("Error communicating with repository at '" + defaultUrl + "'.", ex);

Expand All @@ -192,7 +196,7 @@ private string downloadPackagesString(string args, string data = null, string co

static readonly TimeSpan updateRepoVersionHoldOff = TimeSpan.FromSeconds(60);
readonly object updateVersionLock = new object();
private void CheckRepoApiVersion()
private void CheckDeployedRepoVersion()
{
lock (updateVersionLock)
{
Expand Down Expand Up @@ -414,7 +418,7 @@ public string[] GetPackageNames(string @class, CancellationToken cancellationTok
public PackageVersion[] GetPackageVersions(string packageName, CancellationToken cancellationToken, params IPackageIdentifier[] compatibleWith)
{
// force update version to check for errors.
CheckRepoApiVersion();
CheckDeployedRepoVersion();
if (IsInError()) return Array.Empty<PackageVersion>();

var parameters = GetQueryParameters(name: packageName);
Expand Down

0 comments on commit e2551af

Please sign in to comment.