diff options
author | Jay Mundrawala <jdmundrawala@gmail.com> | 2014-09-30 13:14:19 -0700 |
---|---|---|
committer | Jay Mundrawala <jdmundrawala@gmail.com> | 2014-09-30 13:14:19 -0700 |
commit | 80763a883926d128f3068ab7ef6987062a1f4fc2 (patch) | |
tree | 70c5023d2077e792af96e57432ebf86b720c0f6e | |
parent | 807c4fa0a1d8986eb041c1c576ed441a47422ad2 (diff) | |
parent | dfb4ad46096d3308bcc31efc3220b2d75dba96ef (diff) | |
download | chef-80763a883926d128f3068ab7ef6987062a1f4fc2.tar.gz |
Merge pull request #2133 from opscode/jdmundrawala/remote-directory-fix
Remote directory should pass specs
-rw-r--r-- | lib/chef/provider/remote_directory.rb | 32 |
1 files changed, 22 insertions, 10 deletions
diff --git a/lib/chef/provider/remote_directory.rb b/lib/chef/provider/remote_directory.rb index 553eb14ae5..5bd1cb5493 100644 --- a/lib/chef/provider/remote_directory.rb +++ b/lib/chef/provider/remote_directory.rb @@ -36,21 +36,18 @@ class Chef def action_create super - files_to_purge = Set.new(Dir.glob(::File.join(Chef::Util::PathHelper.escape_glob(@new_resource.path), '**', '*'), - ::File::FNM_DOTMATCH).select do |name| - name !~ /(?:^|#{Regexp.escape(::File::SEPARATOR)})\.\.?$/ - end) + # Mark all files as needing to be purged + 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) - # the file is removed from the purge list - files_to_purge.delete(::File.join(@new_resource.path, cookbook_file_relative_path)) - # parent directories are also removed from the purge list - directories=::File.dirname(::File.join(@new_resource.path, cookbook_file_relative_path)).split(::File::SEPARATOR) - for i in 0..directories.length-1 - files_to_purge.delete(::File.join(directories[0..i])) + # parent directories and file being transfered are removed from the purge list + Pathname.new(Chef::Util::PathHelper.cleanpath(::File.join(@new_resource.path, cookbook_file_relative_path))).descend do |d| + files_to_purge.delete(d.to_s) end end + purge_unmanaged_files(files_to_purge) end @@ -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| |