@@ -52,28 +52,19 @@ private void HarvestFiles(HarvestFilesSymbol harvestFile, IntermediateSection se
52
52
53
53
var resolvedFiles = Enumerable . Empty < WildcardFile > ( ) ;
54
54
55
- try
56
- {
57
- var included = this . GetWildcardFiles ( harvestFile , inclusions ) ;
58
- var excluded = this . GetWildcardFiles ( harvestFile , exclusions ) ;
55
+ var included = this . GetWildcardFiles ( harvestFile , inclusions ) ;
56
+ var excluded = this . GetWildcardFiles ( harvestFile , exclusions ) ;
59
57
60
- foreach ( var excludedFile in excluded )
61
- {
62
- this . Messaging . Write ( OptimizerVerboses . ExcludedFile ( harvestFile . SourceLineNumbers , excludedFile . Path ) ) ;
63
- }
58
+ foreach ( var excludedFile in excluded )
59
+ {
60
+ this . Messaging . Write ( OptimizerVerboses . ExcludedFile ( harvestFile . SourceLineNumbers , excludedFile . Path ) ) ;
61
+ }
64
62
65
- resolvedFiles = included . Except ( excluded , comparer ) . ToList ( ) ;
63
+ resolvedFiles = included . Except ( excluded , comparer ) . ToList ( ) ;
66
64
67
- if ( ! resolvedFiles . Any ( ) )
68
- {
69
- this . Messaging . Write ( OptimizerWarnings . ZeroFilesHarvested ( harvestFile . SourceLineNumbers ) ) ;
70
- }
71
- }
72
- catch ( DirectoryNotFoundException e )
65
+ if ( ! resolvedFiles . Any ( ) )
73
66
{
74
- this . Messaging . Write ( OptimizerWarnings . ExpectedDirectory ( harvestFile . SourceLineNumbers , e . Message ) ) ;
75
-
76
- return ;
67
+ this . Messaging . Write ( OptimizerWarnings . ZeroFilesHarvested ( harvestFile . SourceLineNumbers ) ) ;
77
68
}
78
69
79
70
foreach ( var fileByRecursiveDir in resolvedFiles . GroupBy ( resolvedFile => resolvedFile . RecursiveDir , resolvedFile => resolvedFile . Path ) )
@@ -139,48 +130,53 @@ private IEnumerable<WildcardFile> GetWildcardFiles(HarvestFilesSymbol harvestFil
139
130
140
131
var files = new List < WildcardFile > ( ) ;
141
132
142
- foreach ( var pattern in patterns )
133
+ try
143
134
{
144
- // Resolve bind paths, if any, which might result in multiple directories.
145
- foreach ( var path in this . ResolveBindPaths ( sourceLineNumbers , pattern ) )
135
+ foreach ( var pattern in patterns )
146
136
{
147
- var sourceDirectory = String . IsNullOrEmpty ( sourcePath ) ? Path . GetDirectoryName ( sourceLineNumbers . FileName ) : sourcePath ;
148
- var recursive = path . IndexOf ( "**" ) >= 0 ;
149
- var filePortion = Path . GetFileName ( path ) ;
150
- var directoryPortion = Path . GetDirectoryName ( path ) ;
151
-
152
- if ( directoryPortion ? . EndsWith ( @"\**" ) == true )
137
+ // Resolve bind paths, if any, which might result in multiple directories.
138
+ foreach ( var path in this . ResolveBindPaths ( sourceLineNumbers , pattern ) )
153
139
{
154
- directoryPortion = directoryPortion . Substring ( 0 , directoryPortion . Length - 3 ) ;
155
- }
140
+ var sourceDirectory = String . IsNullOrEmpty ( sourcePath ) ? Path . GetDirectoryName ( sourceLineNumbers . FileName ) : sourcePath ;
141
+ var recursive = path . IndexOf ( "**" ) >= 0 ;
142
+ var filePortion = Path . GetFileName ( path ) ;
143
+ var directoryPortion = Path . GetDirectoryName ( path ) . TrimEnd ( Path . DirectorySeparatorChar , Path . AltDirectorySeparatorChar ) ;
156
144
157
- var recursiveDirOffset = directoryPortion . Length + 1 ;
145
+ if ( directoryPortion ? . EndsWith ( @"\**" ) == true )
146
+ {
147
+ directoryPortion = directoryPortion . Substring ( 0 , directoryPortion . Length - 3 ) ;
148
+ }
158
149
159
- if ( directoryPortion is null || directoryPortion . Length == 0 || directoryPortion == "**" )
160
- {
161
- directoryPortion = sourceDirectory ;
162
- recursiveDirOffset = sourceDirectory . Length + 1 ;
150
+ if ( directoryPortion is null || directoryPortion . Length == 0 || directoryPortion == "**" )
151
+ {
152
+ directoryPortion = sourceDirectory ;
163
153
164
- }
165
- else if ( ! Path . IsPathRooted ( directoryPortion ) )
166
- {
167
- directoryPortion = Path . Combine ( sourceDirectory , directoryPortion ) ;
168
- recursiveDirOffset = directoryPortion . Length + 1 ;
169
- }
154
+ }
155
+ else if ( ! Path . IsPathRooted ( directoryPortion ) )
156
+ {
157
+ directoryPortion = Path . Combine ( sourceDirectory , directoryPortion ) ;
158
+ }
170
159
171
- var foundFiles = Directory . EnumerateFiles ( directoryPortion , filePortion , recursive ? SearchOption . AllDirectories : SearchOption . TopDirectoryOnly ) ;
160
+ var recursiveDirOffset = directoryPortion . Length + 1 ;
172
161
173
- foreach ( var foundFile in foundFiles )
174
- {
175
- var recursiveDir = Path . GetDirectoryName ( foundFile . Substring ( recursiveDirOffset ) ) ;
176
- files . Add ( new WildcardFile ( )
162
+ var foundFiles = Directory . EnumerateFiles ( directoryPortion , filePortion , recursive ? SearchOption . AllDirectories : SearchOption . TopDirectoryOnly ) ;
163
+
164
+ foreach ( var foundFile in foundFiles )
177
165
{
178
- RecursiveDir = recursiveDir ,
179
- Path = foundFile ,
180
- } ) ;
166
+ var recursiveDir = Path . GetDirectoryName ( foundFile . Substring ( recursiveDirOffset ) ) ;
167
+ files . Add ( new WildcardFile ( )
168
+ {
169
+ RecursiveDir = recursiveDir ,
170
+ Path = foundFile ,
171
+ } ) ;
172
+ }
181
173
}
182
174
}
183
175
}
176
+ catch ( DirectoryNotFoundException e )
177
+ {
178
+ this . Messaging . Write ( OptimizerWarnings . ExpectedDirectory ( harvestFile . SourceLineNumbers , e . Message ) ) ;
179
+ }
184
180
185
181
return files ;
186
182
}
0 commit comments