summaryrefslogtreecommitdiff
path: root/lib/chef
diff options
context:
space:
mode:
authorLamont Granquist <lamont@scriptkiddie.org>2018-02-13 12:45:25 -0800
committerGitHub <noreply@github.com>2018-02-13 12:45:25 -0800
commit63cf453069efa5606dc8f8a06a38b02ab71e27b6 (patch)
treea4e7ecac7c0d82a937069cc3a46a18f05208ec08 /lib/chef
parentaf4db730bb7ae2e03b6fd6ce7d2b74d2ef2e3336 (diff)
parentffb063c74263ef04440e7887e5265f1c58844890 (diff)
downloadchef-63cf453069efa5606dc8f8a06a38b02ab71e27b6.tar.gz
Merge pull request #6822 from chef/lcg/remote_file_cleanup_tempfiles
RemoteFile: unlink tempfile when using cache control shows unchanged
Diffstat (limited to 'lib/chef')
-rw-r--r--lib/chef/provider/remote_file/http.rb11
1 files changed, 8 insertions, 3 deletions
diff --git a/lib/chef/provider/remote_file/http.rb b/lib/chef/provider/remote_file/http.rb
index 4732253e5b..8dfa84ee2a 100644
--- a/lib/chef/provider/remote_file/http.rb
+++ b/lib/chef/provider/remote_file/http.rb
@@ -61,17 +61,22 @@ class Chef
def fetch
http = Chef::HTTP::Simple.new(uri, http_client_opts)
- tempfile = Chef::FileContentManagement::Tempfile.new(@new_resource).tempfile
+ orig_tempfile = Chef::FileContentManagement::Tempfile.new(@new_resource).tempfile
if want_progress?
- tempfile = http.streaming_request_with_progress(uri, headers, tempfile) do |size, total|
+ tempfile = http.streaming_request_with_progress(uri, headers, orig_tempfile) do |size, total|
events.resource_update_progress(new_resource, size, total, progress_interval)
end
else
- tempfile = http.streaming_request(uri, headers, tempfile)
+ tempfile = http.streaming_request(uri, headers, orig_tempfile)
end
if tempfile
update_cache_control_data(tempfile, http.last_response)
tempfile.close
+ else
+ # cache_control shows the file is unchanged, so we got back nil from the streaming_request above, and it is
+ # now our responsibility to unlink the tempfile we created
+ orig_tempfile.close
+ orig_tempfile.unlink
end
tempfile
end