From 752a23b7e769d4f2b369f32a2c2e18ab5c21de7e Mon Sep 17 00:00:00 2001 From: Robert August Vincent II Date: Thu, 29 Sep 2022 15:52:12 -0400 Subject: [PATCH] provider: Ensure cleanup happens Fixes #328 --- lib/puppet/provider/archive/ruby.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/puppet/provider/archive/ruby.rb b/lib/puppet/provider/archive/ruby.rb index 213362ca..408b804e 100644 --- a/lib/puppet/provider/archive/ruby.rb +++ b/lib/puppet/provider/archive/ruby.rb @@ -84,6 +84,7 @@ def exists? def create transfer_download(archive_filepath) unless checksum? extract + ensure cleanup end @@ -144,7 +145,7 @@ def checksum?(store_checksum = true) end def cleanup - return unless extracted? && resource[:cleanup] == :true + return unless resource[:cleanup] == :true && resource[:extract] == :true Puppet.debug("Cleanup archive #{archive_filepath}") destroy @@ -201,12 +202,13 @@ def transfer_download(archive_filepath) actual_checksum = archive.checksum(resource[:checksum_type]) if actual_checksum != checksum destroy - FileUtils.rm_f(temppath) if File.exist?(temppath) raise(Puppet::Error, "Download file checksum mismatch (expected: #{checksum} actual: #{actual_checksum})") end end move_file_in_place(temppath, archive_filepath) + ensure + FileUtils.rm_f(temppath) if File.exist?(temppath) end def move_file_in_place(from, to)