From 0ea1792f26207640e6be50f4dc4de8a92dc3fb0a Mon Sep 17 00:00:00 2001
From: Lucas Nussbaum <lucas.nussbaum@loria.fr>
Date: Thu, 24 Jan 2019 11:18:23 +0100
Subject: [PATCH] [dev/bind] clean old zone files before generation

---
 lib/refrepo/gen/puppet/bindg5k.rb | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/lib/refrepo/gen/puppet/bindg5k.rb b/lib/refrepo/gen/puppet/bindg5k.rb
index cc2d456bac5..2ae8ea2347f 100644
--- a/lib/refrepo/gen/puppet/bindg5k.rb
+++ b/lib/refrepo/gen/puppet/bindg5k.rb
@@ -1,6 +1,7 @@
 # See also: https://www.grid5000.fr/mediawiki/index.php/DNS_server
 
 require 'dns/zone'
+require 'find'
 
 #Prettier aligned dump of records
 class DNS::Zone::RR::A
@@ -436,6 +437,15 @@ def generate_puppet_bindg5k(options)
     dest_dir = "#{$options[:output_dir]}/platforms/production/modules/generated/files/bind/"
     zones_dir = File.join(dest_dir, "zones/#{site_uid}")
 
+    # Cleanup of old zone files
+    Find.find(zones_dir) do |path|
+      next if not File::file?(path)
+      next if path =~ /manual/ # skip *manual* files
+      # FIXME those files are not named *manual*, but should not be removed
+      next if ['nancy-laptops.db', 'toulouse-servers.db', 'toulouse.db'].include?(File::basename(path))
+      FileUtils::rm(path)
+    end
+
     site_records = {}
 
     # Servers
-- 
GitLab