diff options
| author | Julian Andres Klode <jak@debian.org> | 2025-10-06 22:27:27 +0200 |
|---|---|---|
| committer | Julian Andres Klode <jak@debian.org> | 2025-10-25 16:58:07 +0200 |
| commit | 2e1243e3f582b1a68ac3fb313364a93128a3f918 (patch) | |
| tree | 00bcb2548203d7ad25cab8ffcc8f7bd9a8b723d0 /apt-pkg | |
| parent | 05fe552b0c61821e5865c5cb224b2ae25247aeab (diff) | |
configuration: Add MoveSubTree with overwrite=false
Diffstat (limited to 'apt-pkg')
| -rw-r--r-- | apt-pkg/contrib/configuration.cc | 15 | ||||
| -rw-r--r-- | apt-pkg/contrib/configuration.h | 1 |
2 files changed, 13 insertions, 3 deletions
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 @@ -679,6 +679,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) return; @@ -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); |
