]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Make updateEmptyNonTerminals conform to its specification... 15806/head
authorMiod Vallat <miod.vallat@powerdns.com>
Wed, 9 Jul 2025 07:31:02 +0000 (09:31 +0200)
committerMiod Vallat <miod.vallat@powerdns.com>
Wed, 9 Jul 2025 07:40:55 +0000 (09:40 +0200)
...by performing the insertions (if any) when all ENT had to be removed
first.

Signed-off-by: Miod Vallat <miod.vallat@powerdns.com>
modules/lmdbbackend/lmdbbackend.cc

index 801005069b008b5c90f608d4610438d7051baf84..7aa56af8662a664bc4f619de1b17cff5e3602de5 100644 (file)
@@ -2804,40 +2804,38 @@ bool LMDBBackend::updateEmptyNonTerminals(domainid_t domain_id, set<DNSName>& in
     needCommit = true;
   }
 
-  // if remove is set, all ENTs should be removed & nothing else should be done
+  DomainInfo info;
+  auto rotxn = d_tdomains->getROTransaction();
+  if (!rotxn.get(domain_id, info)) {
+    // cout <<"No such domain with id "<<domain_id<<endl;
+    return false;
+  }
+
+  // if remove is set, all ENTs should be removed
+  compoundOrdername order;
   if (remove) {
-    compoundOrdername order;
     string match = order(domain_id);
     LMDBBackend::deleteDomainRecords(*txn, QType::ENT, match);
   }
   else {
-    DomainInfo di;
-    auto rotxn = d_tdomains->getROTransaction();
-    if (!rotxn.get(domain_id, di)) {
-      // cout <<"No such domain with id "<<domain_id<<endl;
-      return false;
-    }
-    compoundOrdername co;
-    for (const auto& n : insert) {
-      LMDBResourceRecord lrr;
-      lrr.qname = n.makeRelative(di.zone);
-      lrr.ttl = 0;
-      lrr.auth = true;
-
-      std::string ser = serializeToBuffer(lrr);
-
-      txn->txn->put(txn->db->dbi, co(domain_id, lrr.qname, QType::ENT), ser);
-
-      // cout <<" +"<<n<<endl;
-    }
-    for (auto n : erase) {
-      // cout <<" -"<<n<<endl;
-      n.makeUsRelative(di.zone);
-      txn->txn->del(txn->db->dbi, co(domain_id, n, QType::ENT));
+    for (auto name : erase) {
+      // cout <<" -"<<name<<endl;
+      name.makeUsRelative(info.zone);
+      txn->txn->del(txn->db->dbi, order(domain_id, name, QType::ENT));
     }
   }
-  if (needCommit)
+  for (const auto& name : insert) {
+    LMDBResourceRecord lrr;
+    lrr.qname = name.makeRelative(info.zone);
+    lrr.ttl = 0;
+    lrr.auth = true;
+    std::string ser = serializeToBuffer(lrr);
+    txn->txn->put(txn->db->dbi, order(domain_id, lrr.qname, QType::ENT), ser);
+    // cout <<" +"<<name<<endl;
+  }
+  if (needCommit) {
     txn->txn->commit();
+  }
   return false;
 }