From: Miod Vallat Date: Wed, 19 Feb 2025 11:16:32 +0000 (+0100) Subject: Preserve record order in pdnsutil add-record. X-Git-Tag: dnsdist-2.0.0-alpha1~44^2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=refs%2Fpull%2F15170%2Fhead;p=thirdparty%2Fpdns.git Preserve record order in pdnsutil add-record. --- diff --git a/pdns/pdnsutil.cc b/pdns/pdnsutil.cc index b12203ebeb..a6fa66ebaa 100644 --- a/pdns/pdnsutil.cc +++ b/pdns/pdnsutil.cc @@ -1727,22 +1727,21 @@ static int addOrReplaceRecord(bool isAdd, const vector& cmds) { } if(isAdd) { - // the 'add' case; preserve existing records... - size_t newRecordsCount = newrrs.size(); + // the 'add' case; preserve existing records, making sure to discard + // would-be new records which contents are identical to the existing ones. + vector oldrrs; di.backend->lookup(rr.qtype, rr.qname, static_cast(di.id)); - while(di.backend->get(oldrr)) { - // ...unless their contents are identical to the records we are adding. - bool skip{false}; - for (size_t idx = 0; idx < newRecordsCount; ++idx) { - if (newrrs.at(idx).content == oldrr.content) { - skip = true; + while (di.backend->get(oldrr)) { + oldrrs.push_back(oldrr); + for (auto iter = newrrs.begin(); iter != newrrs.end(); ++iter) { + if (iter->content == oldrr.content) { + newrrs.erase(iter); break; } } - if (!skip) { - newrrs.push_back(oldrr); - } } + oldrrs.insert(oldrrs.end(), newrrs.begin(), newrrs.end()); + newrrs = std::move(oldrrs); } else { cout<<"All existing records for "<