]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Sort output for "zone list" and "rrset add" as done everywhere else.
authorMiod Vallat <miod.vallat@powerdns.com>
Wed, 20 Aug 2025 13:24:26 +0000 (15:24 +0200)
committerMiod Vallat <miod.vallat@powerdns.com>
Thu, 4 Sep 2025 09:14:00 +0000 (11:14 +0200)
Signed-off-by: Miod Vallat <miod.vallat@powerdns.com>
pdns/pdnsutil.cc

index 8479ce2f8eaa4c1edb24a8a55ac532c82b9cc6b2..32d2cfaa966618716eecb3bf68b7a02cc1c9ce89 100644 (file)
@@ -1757,28 +1757,21 @@ static int listZone(const ZoneName &zone) {
     return EXIT_FAILURE;
   }
 
-  di.backend->list(zone, di.id);
+  std::vector<DNSRecord> records;
   DNSResourceRecord rr;
-  cout<<"$ORIGIN ."<<endl;
-  std::ostream::sync_with_stdio(false);
 
+  di.backend->list(zone, di.id);
   while(di.backend->get(rr)) {
-    if(rr.qtype.getCode() != 0) {
-      switch (rr.qtype.getCode()) {
-      case QType::ALIAS:
-      case QType::CNAME:
-      case QType::MX:
-      case QType::NS:
-      case QType::SRV:
-        if (!rr.content.empty() && rr.content[rr.content.size()-1] != '.') {
-          rr.content.append(1, '.');
-        }
-        break;
-      }
-
-      cout<<rr.qname<<"\t"<<rr.ttl<<"\tIN\t"<<rr.qtype.toString()<<"\t"<<rr.content<<"\n";
+    if(rr.qtype.getCode() != QType::ENT) {
+      records.emplace_back(DNSRecord(rr));
     }
   }
+  sort(records.begin(), records.end(), DNSRecord::prettyCompare);
+  cout<<"$ORIGIN ."<<endl;
+  std::ostream::sync_with_stdio(false);
+  for (const auto& rec : records) {
+    std::cout << formatRecord(rec) << std::endl;
+  }
   cout.flush();
   return EXIT_SUCCESS;
 }
@@ -2609,8 +2602,13 @@ static int addOrReplaceRecord(bool isAdd, const vector<string>& cmds) {
   // need to be explicit to bypass the ueberbackend cache!
   di.backend->lookup(rr.qtype, name, di.id);
   cout<<"New rrset:"<<endl;
+  std::vector<DNSRecord> finalrrs;
   while(di.backend->get(rr)) {
-    cout<<rr.qname.toString()<<" "<<rr.ttl<<" IN "<<rr.qtype.toString()<<" "<<rr.content<<endl;
+    finalrrs.emplace_back(DNSRecord(rr));
+  }
+  sort(finalrrs.begin(), finalrrs.end(), DNSRecord::prettyCompare);
+  for (const auto& rec : finalrrs) {
+    std::cout << formatRecord(rec, " ") << std::endl;
   }
   di.backend->commitTransaction();
   return EXIT_SUCCESS;