@@ -12,23 +12,24 @@ namespace Semmle.Extraction.CSharp.DependencyFetching
12
12
// This class is used to read a set of files and decide different properties about the
13
13
// content (by reading the content of the files only once).
14
14
// The implementation is lazy, so the properties are only calculated when
15
- // the first property is accessed.
15
+ // the first property is accessed.
16
16
// </summary>
17
17
internal partial class FileContent
18
18
{
19
19
private readonly ProgressMonitor progressMonitor ;
20
20
private readonly IUnsafeFileReader unsafeFileReader ;
21
21
private readonly Func < IEnumerable < string > > getFiles ;
22
22
private readonly Func < HashSet < string > > getAlreadyDownloadedPackages ;
23
- private readonly HashSet < string > notYetDownloadedPackages = new HashSet < string > ( ) ;
23
+ private readonly HashSet < string > allPackages = new HashSet < string > ( ) ;
24
24
private readonly Initializer initialize ;
25
25
26
- public HashSet < string > NotYetDownloadedPackages
26
+ public IEnumerable < string > NotYetDownloadedPackages
27
27
{
28
28
get
29
29
{
30
30
initialize . Run ( ) ;
31
- return notYetDownloadedPackages ;
31
+ var alreadyDownloadedPackages = getAlreadyDownloadedPackages ( ) ;
32
+ return allPackages . Except ( alreadyDownloadedPackages ) ;
32
33
}
33
34
}
34
35
@@ -101,22 +102,21 @@ private static bool IsGroupMatch(ReadOnlySpan<char> line, Regex regex, string gr
101
102
102
103
private void DoInitialize ( )
103
104
{
104
- var alreadyDownloadedPackages = getAlreadyDownloadedPackages ( ) ;
105
105
foreach ( var file in getFiles ( ) )
106
106
{
107
107
try
108
108
{
109
109
foreach ( ReadOnlySpan < char > line in unsafeFileReader . ReadLines ( file ) )
110
110
{
111
111
112
- // Find the not yet downloaded packages.
112
+ // Find all the packages.
113
113
foreach ( var valueMatch in PackageReference ( ) . EnumerateMatches ( line ) )
114
114
{
115
115
// We can't get the group from the ValueMatch, so doing it manually:
116
116
var packageName = GetGroup ( line , valueMatch , "Include" ) ;
117
- if ( ! string . IsNullOrEmpty ( packageName ) && ! alreadyDownloadedPackages . Contains ( packageName ) )
117
+ if ( ! string . IsNullOrEmpty ( packageName ) && ! allPackages . Contains ( packageName ) )
118
118
{
119
- notYetDownloadedPackages . Add ( packageName ) ;
119
+ allPackages . Add ( packageName ) ;
120
120
}
121
121
}
122
122
0 commit comments