Skip to content

Commit

Permalink
ffldb: throw error when attempting to delete an open file
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
kcalvinalvin committed Jul 1, 2024
1 parent d881c68 commit 4712e20
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions database/ffldb/blockio.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down

0 comments on commit 4712e20

Please sign in to comment.