summaryrefslogtreecommitdiff
path: root/src/mongo/db/storage
diff options
context:
space:
mode:
authorAdam Cooper <adam.cooper@mongodb.com>2020-08-24 17:41:41 -0400
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2020-08-24 21:54:48 +0000
commit4f4adc1cf23281036dc4d9b61eb24c538e1d9863 (patch)
treea7532237885a45c08a40e4a7f44cef8b0f107e87 /src/mongo/db/storage
parent45924f56e67166a9bacc2f76516a9bc1ae37b53e (diff)
downloadmongo-4f4adc1cf23281036dc4d9b61eb24c538e1d9863.tar.gz
SERVER-47733 SymmetricEncryptorWindows shouldn't pad when update is called
(cherry picked from commit 2f6e5d0f94c06fde943ed6a25a9b7ecf6f774ce5)
Diffstat (limited to 'src/mongo/db/storage')
-rw-r--r--src/mongo/db/storage/remove_saver.cpp24
-rw-r--r--src/mongo/db/storage/remove_saver.h15
2 files changed, 32 insertions, 7 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
diff --git a/src/mongo/db/storage/remove_saver.h b/src/mongo/db/storage/remove_saver.h
index 0704ddb4d49..463fe7f8410 100644
--- a/src/mongo/db/storage/remove_saver.h
+++ b/src/mongo/db/storage/remove_saver.h
@@ -51,7 +51,11 @@ class RemoveSaver {
RemoveSaver& operator=(const RemoveSaver&) = delete;
public:
- RemoveSaver(const std::string& type, const std::string& ns, const std::string& why);
+ class Storage;
+ RemoveSaver(const std::string& type,
+ const std::string& ns,
+ const std::string& why,
+ std::unique_ptr<Storage> storage = std::make_unique<Storage>());
~RemoveSaver();
/**
@@ -77,11 +81,20 @@ public:
}
void file() && = delete;
+ class Storage {
+ public:
+ virtual ~Storage() = default;
+ virtual std::unique_ptr<std::ostream> makeOstream(const boost::filesystem::path& file,
+ const boost::filesystem::path& root);
+ virtual void dumpBuffer() {}
+ };
+
private:
boost::filesystem::path _root;
boost::filesystem::path _file;
std::unique_ptr<DataProtector> _protector;
std::unique_ptr<std::ostream> _out;
+ std::unique_ptr<Storage> _storage;
};
} // namespace mongo