pair < section_iter_t, bool > nr(sections.insert(nt));
cur_section = nr.first;
}
- else if (!cline->key.empty()) {
+ else {
+ if (cur_section->second.lines.count(*cline)) {
+ // replace an existing key/line in this section, so that
+ // [mysection]
+ // foo = 1
+ // foo = 2
+ // will result in foo = 2.
+ cur_section->second.lines.erase(*cline);
+ if (cline->key.length())
+ std::cerr << "warning: line " << line_no << ": '" << cline->key << "' in section '"
+ << cur_section->first << "' redefined " << std::endl;
+ }
// add line to current section
//std::cerr << "cur_section = " << cur_section->first << ", " << *cline << std::endl;
cur_section->second.lines.insert(*cline);
log file = osd0_log\n\
";
+const char dup_key_config_1[] = "\
+[mds.a]\n\
+ log_file = 1\n\
+ log_file = 3\n\
+";
+
TEST(Whitespace, ConfUtils) {
std::string test0("");
ConfFile::trim_whitespace(test0, false);
ASSERT_EQ(err.size(), 0U);
ASSERT_EQ(conf.log_file, "osd0_log");
}
+
+TEST(DupKey, ConfUtils) {
+ md_config_t conf;
+ std::deque<std::string> err;
+ std::string dup_key_config_f(next_tempfile(dup_key_config_1));
+
+ conf.name.set(CEPH_ENTITY_TYPE_MDS, "a");
+ conf.parse_config_files(dup_key_config_f.c_str(), &err, 0);
+ ASSERT_EQ(err.size(), 0U);
+ ASSERT_EQ(conf.log_file, string("3"));
+}