@@ -178,55 +178,32 @@ func ExtractWithFlags(buildFlags []string, patterns []string) error {
178178 }
179179
180180 extractPackage (pkg , & wg , goroutineSem , fdSem )
181- return
182- }
183181
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 ()
186187
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+ }
203192
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+ }
208196 }
209197
210- goModPaths = append ( goModPaths , path )
198+ return
211199 }
212200
213- return nil
201+ log . Printf ( "Skipping dependency package %s." , pkg . PkgPath )
214202 })
215203
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 ()
228205
229- log .Println ("Done extracting go.mod files ." )
206+ log .Println ("Done extracting packages ." )
230207
231208 return nil
232209}
0 commit comments