@@ -12,23 +12,22 @@ 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
- private readonly Func < HashSet < string > > getAlreadyDownloadedPackages ;
23
- private readonly HashSet < string > notYetDownloadedPackages = new HashSet < string > ( ) ;
22
+ private readonly HashSet < string > allPackages = new HashSet < string > ( ) ;
24
23
private readonly Initializer initialize ;
25
24
26
- public HashSet < string > NotYetDownloadedPackages
25
+ public HashSet < string > AllPackages
27
26
{
28
27
get
29
28
{
30
29
initialize . Run ( ) ;
31
- return notYetDownloadedPackages ;
30
+ return allPackages ;
32
31
}
33
32
}
34
33
@@ -50,23 +49,18 @@ public bool UseAspNetDlls
50
49
}
51
50
}
52
51
53
- internal FileContent ( Func < HashSet < string > > getAlreadyDownloadedPackages ,
54
- ProgressMonitor progressMonitor ,
52
+ internal FileContent ( ProgressMonitor progressMonitor ,
55
53
Func < IEnumerable < string > > getFiles ,
56
54
IUnsafeFileReader unsafeFileReader )
57
55
{
58
- this . getAlreadyDownloadedPackages = getAlreadyDownloadedPackages ;
59
56
this . progressMonitor = progressMonitor ;
60
57
this . getFiles = getFiles ;
61
58
this . unsafeFileReader = unsafeFileReader ;
62
59
this . initialize = new Initializer ( DoInitialize ) ;
63
60
}
64
61
65
62
66
- public FileContent ( TemporaryDirectory packageDirectory , ProgressMonitor progressMonitor , Func < IEnumerable < string > > getFiles ) : this ( ( ) => Directory . GetDirectories ( packageDirectory . DirInfo . FullName )
67
- . Select ( d => Path . GetFileName ( d )
68
- . ToLowerInvariant ( ) )
69
- . ToHashSet ( ) , progressMonitor , getFiles , new UnsafeFileReader ( ) )
63
+ public FileContent ( ProgressMonitor progressMonitor , Func < IEnumerable < string > > getFiles ) : this ( progressMonitor , getFiles , new UnsafeFileReader ( ) )
70
64
{ }
71
65
72
66
private static string GetGroup ( ReadOnlySpan < char > input , ValueMatch valueMatch , string groupPrefix )
@@ -101,22 +95,21 @@ private static bool IsGroupMatch(ReadOnlySpan<char> line, Regex regex, string gr
101
95
102
96
private void DoInitialize ( )
103
97
{
104
- var alreadyDownloadedPackages = getAlreadyDownloadedPackages ( ) ;
105
98
foreach ( var file in getFiles ( ) )
106
99
{
107
100
try
108
101
{
109
102
foreach ( ReadOnlySpan < char > line in unsafeFileReader . ReadLines ( file ) )
110
103
{
111
104
112
- // Find the not yet downloaded packages.
105
+ // Find all the packages.
113
106
foreach ( var valueMatch in PackageReference ( ) . EnumerateMatches ( line ) )
114
107
{
115
108
// We can't get the group from the ValueMatch, so doing it manually:
116
109
var packageName = GetGroup ( line , valueMatch , "Include" ) ;
117
- if ( ! string . IsNullOrEmpty ( packageName ) && ! alreadyDownloadedPackages . Contains ( packageName ) )
110
+ if ( ! string . IsNullOrEmpty ( packageName ) )
118
111
{
119
- notYetDownloadedPackages . Add ( packageName ) ;
112
+ allPackages . Add ( packageName ) ;
120
113
}
121
114
}
122
115
0 commit comments