diff options
author | Benety Goh <benety@mongodb.com> | 2015-09-23 20:20:33 -0400 |
---|---|---|
committer | Benety Goh <benety@mongodb.com> | 2015-09-24 22:20:28 -0400 |
commit | db6396298c7747060c822f6b22e35a08fc847a01 (patch) | |
tree | 978a4c6306918610a80d725f5b97808593e5c363 /src/mongo/db/dbhelpers.cpp | |
parent | a2e4770b90d0cc29375e3a2975010fc98e95a167 (diff) | |
download | mongo-db6396298c7747060c822f6b22e35a08fc847a01.tar.gz |
SERVER-15929 RemoveSaver::goingToDelete() returns error status if it fails to open file or write document to file
Diffstat (limited to 'src/mongo/db/dbhelpers.cpp')
-rw-r--r-- | src/mongo/db/dbhelpers.cpp | 33 |
1 files changed, 17 insertions, 16 deletions
diff --git a/src/mongo/db/dbhelpers.cpp b/src/mongo/db/dbhelpers.cpp index 69b3d4c7e5f..2119d975e4b 100644 --- a/src/mongo/db/dbhelpers.cpp +++ b/src/mongo/db/dbhelpers.cpp @@ -62,6 +62,7 @@ #include "mongo/db/s/collection_metadata.h" #include "mongo/db/s/sharding_state.h" #include "mongo/s/shard_key_pattern.h" +#include "mongo/util/mongoutils/str.h" #include "mongo/util/log.h" #include "mongo/util/scopeguard.h" @@ -564,7 +565,7 @@ void Helpers::emptyCollection(OperationContext* txn, const char* ns) { deleteObjects(txn, context.db(), ns, BSONObj(), PlanExecutor::YIELD_MANUAL, false); } -Helpers::RemoveSaver::RemoveSaver(const string& a, const string& b, const string& why) : _out(0) { +Helpers::RemoveSaver::RemoveSaver(const string& a, const string& b, const string& why) { static int NUM = 0; _root = storageGlobalParams.dbpath; @@ -581,27 +582,27 @@ Helpers::RemoveSaver::RemoveSaver(const string& a, const string& b, const string _file /= ss.str(); } -Helpers::RemoveSaver::~RemoveSaver() { - if (_out) { - _out->close(); - delete _out; - _out = 0; - } -} - -void Helpers::RemoveSaver::goingToDelete(const BSONObj& o) { +Status Helpers::RemoveSaver::goingToDelete(const BSONObj& o) { if (!_out) { boost::filesystem::create_directories(_root); - _out = new ofstream(); - _out->open(_file.string().c_str(), ios_base::out | ios_base::binary); - if (!_out->good()) { - error() << "couldn't create file: " << _file.string() << " for remove saving" << endl; - delete _out; + _out.reset(new ofstream(_file.string().c_str(), ios_base::out | ios_base::binary)); + if (_out->fail()) { + string msg = str::stream() << "couldn't create file: " << _file.string() + << " for remove saving: " << errnoWithDescription(); + error() << msg; + _out.reset(); _out = 0; - return; + return Status(ErrorCodes::FileNotOpen, msg); } } _out->write(o.objdata(), o.objsize()); + if (_out->fail()) { + string msg = str::stream() << "couldn't write document to file: " << _file.string() + << " for remove saving: " << errnoWithDescription(); + error() << msg; + return Status(ErrorCodes::OperationFailed, msg); + } + return Status::OK(); } |