chore(indexshipper): Close temp file after download (#19398)

When downloading a potentially compressed file, the file is first downloaded into a temp file and this temp file is then re-opened and processed. The re-opened *File is Close()d as expected but the initial temp *File is not.

This PR adds the missing Close().
pull/19423/head^2
Jarkko Pöyry 8 months ago committed by GitHub
parent af3e999496
commit 815072fe27
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 8
      pkg/storage/stores/shipper/indexshipper/storage/util.go

@ -62,8 +62,10 @@ func DownloadFileFromStorage(destination string, decompressFile bool, sync bool,
return err
}
defer func() {
err := os.Remove(tmpName)
if err != nil {
if err := ftmp.Close(); err != nil {
level.Warn(logger).Log("msg", "failed to close file", "file", tmpName)
}
if err := os.Remove(tmpName); err != nil {
level.Warn(logger).Log("msg", "failed to delete temp file from index download", "err", err)
}
}()
@ -83,7 +85,7 @@ func DownloadFileFromStorage(destination string, decompressFile bool, sync bool,
}
defer func() {
if err := tmpReader.Close(); err != nil {
level.Warn(logger).Log("msg", "failed to close file", "file", destination+"-tmp")
level.Warn(logger).Log("msg", "failed to close file", "file", tmpName)
}
}()

Loading…
Cancel
Save