diff --git a/src/MultiDiskAdaptor.cc b/src/MultiDiskAdaptor.cc index ad17e827..8f9c6c20 100644 --- a/src/MultiDiskAdaptor.cc +++ b/src/MultiDiskAdaptor.cc @@ -141,6 +141,7 @@ std::unique_ptr createDiskWriterEntry void MultiDiskAdaptor::resetDiskWriterEntries() { + assert(openedDiskWriterEntries_.empty()); diskWriterEntries_.clear(); if(getFileEntries().empty()) { return; @@ -271,18 +272,19 @@ void MultiDiskAdaptor::openExistingFile() void MultiDiskAdaptor::closeFile() { - size_t n = 0; - openedDiskWriterEntries_.clear(); - for(auto& dwent : diskWriterEntries_) { - if(dwent->isOpen()) { - ++n; - dwent->closeFile(); + for(auto& dwent : openedDiskWriterEntries_) { + auto& dw = dwent->getDiskWriter(); + // required for unit test + if (!dw) { + continue; } + dw->closeFile(); } auto& openedFileCounter = getOpenedFileCounter(); if(openedFileCounter) { - openedFileCounter->reduceNumOfOpenedFile(n); + openedFileCounter->reduceNumOfOpenedFile(openedDiskWriterEntries_.size()); } + openedDiskWriterEntries_.clear(); } namespace {