@@ -178,55 +178,32 @@ func ExtractWithFlags(buildFlags []string, patterns []string) error {
178
178
}
179
179
180
180
extractPackage (pkg , & wg , goroutineSem , fdSem )
181
- return
182
- }
183
181
184
- log .Printf ("Skipping dependency package %s." , pkg .PkgPath )
185
- })
182
+ if pkgRoots [pkg .PkgPath ] != "" {
183
+ modPath := filepath .Join (pkgRoots [pkg .PkgPath ], "go.mod" )
184
+ if util .FileExists (modPath ) {
185
+ log .Printf ("Extracting %s" , modPath )
186
+ start := time .Now ()
186
187
187
- wg .Wait ()
188
-
189
- log .Println ("Done extracting packages." )
190
- log .Println ("Starting to extract go.mod files." )
191
-
192
- cwd , err := os .Getwd ()
193
- if err != nil {
194
- log .Printf ("Warning: unable to get working directory: %s" , err .Error ())
195
- log .Println ("Skipping go.mod extraction" )
196
- }
197
- rcwd , err := filepath .EvalSymlinks (cwd )
198
- if err == nil {
199
- cwd = rcwd
200
- }
201
-
202
- goModPaths := make ([]string , 0 , 10 )
188
+ err := extractGoMod (modPath )
189
+ if err != nil {
190
+ log .Printf ("Failed to extract go.mod: %s" , err .Error ())
191
+ }
203
192
204
- filepath .Walk (cwd , func (path string , info os.FileInfo , err error ) error {
205
- if filepath .Base (path ) == "go.mod" && info != nil && info .Mode ().IsRegular () {
206
- if err != nil {
207
- log .Printf ("Found go.mod with path %s, but encountered error %s" , path , err .Error ())
193
+ end := time .Since (start )
194
+ log .Printf ("Done extracting %s (%dms)" , modPath , end .Nanoseconds ()/ 1000000 )
195
+ }
208
196
}
209
197
210
- goModPaths = append ( goModPaths , path )
198
+ return
211
199
}
212
200
213
- return nil
201
+ log . Printf ( "Skipping dependency package %s." , pkg . PkgPath )
214
202
})
215
203
216
- for _ , path := range goModPaths {
217
- log .Printf ("Extracting %s" , path )
218
- start := time .Now ()
219
-
220
- err := extractGoMod (path )
221
- if err != nil {
222
- log .Printf ("Failed to extract go.mod: %s" , err .Error ())
223
- }
224
-
225
- end := time .Since (start )
226
- log .Printf ("Done extracting %s (%dms)" , path , end .Nanoseconds ()/ 1000000 )
227
- }
204
+ wg .Wait ()
228
205
229
- log .Println ("Done extracting go.mod files ." )
206
+ log .Println ("Done extracting packages ." )
230
207
231
208
return nil
232
209
}
0 commit comments