forked from loic-sharma/BaGet
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve package mirroring (loic-sharma#679)
Improves the mirroring implementation: 1. Push all mirroring logic into the `MirrorService`. This will make it easier to reuse mirroring logic in the upcoming Razor Pages rewrite: loic-sharma#678 2. Add unit and integration tests on the mirroring functionality 3. Fixed bugs caught by tests
- Loading branch information
1 parent
a742a9a
commit 7d5e2ad
Showing
21 changed files
with
827 additions
and
354 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,63 @@ | ||
using BaGet.Protocol; | ||
using BaGet.Protocol.Models; | ||
using NuGet.Versioning; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using BaGet.Protocol; | ||
using BaGet.Protocol.Models; | ||
using NuGet.Versioning; | ||
using Microsoft.Extensions.Logging; | ||
|
||
namespace BaGet.Core | ||
{ | ||
internal sealed class MirrorV3Client : IMirrorNuGetClient | ||
/// <summary> | ||
/// The mirroring client for a NuGet server that uses the V3 protocol. | ||
/// </summary> | ||
internal sealed class MirrorV3Client : IMirrorClient | ||
{ | ||
private readonly NuGetClient _client; | ||
private readonly ILogger<MirrorV3Client> _logger; | ||
|
||
public MirrorV3Client(NuGetClient client) | ||
public MirrorV3Client(NuGetClient client, ILogger<MirrorV3Client> logger) | ||
{ | ||
_client = client ?? throw new ArgumentNullException(nameof(client)); | ||
_logger = logger ?? throw new ArgumentNullException(nameof(logger)); | ||
} | ||
|
||
public async Task<Stream> DownloadPackageAsync(string id, NuGetVersion version, CancellationToken cancellationToken) | ||
public async Task<Stream> DownloadPackageAsync(string id, NuGetVersion version, | ||
CancellationToken cancellationToken) | ||
{ | ||
return await _client.DownloadPackageAsync(id, version, cancellationToken); | ||
} | ||
|
||
public async Task<IReadOnlyList<PackageMetadata>> GetPackageMetadataAsync(string id, CancellationToken cancellationToken) | ||
public async Task<IReadOnlyList<PackageMetadata>> GetPackageMetadataAsync( | ||
string id, | ||
CancellationToken cancellationToken) | ||
{ | ||
return await _client.GetPackageMetadataAsync(id, cancellationToken); | ||
try | ||
{ | ||
return await _client.GetPackageMetadataAsync(id, cancellationToken); | ||
} | ||
catch (Exception e) | ||
{ | ||
_logger.LogError(e, "Failed to mirror {PackageId}'s upstream metadata", id); | ||
return new List<PackageMetadata>(); | ||
} | ||
} | ||
|
||
public async Task<IReadOnlyList<NuGetVersion>> ListPackageVersionsAsync(string id, bool includeUnlisted, CancellationToken cancellationToken) | ||
public async Task<IReadOnlyList<NuGetVersion>> ListPackageVersionsAsync( | ||
string id, | ||
CancellationToken cancellationToken) | ||
{ | ||
return await _client.ListPackageVersionsAsync(id, includeUnlisted, cancellationToken); | ||
try | ||
{ | ||
return await _client.ListPackageVersionsAsync(id, includeUnlisted: true, cancellationToken); | ||
} | ||
catch (Exception e) | ||
{ | ||
_logger.LogError(e, "Failed to mirror {PackageId}'s upstream versions", id); | ||
return new List<NuGetVersion>(); | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.