summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLamont Granquist <lamont@scriptkiddie.org>2018-02-02 11:09:43 -0800
committerLamont Granquist <lamont@scriptkiddie.org>2018-02-02 11:09:43 -0800
commit5df73f6fa1c607bf0cf6d1e2f09b533a4106c164 (patch)
tree257bba17510bf9e3ecdd6f767015ce7d17bbc6e9
parent75f1d2c8836a10ca5d2e427df465111c5351b3b6 (diff)
downloadchef-lcg/remote_file_cleanup_tempfiles.tar.gz
RemoteFile: unlink tempfile when using cache control shows unchangedlcg/remote_file_cleanup_tempfiles
We can get back a nil tempfile from the streaming downloader which means that we need to clean up our own tempfile since the base file provider will not do it for us. Signed-off-by: Lamont Granquist <lamont@scriptkiddie.org>
-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