Skip to content

Commit 815072f

Browse files
authored
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().
1 parent af3e999 commit 815072f

File tree

1 file changed

+5
-3
lines changed
  • pkg/storage/stores/shipper/indexshipper/storage

1 file changed

+5
-3
lines changed

pkg/storage/stores/shipper/indexshipper/storage/util.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,10 @@ func DownloadFileFromStorage(destination string, decompressFile bool, sync bool,
6262
return err
6363
}
6464
defer func() {
65-
err := os.Remove(tmpName)
66-
if err != nil {
65+
if err := ftmp.Close(); err != nil {
66+
level.Warn(logger).Log("msg", "failed to close file", "file", tmpName)
67+
}
68+
if err := os.Remove(tmpName); err != nil {
6769
level.Warn(logger).Log("msg", "failed to delete temp file from index download", "err", err)
6870
}
6971
}()
@@ -83,7 +85,7 @@ func DownloadFileFromStorage(destination string, decompressFile bool, sync bool,
8385
}
8486
defer func() {
8587
if err := tmpReader.Close(); err != nil {
86-
level.Warn(logger).Log("msg", "failed to close file", "file", destination+"-tmp")
88+
level.Warn(logger).Log("msg", "failed to close file", "file", tmpName)
8789
}
8890
}()
8991

0 commit comments

Comments
 (0)