@@ -12,23 +12,24 @@ namespace Semmle.Extraction.CSharp.DependencyFetching
1212 // This class is used to read a set of files and decide different properties about the
1313 // content (by reading the content of the files only once).
1414 // The implementation is lazy, so the properties are only calculated when
15- // the first property is accessed.
15+ // the first property is accessed.
1616 // </summary>
1717 internal partial class FileContent
1818 {
1919 private readonly ProgressMonitor progressMonitor ;
2020 private readonly IUnsafeFileReader unsafeFileReader ;
2121 private readonly Func < IEnumerable < string > > getFiles ;
2222 private readonly Func < HashSet < string > > getAlreadyDownloadedPackages ;
23- private readonly HashSet < string > notYetDownloadedPackages = new HashSet < string > ( ) ;
23+ private readonly HashSet < string > allPackages = new HashSet < string > ( ) ;
2424 private readonly Initializer initialize ;
2525
26- public HashSet < string > NotYetDownloadedPackages
26+ public IEnumerable < string > NotYetDownloadedPackages
2727 {
2828 get
2929 {
3030 initialize . Run ( ) ;
31- return notYetDownloadedPackages ;
31+ var alreadyDownloadedPackages = getAlreadyDownloadedPackages ( ) ;
32+ return allPackages . Except ( alreadyDownloadedPackages ) ;
3233 }
3334 }
3435
@@ -101,22 +102,21 @@ private static bool IsGroupMatch(ReadOnlySpan<char> line, Regex regex, string gr
101102
102103 private void DoInitialize ( )
103104 {
104- var alreadyDownloadedPackages = getAlreadyDownloadedPackages ( ) ;
105105 foreach ( var file in getFiles ( ) )
106106 {
107107 try
108108 {
109109 foreach ( ReadOnlySpan < char > line in unsafeFileReader . ReadLines ( file ) )
110110 {
111111
112- // Find the not yet downloaded packages.
112+ // Find all the packages.
113113 foreach ( var valueMatch in PackageReference ( ) . EnumerateMatches ( line ) )
114114 {
115115 // We can't get the group from the ValueMatch, so doing it manually:
116116 var packageName = GetGroup ( line , valueMatch , "Include" ) ;
117- if ( ! string . IsNullOrEmpty ( packageName ) && ! alreadyDownloadedPackages . Contains ( packageName ) )
117+ if ( ! string . IsNullOrEmpty ( packageName ) && ! allPackages . Contains ( packageName ) )
118118 {
119- notYetDownloadedPackages . Add ( packageName ) ;
119+ allPackages . Add ( packageName ) ;
120120 }
121121 }
122122
0 commit comments