From 4712e20049ebc24c4902049c47aadac27ffdc549 Mon Sep 17 00:00:00 2001 From: Calvin Kim Date: Mon, 1 Jul 2024 21:50:30 +0900 Subject: [PATCH] ffldb: throw error when attempting to delete an open file This change lets us test that we don't attempt to delete open files with unit tests. On Windows this behavior is not allowed which results in an error but on linux and osx it's allowed. To better test Windows compatibilty adding this explicit check in is useful. --- database/ffldb/blockio.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/database/ffldb/blockio.go b/database/ffldb/blockio.go index 2b415a17b0..2272ba1658 100644 --- a/database/ffldb/blockio.go +++ b/database/ffldb/blockio.go @@ -307,6 +307,11 @@ func (s *blockStore) openFile(fileNum uint32) (*lockableFile, error) { // other state cleanup necessary. func (s *blockStore) deleteFile(fileNum uint32) error { filePath := blockFilePath(s.basePath, fileNum) + blockFile := s.openBlockFiles[fileNum] + if blockFile != nil { + err := fmt.Errorf("attempted to delete open file at %v", filePath) + return makeDbErr(database.ErrDriverSpecific, err.Error(), err) + } if err := os.Remove(filePath); err != nil { return makeDbErr(database.ErrDriverSpecific, err.Error(), err) }