Commit c3c44937 authored by Colin Shea's avatar Colin Shea

Purge is optional, #generate is even smarter

Purge is not called by default any more. We're managing the results of
the generation in a git repo, so don't delete the entire directory every

Compare the list of zones old vs new and delete any old. This allows the
user to rename a zone and not leave files around.

The comparison for SOA record bumping didn't work until the introduction
of the remote vs local concept of zone files. Now, you can point dnsgit
to the old zones on your laptop and it'll only update the zones that
have actually changed.
parent 855e1a47
......@@ -10,5 +10,5 @@ require 'zonefile'
config = YAML.load_file(ENV['ZONE_CONFIG_FILE'] || "config.yaml")
generator =, Dir.pwd)
......@@ -35,17 +35,26 @@ class ZoneGenerator
# Delete the old generated directory, and rebuild it.
def purge!
FileUtils.rm_rf @generated
Dir.glob("#{@generated}/*").sort.each do |item|
FileUtils.rm_rf item
FileUtils.mkdir_p @generated
FileUtils.mkdir_p @tmp_zones
# Generates all zones
def generate
ruby_zones = Dir.glob("#{@zones_dir}/**/*.rb").map {|z| File.basename(z, '.rb')+'.zone'}
text_zones = Dir.glob("#{@config['local_zones_dir']}/*.zone").map {|z| File.basename(z) }
old_zones = (text_zones-ruby_zones).map{|f| File.join(@config['local_zones_dir'], f)}
old_zones.each do |old|
FileUtils.rm old
end,"w") do |f|
Dir.glob("#{@zones_dir}/**/*.rb").sort.each do |file|
domain = File.basename(file).sub(/\.rb$/,"")
puts "Generating zone for '#{domain}'"
puts "Parsing zone for #{domain}"
generate_zone(file, domain)
f.puts "zone \"#{domain}\" IN { type master; file \"#{@config['zones_dir']}/#{domain}.zone\"; };"
......@@ -61,7 +70,7 @@ class ZoneGenerator
new_zonefile = zone.zonefile
# path to the deployed version
old_file = "#{@config['zones_dir']}/#{domain}.zone"
old_file = "#{@config['local_zones_dir']}/#{domain}.zone"
# is there already a deployed version?
if File.exists?(old_file)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment