diff options
author | Shaun Verch <shaun.verch@mongodb.com> | 2014-05-07 18:01:04 -0400 |
---|---|---|
committer | Shaun Verch <shaun.verch@mongodb.com> | 2014-05-13 17:08:50 -0400 |
commit | a503b4b57e57f81bebddd07ed75cf116f23de350 (patch) | |
tree | ae0db9e6b4474142a3862ddf550554f1af09ba39 /src/mongo/util/options_parser/options_parser.cpp | |
parent | b3e8e45ea6f346f804161e1fe4043ba3e5850ba8 (diff) | |
download | mongo-a503b4b57e57f81bebddd07ed75cf116f23de350.tar.gz |
SERVER-13439 Make sure values explicitly set to false in config file show up in parsed result
Diffstat (limited to 'src/mongo/util/options_parser/options_parser.cpp')
-rw-r--r-- | src/mongo/util/options_parser/options_parser.cpp | 65 |
1 files changed, 48 insertions, 17 deletions
diff --git a/src/mongo/util/options_parser/options_parser.cpp b/src/mongo/util/options_parser/options_parser.cpp index 00b3b5d09ff..42c5c2cdd0c 100644 --- a/src/mongo/util/options_parser/options_parser.cpp +++ b/src/mongo/util/options_parser/options_parser.cpp @@ -221,10 +221,7 @@ namespace optionenvironment { return Status::OK(); } else if (stringVal == "false") { - // XXX: Don't set switches that are false, to maintain backwards - // compatibility with the old behavior since some code depends on this - // behavior - *value = Value(); + *value = Value(false); return Status::OK(); } else { @@ -345,19 +342,6 @@ namespace optionenvironment { return ret; } - // XXX: Don't set switches that are false, to maintain backwards compatibility - // with the old behavior during the transition to the new parser - if (iterator->_type == Switch) { - bool value; - ret = optionValue.get(&value); - if (!ret.isOK()) { - return ret; - } - if (!value) { - continue; - } - } - // If this is really a StringMap, try to split on "key=value" for each element // in our StringVector if (iterator->_type == StringMap) { @@ -595,6 +579,45 @@ namespace optionenvironment { return Status::OK(); } + /** + * Remove any options of type "Switch" that are set to false. This is needed because boost + * defaults switches to false, and we need to be able to tell the difference between + * whether an option is set explicitly to false in config files or not present at all. + */ + Status removeFalseSwitches(const OptionSection& options, Environment* environment) { + std::vector<OptionDescription> options_vector; + Status ret = options.getAllOptions(&options_vector); + if (!ret.isOK()) { + return ret; + } + + for (std::vector<OptionDescription>::const_iterator iterator = options_vector.begin(); + iterator != options_vector.end(); iterator++) { + + if (iterator->_type == Switch) { + bool switchValue; + Status ret = environment->get(iterator->_dottedName, &switchValue); + if (!ret.isOK() && ret != ErrorCodes::NoSuchKey) { + StringBuilder sb; + sb << "Error getting switch value for option: " << iterator->_dottedName + << " from source: " << ret.toString(); + return Status(ErrorCodes::InternalError, sb.str()); + } + else if (ret.isOK() && switchValue == false) { + Status ret = environment->remove(iterator->_dottedName); + if (!ret.isOK()) { + StringBuilder sb; + sb << "Error removing false flag: " << iterator->_dottedName << ": " + << ret.toString(); + return Status(ErrorCodes::InternalError, sb.str()); + } + } + } + } + + return Status::OK(); + } + } // namespace /** @@ -673,6 +696,14 @@ namespace optionenvironment { sb << "Error parsing command line: " << e.what(); return Status(ErrorCodes::BadValue, sb.str()); } + + // This is needed because "switches" default to false in boost, and we don't want to + // erroneously think that they were present but set to false in a config file. + ret = removeFalseSwitches(options, environment); + if (!ret.isOK()) { + return ret; + } + return Status::OK(); } |