]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mon/ConfigMap: factor out parse_key helper
authorSage Weil <sage@newdream.net>
Tue, 16 Feb 2021 22:06:16 +0000 (17:06 -0500)
committerSage Weil <sage@newdream.net>
Wed, 17 Feb 2021 17:27:58 +0000 (12:27 -0500)
Signed-off-by: Sage Weil <sage@newdream.net>
src/mon/ConfigMap.cc
src/mon/ConfigMap.h
src/mon/ConfigMonitor.cc

index 7fb13841df4230871fde8c0550d73de7a6ee0c11..763b8ce9b1731250210bfcab7eb98ae17ff5ed74 100644 (file)
@@ -233,6 +233,23 @@ bool ConfigMap::parse_mask(
   return true;
 }
 
+void ConfigMap::parse_key(
+  const std::string& key,
+  std::string *name,
+  std::string *who)
+{
+  auto last_slash = key.rfind('/');
+  if (last_slash == std::string::npos) {
+    *name = key;
+  } else if (auto mgrpos = key.find("/mgr/"); mgrpos != std::string::npos) {
+    *name = key.substr(mgrpos + 1);
+    *who = key.substr(0, mgrpos);
+  } else {
+    *name = key.substr(last_slash + 1);
+    *who = key.substr(0, last_slash);
+  }
+}
+
 
 // --------------
 
index d5991bc1d7f33b5d12e06a27d34a42a67bc74a19..2ecdcc071336581873278acecacbfabcc926bc1f 100644 (file)
@@ -129,6 +129,10 @@ struct ConfigMap {
     const std::string& device_class,
     std::map<std::string,std::pair<std::string,const MaskedOption*>> *src=0);
 
+  void parse_key(
+    const std::string& key,
+    std::string *name,
+    std::string *who);
   static bool parse_mask(
     const std::string& in,
     std::string *section,
index c316af3284e0f486248c831a70730fe950bdb89d..d305aa4a24295e1dc965d0da2cb5c4e4aaf254af 100644 (file)
@@ -777,18 +777,9 @@ void ConfigMonitor::load_config()
 
     current[key] = it->value();
 
-    auto last_slash = key.rfind('/');
     string name;
     string who;
-    if (last_slash == std::string::npos) {
-      name = key;
-    } else if (auto mgrpos = key.find("/mgr/"); mgrpos != std::string::npos) {
-      name = key.substr(mgrpos + 1);
-      who = key.substr(0, mgrpos);
-    } else {
-      name = key.substr(last_slash + 1);
-      who = key.substr(0, last_slash);
-    }
+    config_map.parse_key(key, &name, &who);
 
     // has this option been renamed?
     {