Skip to content

Commit acba599

Browse files
committed
Inline CheckFeeds
1 parent ddcd9d5 commit acba599

File tree

1 file changed

+30
-34
lines changed

1 file changed

+30
-34
lines changed

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

Lines changed: 30 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -119,13 +119,37 @@ public HashSet<AssemblyLookupLocation> Restore()
119119

120120
try
121121
{
122-
if (checkNugetFeedResponsiveness && !CheckFeeds(out explicitFeeds, out allFeeds))
122+
if (checkNugetFeedResponsiveness)
123123
{
124-
// todo: we could also check the reachability of the inherited nuget feeds, but to use those in the fallback we would need to handle authentication too.
125-
var unresponsiveMissingPackageLocation = DownloadMissingPackagesFromSpecificFeeds([], explicitFeeds);
126-
return unresponsiveMissingPackageLocation is null
127-
? []
128-
: [unresponsiveMissingPackageLocation];
124+
// Find feeds that are configured in NuGet.config files and divide them into ones that
125+
// are explicitly configured for the project, and "all feeds" (including inherited ones)
126+
// from other locations on the host outside of the working directory.
127+
(explicitFeeds, allFeeds) = GetAllFeeds();
128+
var inheritedFeeds = allFeeds.Except(explicitFeeds).ToHashSet();
129+
130+
// Check whether the explicit feeds can be reached.
131+
HashSet<string> feedsToCheck = explicitFeeds;
132+
133+
// If private package registries are configured for C#, then check those
134+
// in addition to the ones that are configured in `nuget.config` files.
135+
this.dependabotProxy?.RegistryURLs.ForEach(url => feedsToCheck.Add(url));
136+
137+
var explicitFeedsReachable = this.CheckSpecifiedFeeds(feedsToCheck);
138+
139+
if (inheritedFeeds.Count > 0)
140+
{
141+
logger.LogInfo($"Inherited NuGet feeds (not checked for reachability): {string.Join(", ", inheritedFeeds.OrderBy(f => f))}");
142+
compilationInfoContainer.CompilationInfos.Add(("Inherited NuGet feed count", inheritedFeeds.Count.ToString()));
143+
}
144+
145+
if (!explicitFeedsReachable)
146+
{
147+
// todo: we could also check the reachability of the inherited nuget feeds, but to use those in the fallback we would need to handle authentication too.
148+
var unresponsiveMissingPackageLocation = DownloadMissingPackagesFromSpecificFeeds([], explicitFeeds);
149+
return unresponsiveMissingPackageLocation is null
150+
? []
151+
: [unresponsiveMissingPackageLocation];
152+
}
129153
}
130154

131155
using (var nuget = new NugetExeWrapper(fileProvider, legacyPackageDirectory, logger))
@@ -732,34 +756,6 @@ private bool IsFeedReachable(string feed, int timeoutMilliSeconds, int tryCount,
732756
return (timeoutMilliSeconds, tryCount);
733757
}
734758

735-
/// <summary>
736-
/// Checks that we can connect to all NuGet feeds that are explicitly configured in configuration files
737-
/// as well as any private package registry feeds that are configured.
738-
/// </summary>
739-
/// <param name="explicitFeeds">Outputs the set of explicit feeds.</param>
740-
/// <param name="allFeeds">Outputs the set of all feeds (explicit and inherited).</param>
741-
/// <returns>True if all feeds are reachable or false otherwise.</returns>
742-
private bool CheckFeeds(out HashSet<string> explicitFeeds, out HashSet<string> allFeeds)
743-
{
744-
(explicitFeeds, allFeeds) = GetAllFeeds();
745-
HashSet<string> feedsToCheck = explicitFeeds;
746-
747-
// If private package registries are configured for C#, then check those
748-
// in addition to the ones that are configured in `nuget.config` files.
749-
this.dependabotProxy?.RegistryURLs.ForEach(url => feedsToCheck.Add(url));
750-
751-
var allFeedsReachable = this.CheckSpecifiedFeeds(feedsToCheck);
752-
753-
var inheritedFeeds = allFeeds.Except(explicitFeeds).ToHashSet();
754-
if (inheritedFeeds.Count > 0)
755-
{
756-
logger.LogInfo($"Inherited NuGet feeds (not checked for reachability): {string.Join(", ", inheritedFeeds.OrderBy(f => f))}");
757-
compilationInfoContainer.CompilationInfos.Add(("Inherited NuGet feed count", inheritedFeeds.Count.ToString()));
758-
}
759-
760-
return allFeedsReachable;
761-
}
762-
763759
/// <summary>
764760
/// Checks that we can connect to the specified NuGet feeds.
765761
/// </summary>

0 commit comments

Comments
 (0)