]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
common/config: extract check_old_style_section_names() 36361/head
authorKefu Chai <kchai@redhat.com>
Thu, 30 Jul 2020 06:00:32 +0000 (14:00 +0800)
committerKefu Chai <kchai@redhat.com>
Sat, 1 Aug 2020 16:01:47 +0000 (00:01 +0800)
extract check_old_style_section_names() out from
md_config_t::parse_config_files() into ConfFile class.

for two reasons:

* so it can be reused
* for smaller md_config_t::parse_config_files(), hence better
  readability

Signed-off-by: Kefu Chai <kchai@redhat.com>
src/common/ConfUtils.cc
src/common/ConfUtils.h
src/common/config.cc

index 70367c0931536b19acd95b8743d7b7776e717f22..ab41e9ead6472a456a45a57c334073337a7d34b7 100644 (file)
@@ -15,6 +15,7 @@
 
 #include <algorithm>
 #include <cctype>
+#include <experimental/iterator>
 #include <fstream>
 #include <iostream>
 #include <iterator>
@@ -303,6 +304,27 @@ std::string ConfFile::normalize_key_name(std::string_view key)
   return k;
 }
 
+void ConfFile::check_old_style_section_names(const std::vector<std::string>& prefixes,
+                                            std::ostream& os)
+{
+  // Warn about section names that look like old-style section names
+  std::vector<std::string> old_style_section_names;
+  for (auto& [name, section] : *this) {
+    for (auto& prefix : prefixes) {
+      if (name.find(prefix) == 0 && name.size() > 3 && name[3] != '.') {
+       old_style_section_names.push_back(name);
+      }
+    }
+  }
+  if (!old_style_section_names.empty()) {
+    os << "ERROR! old-style section name(s) found: ";
+    std::copy(std::begin(old_style_section_names),
+              std::end(old_style_section_names),
+              std::experimental::make_ostream_joiner(os, ", "));
+    os << ". Please use the new style section names that include a period.";
+  }
+}
+
 std::ostream &operator<<(std::ostream &oss, const ConfFile &cf)
 {
   for (auto& [name, section] : cf) {
index 80dd8df866295e1183d24252b504efa6e417e284..1541d371d7bc31194cb81d78d3fbfffb8e25ba20 100644 (file)
@@ -73,6 +73,13 @@ public:
   int read(const std::string& section, std::string_view key,
           std::string &val) const;
   static std::string normalize_key_name(std::string_view key);
+  // print warnings to os if any old-style section name is found
+  //
+  // consider a section name as old-style name if it starts with any of the
+  // given prefixes, but does not follow with a "."
+  void check_old_style_section_names(const std::vector<std::string>& prefixes,
+                                    std::ostream& os);
+
 private:
   bool load_from_buffer(std::string_view buf, std::ostream* warning);
 };
index fc52433be40a01d0675874e3c84db3e8e2170054..2a5eeed0f91369f0d9bdd8a996edb4ecc5ed75a5 100644 (file)
@@ -401,29 +401,8 @@ int md_config_t::parse_config_files(ConfigValues& values,
       }
     }
   }
-
-  // Warn about section names that look like old-style section names
-  std::deque < std::string > old_style_section_names;
-  for (auto& [name, section] : cf) {
-    if (((name.find("mds") == 0) || (name.find("mon") == 0) ||
-        (name.find("osd") == 0)) && (name.size() > 3) && (name[3] != '.')) {
-      old_style_section_names.push_back(name);
-    }
-  }
-  if (!old_style_section_names.empty()) {
-    ostringstream oss;
-    cerr << "ERROR! old-style section name(s) found: ";
-    string sep;
-    for (std::deque < std::string >::const_iterator os = old_style_section_names.begin();
-        os != old_style_section_names.end(); ++os) {
-      cerr << sep << *os;
-      sep = ", ";
-    }
-    cerr << ". Please use the new style section names that include a period.";
-  }
-
+  cf.check_old_style_section_names({"mds", "mon", "osd"}, cerr);
   update_legacy_vals(values);
-
   return 0;
 }