summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/chef/provider/remote_directory.rb24
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|