Permalink
Browse files

SERVER-1208 config files ignore flags set to =false, warn about fast …

…sync, and skip lines starting with #
  • Loading branch information...
1 parent 9a79fd7 commit 093b04d395c1cacfcde76da13f2eb62667ec8b3d @dannenberg dannenberg committed with kchodorow Jul 27, 2011
Showing with 48 additions and 1 deletion.
  1. +31 −1 db/cmdline.cpp
  2. +1 −0 db/cmdline.h
  3. +4 −0 jstests/libs/testconfig
  4. +12 −0 jstests/slowNightly/command_line_parsing.js
View
@@ -28,6 +28,8 @@
#include <direct.h>
#endif
+#define MAX_LINE_LENGTH 256
+
namespace po = boost::program_options;
namespace fs = boost::filesystem;
@@ -94,6 +96,32 @@ namespace mongo {
}
#endif
+ void CmdLine::parseConfigFile( ifstream &f, stringstream &ss ) {
+ string s;
+ char line[MAX_LINE_LENGTH];
+
+ while ( f ) {
+ f.getline(line, MAX_LINE_LENGTH);
+ s = line;
+ std::remove(s.begin(), s.end(), ' ');
+ std::remove(s.begin(), s.end(), '\t');
+ boost::to_upper(s);
+
+ if ( s.find( "FASTSYNC" ) != string::npos )
+ cout << "warning \"fastsync\" should not be put in your configuration file" << endl;
+
+ if ( s[0] == '#' ) {
+ // skipping commented line
+ } else if ( s.find( "=FALSE" ) == string::npos ) {
+ ss << line << endl;
+ } else {
+ cout << "warning: remove or comment out this line by starting it with \'#\', skipping now : " << line << endl;
+ }
+ }
+ return;
+ }
+
+
bool CmdLine::store( int argc , char ** argv ,
boost::program_options::options_description& visible,
@@ -150,7 +178,9 @@ namespace mongo {
return false;
}
- po::store( po::parse_config_file( f , all ) , params );
+ stringstream ss;
+ CmdLine::parseConfigFile( f, ss );
+ po::store( po::parse_config_file( ss , all ) , params );
f.close();
}
View
@@ -120,6 +120,7 @@ namespace mongo {
boost::program_options::options_description& hidden );
+ static void parseConfigFile( ifstream &f, stringstream &ss);
/**
* @return true if should run program, false if should exit
*/
@@ -0,0 +1,4 @@
+fastsync = true
+#comment line
+#commentedflagwithan = false
+version = false
@@ -7,3 +7,15 @@ var baseName = "jstests_slowNightly_command_line_parsing";
var m = startMongod( "--port", port, "--dbpath", "/data/db/" + baseName, "--notablescan" );
m.getDB( baseName ).getCollection( baseName ).save( {a:1} );
assert.throws( function() { m.getDB( baseName ).getCollection( baseName ).find( {a:1} ).toArray() } );
+
+// test config file
+var m2 = startMongod( "--port", port+2, "--dbpath", "/data/db/" + baseName +"2", "--config", "jstests/libs/testconfig");
+var m2result = {
+ "parsed" : {
+ "config" : "jstests/libs/testconfig",
+ "dbpath" : "/data/db/jstests_slowNightly_command_line_parsing2",
+ "fastsync" : "true",
+ "port" : 31002
+ }
+};
+assert( friendlyEqual(m2result.parsed, m2.getDB("admin").runCommand( "getCmdLineOpts" ).parsed) );

0 comments on commit 093b04d

Please sign in to comment.