From b38a145cfd66013f4a9c54d5c245502e531531a4 Mon Sep 17 00:00:00 2001 From: Nikolay Date: Tue, 28 Mar 2023 03:10:15 +0200 Subject: [PATCH] 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 --- app/vmselect/netstorage/tmp_blocks_file.go | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/app/vmselect/netstorage/tmp_blocks_file.go b/app/vmselect/netstorage/tmp_blocks_file.go index 28a3015f1c..dfcfe0d6e7 100644 --- a/app/vmselect/netstorage/tmp_blocks_file.go +++ b/app/vmselect/netstorage/tmp_blocks_file.go @@ -183,14 +183,12 @@ func (tbf *tmpBlocksFile) MustClose() { } 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 { 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 }