diff options
Diffstat (limited to 'src/mongo/db/repair_database.cpp')
-rw-r--r-- | src/mongo/db/repair_database.cpp | 23 |
1 files changed, 17 insertions, 6 deletions
diff --git a/src/mongo/db/repair_database.cpp b/src/mongo/db/repair_database.cpp index 098184c3c83..03d61395e61 100644 --- a/src/mongo/db/repair_database.cpp +++ b/src/mongo/db/repair_database.cpp @@ -430,21 +430,32 @@ namespace mongo { Database::closeDatabase( dbName, reservedPathString ); } + // at this point if we abort, we don't want to delete new files + // as they might be the only copies + + if ( repairFileDeleter.get() ) + repairFileDeleter->success(); + Client::Context ctx( dbName ); Database::closeDatabase(dbName, storageGlobalParams.dbpath); - if ( backupOriginalFiles ) { _renameForBackup( dbName, reservedPath ); } else { + // first make new directory before deleting data + Path newDir = Path(storageGlobalParams.dbpath) / dbName; + MONGO_ASSERT_ON_EXCEPTION(boost::filesystem::create_directory(newDir)); + + // this deletes old files _deleteDataFiles( dbName ); - MONGO_ASSERT_ON_EXCEPTION( - boost::filesystem::create_directory(Path(storageGlobalParams.dbpath) / dbName)); - } - if ( repairFileDeleter.get() ) - repairFileDeleter->success(); + if ( !boost::filesystem::exists(newDir) ) { + // we deleted because of directoryperdb + // re-create + MONGO_ASSERT_ON_EXCEPTION(boost::filesystem::create_directory(newDir)); + } + } _replaceWithRecovered( dbName, reservedPathString.c_str() ); |