diff options
Diffstat (limited to 'lib/chef/chef_fs/file_system.rb')
-rw-r--r-- | lib/chef/chef_fs/file_system.rb | 50 |
1 files changed, 25 insertions, 25 deletions
diff --git a/lib/chef/chef_fs/file_system.rb b/lib/chef/chef_fs/file_system.rb index 1805869e32..9ce4a23254 100644 --- a/lib/chef/chef_fs/file_system.rb +++ b/lib/chef/chef_fs/file_system.rb @@ -113,15 +113,15 @@ class Chef # puts message # end # - def self.copy_to(pattern, src_root, dest_root, recurse_depth, options) + def self.copy_to(pattern, src_root, dest_root, recurse_depth, options, ui) found_result = false list_pairs(pattern, src_root, dest_root) do |src, dest| found_result = true - new_dest_parent = get_or_create_parent(dest, options) - copy_entries(src, dest, new_dest_parent, recurse_depth, options) + new_dest_parent = get_or_create_parent(dest, options, ui) + copy_entries(src, dest, new_dest_parent, recurse_depth, options, ui) end if !found_result && pattern.exact_path - puts "#{pattern}: No such file or directory on remote or local" + ui.error "#{pattern}: No such file or directory on remote or local" end end @@ -216,7 +216,7 @@ class Chef private # Copy two entries (could be files or dirs) - def self.copy_entries(src_entry, dest_entry, new_dest_parent, recurse_depth, options) + def self.copy_entries(src_entry, dest_entry, new_dest_parent, recurse_depth, options, ui) # A NOTE about this algorithm: # There are cases where this algorithm does too many network requests. # knife upload with a specific filename will first check if the file @@ -233,10 +233,10 @@ class Chef # If we would not have uploaded it, we will not purge it. if src_entry.parent.can_have_child?(dest_entry.name, dest_entry.dir?) if options[:dry_run] - puts "Would delete #{dest_entry.path_for_printing}" + ui.output "Would delete #{dest_entry.path_for_printing}" else dest_entry.delete(true) - puts "Deleted extra entry #{dest_entry.path_for_printing} (purge is on)" + ui.output "Deleted extra entry #{dest_entry.path_for_printing} (purge is on)" end else Chef::Log.info("Not deleting extra entry #{dest_entry.path_for_printing} (purge is off)") @@ -248,35 +248,35 @@ class Chef # If the entry can do a copy directly from filesystem, do that. if new_dest_parent.respond_to?(:create_child_from) if options[:dry_run] - puts "Would create #{dest_entry.path_for_printing}" + ui.output "Would create #{dest_entry.path_for_printing}" else new_dest_parent.create_child_from(src_entry) - puts "Created #{dest_entry.path_for_printing}" + ui.output "Created #{dest_entry.path_for_printing}" end return end if src_entry.dir? if options[:dry_run] - puts "Would create #{dest_entry.path_for_printing}" + ui.output "Would create #{dest_entry.path_for_printing}" new_dest_dir = new_dest_parent.child(src_entry.name) else new_dest_dir = new_dest_parent.create_child(src_entry.name, nil) - puts "Created #{dest_entry.path_for_printing}/" + ui.output "Created #{dest_entry.path_for_printing}/" end # Directory creation is recursive. if recurse_depth != 0 src_entry.children.each do |src_child| new_dest_child = new_dest_dir.child(src_child.name) - copy_entries(src_child, new_dest_child, new_dest_dir, recurse_depth ? recurse_depth - 1 : recurse_depth, options) + copy_entries(src_child, new_dest_child, new_dest_dir, recurse_depth ? recurse_depth - 1 : recurse_depth, options, ui) end end else if options[:dry_run] - puts "Would create #{dest_entry.path_for_printing}" + ui.output "Would create #{dest_entry.path_for_printing}" else new_dest_parent.create_child(src_entry.name, src_entry.read) - puts "Created #{dest_entry.path_for_printing}" + ui.output "Created #{dest_entry.path_for_printing}" end end end @@ -288,10 +288,10 @@ class Chef if dest_entry.respond_to?(:copy_from) if options[:force] || compare(src_entry, dest_entry)[0] == false if options[:dry_run] - puts "Would update #{dest_entry.path_for_printing}" + ui.output "Would update #{dest_entry.path_for_printing}" else dest_entry.copy_from(src_entry) - puts "Updated #{dest_entry.path_for_printing}" + ui.output "Updated #{dest_entry.path_for_printing}" end end return @@ -303,17 +303,17 @@ class Chef # If both are directories, recurse into their children if recurse_depth != 0 child_pairs(src_entry, dest_entry).each do |src_child, dest_child| - copy_entries(src_child, dest_child, dest_entry, recurse_depth ? recurse_depth - 1 : recurse_depth, options) + copy_entries(src_child, dest_child, dest_entry, recurse_depth ? recurse_depth - 1 : recurse_depth, options, ui) end end else # If they are different types. - Chef::Log.error("File #{dest_entry.path_for_printing} is a directory while file #{dest_entry.path_for_printing} is a regular file\n") + ui.error("File #{dest_entry.path_for_printing} is a directory while file #{dest_entry.path_for_printing} is a regular file\n") return end else if dest_entry.dir? - Chef::Log.error("File #{dest_entry.path_for_printing} is a directory while file #{dest_entry.path_for_printing} is a regular file\n") + ui.error("File #{dest_entry.path_for_printing} is a directory while file #{dest_entry.path_for_printing} is a regular file\n") return else @@ -327,11 +327,11 @@ class Chef end if should_copy if options[:dry_run] - puts "Would update #{dest_entry.path_for_printing}" + ui.output "Would update #{dest_entry.path_for_printing}" else src_value = src_entry.read if src_value.nil? dest_entry.write(src_value) - puts "Updated #{dest_entry.path_for_printing}" + ui.output "Updated #{dest_entry.path_for_printing}" end end end @@ -339,15 +339,15 @@ class Chef end end - def self.get_or_create_parent(entry, options) + def self.get_or_create_parent(entry, options, ui) parent = entry.parent if parent && !parent.exists? - parent_parent = get_or_create_parent(entry.parent, options) + parent_parent = get_or_create_parent(entry.parent, options, ui) if options[:dry_run] - puts "Would create #{parent.path_for_printing}" + ui.output "Would create #{parent.path_for_printing}" else parent = parent_parent.create_child(parent.name, true) - puts "Created #{parent.path_for_printing}" + ui.output "Created #{parent.path_for_printing}" end end return parent |