app/vmselect: properly remove temp files at windows system (#4020)

With non-posix compliant systems it's not possible to remove unclosed files.

Updates https://github.com/VictoriaMetrics/VictoriaMetrics/issues/70
This commit is contained in:
Nikolay 2023-03-28 03:10:15 +02:00 committed by Aliaksandr Valialkin
parent 54b9537a76
commit b38a145cfd
No known key found for this signature in database
GPG Key ID: A72BEC6CD3D0DED1

View File

@ -183,14 +183,12 @@ func (tbf *tmpBlocksFile) MustClose() {
} }
fname := tbf.f.Name() fname := tbf.f.Name()
// Remove the file at first, then close it.
// This way the OS shouldn't try to flush file contents to storage
// on close.
if err := os.Remove(fname); err != nil {
logger.Panicf("FATAL: cannot remove %q: %s", fname, err)
}
if err := tbf.f.Close(); err != nil { if err := tbf.f.Close(); err != nil {
logger.Panicf("FATAL: cannot close %q: %s", fname, err) logger.Panicf("FATAL: cannot close %q: %s", fname, err)
} }
// We cannot remove unclosed at non-posix filesystems, like windows
if err := os.Remove(fname); err != nil {
logger.Panicf("FATAL: cannot remove %q: %s", fname, err)
}
tbf.f = nil tbf.f = nil
} }