bool run(const string& dbname , BSONObj& cmdObj, int, string& errmsg, BSONObjBuilder& result, bool fromRepl ) { string ns = dbname + "." + cmdObj.firstElement().valuestrsafe(); NamespaceString ns_string(ns); const bool full = cmdObj["full"].trueValue(); const bool scanData = full || cmdObj["scandata"].trueValue(); if ( !ns_string.isNormal() && full ) { errmsg = "Can only run full validate on a regular collection"; return false; } if (!serverGlobalParams.quiet) { MONGO_TLOG(0) << "CMD: validate " << ns << endl; } Client::ReadContext ctx(ns_string.ns()); Database* db = cc().database(); if ( !db ) { errmsg = "database not found"; return false; } Collection* collection = db->getCollection( ns ); if ( !collection ) { errmsg = "collection not found"; return false; } result.append( "ns", ns ); ValidateResults results; Status status = collection->validate( full, scanData, &results, &result ); if ( !status.isOK() ) return appendCommandStatus( result, status ); result.appendBool("valid", results.valid); result.append("errors", results.errors); if ( !full ){ result.append("warning", "Some checks omitted for speed. use {full:true} option to do more thorough scan."); } if ( !results.valid ) { result.append("advice", "ns corrupt. See http://dochub.mongodb.org/core/data-recovery"); } return true; }
void Checker::name_style_check(NameType type) { std::string option_name = ( type == NT_CLASS ? "class_naming_style" : type == NT_FUNCTION ? "function_naming_style" : "variable_naming_style"); NamingStyle ns = settings.naming_styles[option_name]; bool style_error = false; if(ns == NS_CAMEL || ns == NS_PASCAL) { style_error = ns == NS_CAMEL && !std::islower(token->line[0]) || ns == NS_PASCAL && !std::isupper(token->line[0]); for(int i = 1; !style_error && i < token->line.size(); ++i) { style_error = !std::isalpha(token->line[i]) && !std::isdigit(token->line[i]); } } if(ns == NS_UNDERSCORE || ns == NS_CAPS_UNDERSCORE) { for(int i = 0; !style_error && i < token->line.size(); ++i) { style_error = token->line[i] != '_' && !std::isdigit(token->line[i]) && ( ns == NS_UNDERSCORE && !islower(token->line[i]) || ns == NS_CAPS_UNDERSCORE && !isupper(token->line[i])); } } if(style_error) { std::string ns_string( ns == NS_CAMEL ? "camel" : ns == NS_PASCAL ? "pascal" : ns == NS_UNDERSCORE ? "underscore" : "caps_underscore"); add_result("name " + token->line + " is not of style " + ns_string); } }