lib/helpers.rb in puppet-retrospec-0.3.0 vs lib/helpers.rb in puppet-retrospec-0.4.0

- old
+ new

@@ -54,14 +54,13 @@ end # creates and/or copies all templates in the gem to the user templates path # returns: user_template_dir def self.sync_user_template_dir(user_template_directory) - Dir.glob(File.join(gem_template_dir, "*.erb")).each do |src| - filename = File.basename(src) - dest = File.expand_path(File.join(user_template_directory, filename)) - safe_copy_file(src, dest) + Dir.glob(File.join(gem_template_dir, '**', '*')).each do |src| + dest = src.gsub(gem_template_dir, user_template_directory) + safe_copy_file(src, dest) unless File.directory?(src) end user_template_directory end # creates and syncs the specifed user template diretory @@ -80,16 +79,17 @@ def self.gem_template_dir File.expand_path(File.join(File.dirname(__FILE__), 'templates')) end def self.safe_copy_file(src, dest) - if File.exists?(dest) + if File.exists?(dest) and not File.zero?(dest) $stderr.puts "!! #{dest} already exists" else if not File.exists?(src) safe_touch(src) else + safe_mkdir(File.dirname(dest)) FileUtils.cp(src,dest) end puts " + #{dest}" end end @@ -106,10 +106,11 @@ end def self.safe_create_file(filename, content) if File.exists? filename old_content = File.read(filename) - if old_content != content + # if we did a better comparison of content we could be smarter about when we create files + if old_content != content or not File.zero?(filename) $stderr.puts "!! #{filename} already exists and differs from template" end else File.open(filename, 'w') do |f| f.puts content