Skip to content

Commit 791c1fa

Browse files
committed
Only use reachable feeds when private registries are configured
1 parent 7a8e10e commit 791c1fa

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

csharp/extractor/Semmle.Extraction.CSharp.DependencyFetching/NugetPackageRestorer.cs

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ public HashSet<AssemblyLookupLocation> Restore()
116116

117117
HashSet<string>? explicitFeeds = null;
118118
HashSet<string>? allFeeds = null;
119+
HashSet<string>? reachableFeeds = [];
119120

120121
try
121122
{
@@ -131,8 +132,11 @@ public HashSet<AssemblyLookupLocation> Restore()
131132
// in addition to the ones that are configured in `nuget.config` files.
132133
this.dependabotProxy?.RegistryURLs.ForEach(url => explicitFeeds.Add(url));
133134

134-
var explicitFeedsReachable = this.CheckSpecifiedFeeds(explicitFeeds);
135-
this.GetReachableNuGetFeeds(inheritedFeeds, isFallback: false);
135+
var (explicitFeedsReachable, reachableExplicitFeeds) =
136+
this.CheckSpecifiedFeeds(explicitFeeds);
137+
reachableFeeds.UnionWith(reachableExplicitFeeds);
138+
139+
reachableFeeds.UnionWith(this.GetReachableNuGetFeeds(inheritedFeeds, isFallback: false));
136140

137141
if (inheritedFeeds.Count > 0)
138142
{
@@ -191,7 +195,7 @@ public HashSet<AssemblyLookupLocation> Restore()
191195
// Restore project dependencies with `dotnet restore`.
192196
var restoredProjects = RestoreSolutions(out var container);
193197
var projects = fileProvider.Projects.Except(restoredProjects);
194-
RestoreProjects(projects, allFeeds, out var containers);
198+
RestoreProjects(projects, reachableFeeds, out var containers);
195199

196200
var dependencies = containers.Flatten(container);
197201

@@ -774,8 +778,11 @@ private HashSet<string> GetExcludedFeeds()
774778
/// Checks that we can connect to the specified NuGet feeds.
775779
/// </summary>
776780
/// <param name="feeds">The set of package feeds to check.</param>
777-
/// <returns>True if all feeds are reachable or false otherwise.</returns>
778-
private bool CheckSpecifiedFeeds(HashSet<string> feeds)
781+
/// <returns>
782+
/// True if all feeds are reachable or false otherwise.
783+
/// Also returns the list of reachable feeds.
784+
/// </returns>
785+
private (bool, List<string>) CheckSpecifiedFeeds(HashSet<string> feeds)
779786
{
780787
// Exclude any feeds that are configured by the corresponding environment variable.
781788
var excludedFeeds = GetExcludedFeeds();
@@ -786,7 +793,7 @@ private bool CheckSpecifiedFeeds(HashSet<string> feeds)
786793

787794
this.EmitUnreachableFeedsDiagnostics(allFeedsReachable);
788795

789-
return allFeedsReachable;
796+
return (allFeedsReachable, reachableFeeds);
790797
}
791798

792799
/// <summary>

0 commit comments

Comments
 (0)