From 2e1243e3f582b1a68ac3fb313364a93128a3f918 Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Mon, 6 Oct 2025 22:27:27 +0200 Subject: configuration: Add MoveSubTree with overwrite=false --- apt-pkg/contrib/configuration.cc | 15 ++++++++++++--- apt-pkg/contrib/configuration.h | 1 + 2 files changed, 13 insertions(+), 3 deletions(-) (limited to 'apt-pkg') diff --git a/apt-pkg/contrib/configuration.cc b/apt-pkg/contrib/configuration.cc index cf72aa3d7..17cdb72c6 100644 --- a/apt-pkg/contrib/configuration.cc +++ b/apt-pkg/contrib/configuration.cc @@ -678,6 +678,10 @@ void Configuration::Clear(string const &Name) } /*}}}*/ void Configuration::MoveSubTree(char const * const OldRootName, char const * const NewRootName)/*{{{*/ +{ + return MoveSubTree(OldRootName, NewRootName, true); +} +void Configuration::MoveSubTree(char const *const OldRootName, char const *const NewRootName, bool Overwrite) { // prevent NewRoot being a subtree of OldRoot if (OldRootName == nullptr) @@ -713,7 +717,10 @@ void Configuration::MoveSubTree(char const * const OldRootName, char const * con while (Top != 0 && Top->Next == 0) { - Set(NewRoot + Top->FullTag(OldRoot), Top->Value); + if (Overwrite) + Set(NewRoot + Top->FullTag(OldRoot), Top->Value); + else + CndSet((NewRoot + Top->FullTag(OldRoot)).c_str(), Top->Value); Item const * const Tmp = Top; Top = Top->Parent; delete Tmp; @@ -721,8 +728,10 @@ void Configuration::MoveSubTree(char const * const OldRootName, char const * con if (Top == Stop) return; } - - Set(NewRoot + Top->FullTag(OldRoot), Top->Value); + if (Overwrite) + Set(NewRoot + Top->FullTag(OldRoot), Top->Value); + else + CndSet((NewRoot + Top->FullTag(OldRoot)).c_str(), Top->Value); Item const * const Tmp = Top; if (Top != 0) Top = Top->Next; diff --git a/apt-pkg/contrib/configuration.h b/apt-pkg/contrib/configuration.h index 30a1cbf43..ab8181a1b 100644 --- a/apt-pkg/contrib/configuration.h +++ b/apt-pkg/contrib/configuration.h @@ -101,6 +101,7 @@ class APT_PUBLIC Configuration bool ExistsAny(const char *Name) const; void MoveSubTree(char const * const OldRoot, char const * const NewRoot); + void MoveSubTree(char const *const OldRoot, char const *const NewRoot, bool Overwrite); // clear a whole tree void Clear(const std::string &Name); -- cgit v1.2.3-70-g09d2