@@ -203,33 +203,37 @@ func (s *Symbolizer) getDebuginfo(ctx context.Context, buildID string) (string,
203203 return "" , nil , nil , debuginfo .ErrUnknownDebuginfoSource
204204 }
205205
206- // Fetch the debug info for the build ID.
207- rc , err := s .debuginfo .FetchDebuginfo (ctx , dbginfo )
208- if err != nil {
209- return "" , nil , nil , fmt .Errorf ("fetch debuginfo (BuildID: %q): %w" , buildID , err )
210- }
211- defer rc .Close ()
206+ targetPath := filepath .Join (s .tmpDir , buildID )
207+ if _ , err := os .Stat (targetPath ); errors .Is (err , os .ErrNotExist ) {
208+ // Fetch the debug info for the build ID.
209+ rc , err := s .debuginfo .FetchDebuginfo (ctx , dbginfo )
210+ if err != nil {
211+ return "" , nil , nil , fmt .Errorf ("fetch debuginfo (BuildID: %q): %w" , buildID , err )
212+ }
213+ defer rc .Close ()
212214
213- f , err := os .CreateTemp (s .tmpDir , "parca-symbolizer-*" )
214- if err != nil {
215- return "" , nil , nil , fmt .Errorf ("create temp file: %w" , err )
216- }
217- defer func () {
218- f .Close ()
219- os .Remove (f .Name ())
220- }()
215+ f , err := os .CreateTemp (s .tmpDir , "parca-symbolizer-*" )
216+ if err != nil {
217+ return "" , nil , nil , fmt .Errorf ("create temp file: %w" , err )
218+ }
221219
222- if _ , err := io .Copy (f , rc ); err != nil {
223- return "" , nil , nil , fmt .Errorf ("copy debuginfo to temp file: %w" , err )
224- }
220+ level .Debug (s .logger ).Log ("msg" , fmt .Sprintf ("Copying %s to tmp file %s\n " , buildID , f .Name ()))
221+ defer func () {
222+ f .Close ()
223+ os .Remove (f .Name ())
224+ }()
225225
226- if err := f . Close ( ); err != nil {
227- return "" , nil , nil , fmt .Errorf ("close temp file: %w" , err )
228- }
226+ if _ , err := io . Copy ( f , rc ); err != nil {
227+ return "" , nil , nil , fmt .Errorf ("copy debuginfo to temp file: %w" , err )
228+ }
229229
230- targetPath := filepath .Join (s .tmpDir , buildID )
231- if err := os .Rename (f .Name (), targetPath ); err != nil {
232- return "" , nil , nil , fmt .Errorf ("rename temp file: %w" , err )
230+ if err := f .Close (); err != nil {
231+ return "" , nil , nil , fmt .Errorf ("close temp file: %w" , err )
232+ }
233+
234+ if err := os .Rename (f .Name (), targetPath ); err != nil {
235+ return "" , nil , nil , fmt .Errorf ("rename temp file: %w" , err )
236+ }
233237 }
234238
235239 e , err := elf .Open (targetPath )
0 commit comments