diff --git a/db/cloner.cpp b/db/cloner.cpp index 8dd06bd9c4e..c23a3d5f32b 100644 --- a/db/cloner.cpp +++ b/db/cloner.cpp @@ -234,10 +234,7 @@ namespace mongo { continue; } } - if( strcmp( from_name, "local.oplog.$main" ) == 0 ) { - // nothing - want to clone this one - } else if( strchr(from_name, '$') ) { - // don't clone index namespaces -- we take care of those separately below. + if( ! nsDollarCheck( from_name ) ){ log(2) << "\t\t not cloning because has $ " << endl; continue; } diff --git a/db/pdfile.cpp b/db/pdfile.cpp index 377162670b1..8567783d6df 100644 --- a/db/pdfile.cpp +++ b/db/pdfile.cpp @@ -1349,7 +1349,7 @@ namespace mongo { */ DiskLoc DataFileMgr::insert(const char *ns, const void *obuf, int len, bool god, const BSONElement &writeId, bool mayAddIndex) { bool wouldAddIndex = false; - massert( 10093 , "cannot insert into reserved $ collection", god || strchr(ns, '$') == 0 || strcmp( ns, "local.oplog.$main" ) == 0 ); + massert( 10093 , "cannot insert into reserved $ collection", god || nsDollarCheck( ns ) ); uassert( 10094 , "invalid ns", strchr( ns , '.' ) > 0 ); const char *sys = strstr(ns, "system."); if ( sys ) { diff --git a/db/pdfile.h b/db/pdfile.h index dd8f04997f6..5cef15bd927 100644 --- a/db/pdfile.h +++ b/db/pdfile.h @@ -485,5 +485,15 @@ namespace mongo { void ensureHaveIdIndex(const char *ns); bool dropIndexes( NamespaceDetails *d, const char *ns, const char *name, string &errmsg, BSONObjBuilder &anObjBuilder, bool maydeleteIdIndex ); + + + /** + * @return true if ns is ok + */ + inline bool nsDollarCheck( const char* ns ){ + if ( strchr( ns , '$' ) == 0 ) + return true; + return strcmp( ns, "local.oplog.$main" ) == 0; + } } // namespace mongo diff --git a/dbtests/basictests.cpp b/dbtests/basictests.cpp index babef84f86a..53911aaf481 100644 --- a/dbtests/basictests.cpp +++ b/dbtests/basictests.cpp @@ -364,6 +364,10 @@ namespace BasicTests { ASSERT( Database::validDBName( "foo" ) ); ASSERT( ! Database::validDBName( "foo/bar" ) ); ASSERT( ! Database::validDBName( "foo.bar" ) ); + + ASSERT( nsDollarCheck( "asdads" ) ); + ASSERT( ! nsDollarCheck( "asda$ds" ) ); + ASSERT( nsDollarCheck( "local.oplog.$main" ) ); } };