]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
When copying/migrating zones, only complain about comments if there are any.
authorMiod Vallat <miod.vallat@powerdns.com>
Fri, 3 Oct 2025 05:25:22 +0000 (07:25 +0200)
committerMiod Vallat <miod.vallat@powerdns.com>
Thu, 23 Oct 2025 09:26:56 +0000 (11:26 +0200)
Fixes: #16201
Signed-off-by: Miod Vallat <miod.vallat@powerdns.com>
(cherry picked from commit dd6e79a5bf56bd80452295ac1f4a8ccbaafdd126)

pdns/pdnsutil.cc

index 1f4517c9c75f9dc1ab6495e698931854b24fd976..4482b4effae03e59180cc089e37b58d07fdbaea2 100644 (file)
@@ -5052,16 +5052,24 @@ static int B2BMigrate(vector<string>& cmds, const std::string_view synopsis)
       nr++;
     }
 
-    // move comments
+    // move comments, if any
     nc=0;
     if (src->listComments(di.id)) {
-      if ((tgt->getCapabilities() & DNSBackend::CAP_COMMENTS) == 0) {
-        throw PDNSException("Target backend does not support comments - remove them first");
-      }
-      Comment c; // NOLINT(readability-identifier-length)
-      while(src->getComment(c)) {
-        c.domain_id = di_new.id;
-        if (!tgt->feedComment(c)) {
+      bool firstComment{true};
+      Comment comm;
+      while (src->getComment(comm)) {
+        if (firstComment) {
+          firstComment = false;
+          if ((tgt->getCapabilities() & DNSBackend::CAP_COMMENTS) == 0) {
+            // TODO: consider simply warning about comments not being copied, and
+            // skip them, rather than abort everything?
+            tgt->abortTransaction();
+            throw PDNSException("Target backend does not support comments - remove them first");
+          }
+        }
+        comm.domain_id = di_new.id;
+        if (!tgt->feedComment(comm)) {
+          tgt->abortTransaction();
           throw PDNSException("Failed to feed zone comments");
         }
         nc++;