diff options
Diffstat (limited to 'src/mongo/db/storage/remove_saver.cpp')
-rw-r--r-- | src/mongo/db/storage/remove_saver.cpp | 24 |
1 files changed, 18 insertions, 6 deletions
diff --git a/src/mongo/db/storage/remove_saver.cpp b/src/mongo/db/storage/remove_saver.cpp index 6652068c6b7..0e56f22ba38 100644 --- a/src/mongo/db/storage/remove_saver.cpp +++ b/src/mongo/db/storage/remove_saver.cpp @@ -35,6 +35,7 @@ #include <boost/filesystem/operations.hpp> #include <fstream> +#include <ios> #include "mongo/db/service_context.h" #include "mongo/db/storage/encryption_hooks.h" @@ -50,7 +51,11 @@ using std::stringstream; namespace mongo { -RemoveSaver::RemoveSaver(const string& a, const string& b, const string& why) { +RemoveSaver::RemoveSaver(const string& a, + const string& b, + const string& why, + std::unique_ptr<Storage> storage) + : _storage(std::move(storage)) { static int NUM = 0; _root = storageGlobalParams.dbpath; @@ -130,16 +135,14 @@ RemoveSaver::~RemoveSaver() { "file"_attr = _file.generic_string(), "error"_attr = redact(errnoWithDescription())); } + + _storage->dumpBuffer(); } } Status RemoveSaver::goingToDelete(const BSONObj& o) { if (!_out) { - // We don't expect to ever pass "" to create_directories below, but catch - // this anyway as per SERVER-26412. - invariant(!_root.empty()); - boost::filesystem::create_directories(_root); - _out.reset(new ofstream(_file.string().c_str(), ios_base::out | ios_base::binary)); + _out = _storage->makeOstream(_file, _root); if (_out->fail()) { string msg = str::stream() << "couldn't create file: " << _file.string() @@ -193,4 +196,13 @@ Status RemoveSaver::goingToDelete(const BSONObj& o) { return Status::OK(); } +std::unique_ptr<std::ostream> RemoveSaver::Storage::makeOstream( + const boost::filesystem::path& file, const boost::filesystem::path& root) { + // We don't expect to ever pass "" to create_directories below, but catch + // this anyway as per SERVER-26412. + invariant(!root.empty()); + boost::filesystem::create_directories(root); + return std::make_unique<std::ofstream>(file.string().c_str(), + std::ios_base::out | std::ios_base::binary); +} } // namespace mongo |