diff options
author | Jay Mundrawala <jdmundrawala@gmail.com> | 2014-09-30 11:03:23 -0700 |
---|---|---|
committer | Jay Mundrawala <jdmundrawala@gmail.com> | 2014-09-30 11:30:43 -0700 |
commit | dfb4ad46096d3308bcc31efc3220b2d75dba96ef (patch) | |
tree | 04d0a9ec89f58b65371e5f3f9aee0b3af4b275d4 | |
parent | aa3157948cfab9ea6e4944f9fe7a6be285a2aaed (diff) | |
download | chef-jdmundrawala/remote-directory-fix.tar.gz |
Refactor action_create in remote_directory providerjdmundrawala/remote-directory-fix
-rw-r--r-- | lib/chef/provider/remote_directory.rb | 24 |
1 files 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| |