diff options
Diffstat (limited to 'lib/chef/provider')
-rw-r--r-- | lib/chef/provider/cookbook_file.rb | 3 | ||||
-rw-r--r-- | lib/chef/provider/file.rb | 25 | ||||
-rw-r--r-- | lib/chef/provider/remote_directory.rb | 39 |
3 files changed, 45 insertions, 22 deletions
diff --git a/lib/chef/provider/cookbook_file.rb b/lib/chef/provider/cookbook_file.rb index 431f3f2367..144afbddeb 100644 --- a/lib/chef/provider/cookbook_file.rb +++ b/lib/chef/provider/cookbook_file.rb @@ -44,9 +44,6 @@ class Chef Chef::Log.debug("#{@new_resource} staging #{file_cache_location} to #{tempfile.path}") tempfile.close FileUtils.cp(file_cache_location, tempfile.path) - # Since the @new_resource.path file will not be updated - # at the time of converge, we must use the tempfile - update_new_file_state(tempfile.path) end Chef::Log.info("#{@new_resource} created file #{@new_resource.path}") end diff --git a/lib/chef/provider/file.rb b/lib/chef/provider/file.rb index 659afc6517..77f5217027 100644 --- a/lib/chef/provider/file.rb +++ b/lib/chef/provider/file.rb @@ -132,7 +132,9 @@ class Chef @current_resource.path(@new_resource.path) if !::File.directory?(@new_resource.path) if ::File.exist?(@new_resource.path) - @current_resource.checksum(checksum(@new_resource.path)) + if @action != :create_if_missing + @current_resource.checksum(checksum(@new_resource.path)) + end end end load_current_resource_attrs @@ -142,6 +144,13 @@ class Chef end def load_current_resource_attrs + if Chef::Platform.windows? + # TODO: To work around CHEF-3554, add support for Windows + # equivalent, or implicit resource reporting won't work for + # Windows. + return + end + if ::File.exist?(@new_resource.path) stat = ::File.stat(@new_resource.path) @current_resource.owner(stat.uid) @@ -215,13 +224,21 @@ class Chef # override the default with the tempfile, since the # file at @new_resource.path will not be updated on converge def update_new_file_state(path=@new_resource.path) + if !::File.directory?(path) + @new_resource.checksum(checksum(path)) + end + + if Chef::Platform.windows? + # TODO: To work around CHEF-3554, add support for Windows + # equivalent, or implicit resource reporting won't work for + # Windows. + return + end + stat = ::File.stat(path) @new_resource.owner(stat.uid) @new_resource.mode(stat.mode & 07777) @new_resource.group(stat.gid) - if !::File.directory?(path) - @new_resource.checksum(checksum(path)) - end end def action_create diff --git a/lib/chef/provider/remote_directory.rb b/lib/chef/provider/remote_directory.rb index 9ccd7ea056..dee383f763 100644 --- a/lib/chef/provider/remote_directory.rb +++ b/lib/chef/provider/remote_directory.rb @@ -34,23 +34,27 @@ class Chef def action_create super - - files_to_purge = Set.new( - Dir.glob(::File.join(@new_resource.path, '**', '*'), ::File::FNM_DOTMATCH).select do |name| - name !~ /(?:^|#{Regexp.escape(::File::SEPARATOR)})\.\.?$/ - end - ) - 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])) + files_to_purge = Set.new(Dir.glob(::File.join(@new_resource.path, '**', '*'), + ::File::FNM_DOTMATCH).select do |name| + name !~ /(?:^|#{Regexp.escape(::File::SEPARATOR)})\.\.?$/ + end) + + converge_by("Create managed files in directory") do + 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])) + end end end - purge_unmanaged_files(files_to_purge) + + converge_by("Purge unmanaged files from directory") do + purge_unmanaged_files(files_to_purge) + end end def action_create_if_missing @@ -170,5 +174,10 @@ class Chef end end + + def whyrun_supported? + true + end + end end |