From dfb4ad46096d3308bcc31efc3220b2d75dba96ef Mon Sep 17 00:00:00 2001 From: Jay Mundrawala Date: Tue, 30 Sep 2014 11:03:23 -0700 Subject: Refactor action_create in remote_directory provider --- lib/chef/provider/remote_directory.rb | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/lib/chef/provider/remote_directory.rb b/lib/chef/provider/remote_directory.rb index 874c6f8e1f..5bd1cb5493 100644 --- a/lib/chef/provider/remote_directory.rb +++ b/lib/chef/provider/remote_directory.rb @@ -37,12 +37,9 @@ class Chef def action_create super # Mark all files as needing to be purged - files_to_purge = Set.new(Dir.glob(::File.join(Chef::Util::PathHelper.escape_glob(@new_resource.path), '**', '*'), - ::File::FNM_DOTMATCH).select do |name| - # Everything except current directory and previous directory - basename = Pathname.new(name).basename().to_s - ['.', '..'].all? {|n| n != basename} - end).map! {|i| Chef::Util::PathHelper.cleanpath(i)} # Make sure each path is clean + files_to_purge = Set.new(ls(@new_resource.path)) # Make sure each path is clean + + # Transfer files files_to_transfer.each do |cookbook_file_relative_path| create_cookbook_file(cookbook_file_relative_path) # parent directories and file being transfered are removed from the purge list @@ -62,6 +59,21 @@ class Chef protected + # List all excluding . and .. + def ls(path) + files = Dir.glob(::File.join(Chef::Util::PathHelper.escape_glob(path), '**', '*'), + ::File::FNM_DOTMATCH) + + # Remove current directory and previous directory + files.reject! do |name| + basename = Pathname.new(name).basename().to_s + ['.', '..'].include?(basename) + end + + # Clean all the paths... this is required because of the join + files.map {|f| Chef::Util::PathHelper.cleanpath(f)} + end + def purge_unmanaged_files(unmanaged_files) if @new_resource.purge unmanaged_files.sort.reverse.each do |f| -- cgit v1.2.1