]> git.saurik.com Git - apt.git/blobdiff - apt-pkg/contrib/configuration.cc
fileutl: simple_buffer: Add write() and full() methods
[apt.git] / apt-pkg / contrib / configuration.cc
index 203de158b5d536fff8e54c8c8aa2b03928f6be3d..d4bb72a8b61ea606e161163308f008e2941b588b 100644 (file)
@@ -485,6 +485,59 @@ void Configuration::Clear(string const &Name)
    }
 }
                                                                        /*}}}*/
    }
 }
                                                                        /*}}}*/
+void Configuration::MoveSubTree(char const * const OldRootName, char const * const NewRootName)/*{{{*/
+{
+   // prevent NewRoot being a subtree of OldRoot
+   if (OldRootName == nullptr)
+      return;
+   if (NewRootName != nullptr)
+   {
+      if (strcmp(OldRootName, NewRootName) == 0)
+        return;
+      std::string const oldroot = std::string(OldRootName) + "::";
+      if (strcasestr(NewRootName, oldroot.c_str()) != NULL)
+        return;
+   }
+
+   Item * Top;
+   Item const * const OldRoot = Top = Lookup(OldRootName, false);
+   if (Top == nullptr)
+      return;
+   std::string NewRoot;
+   if (NewRootName != nullptr)
+      NewRoot.append(NewRootName).append("::");
+
+   Top->Value.clear();
+   Item * const Stop = Top;
+   Top = Top->Child;
+   Stop->Child = 0;
+   for (; Top != 0;)
+   {
+      if (Top->Child != 0)
+      {
+        Top = Top->Child;
+        continue;
+      }
+
+      while (Top != 0 && Top->Next == 0)
+      {
+        Set(NewRoot + Top->FullTag(OldRoot), Top->Value);
+        Item const * const Tmp = Top;
+        Top = Top->Parent;
+        delete Tmp;
+
+        if (Top == Stop)
+           return;
+      }
+
+      Set(NewRoot + Top->FullTag(OldRoot), Top->Value);
+      Item const * const Tmp = Top;
+      if (Top != 0)
+        Top = Top->Next;
+      delete Tmp;
+   }
+}
+                                                                       /*}}}*/
 // Configuration::Exists - Returns true if the Name exists             /*{{{*/
 // ---------------------------------------------------------------------
 /* */
 // Configuration::Exists - Returns true if the Name exists             /*{{{*/
 // ---------------------------------------------------------------------
 /* */