Skip to content

Commit

Permalink
provider: Ensure cleanup happens
Browse files Browse the repository at this point in the history
  • Loading branch information
pillarsdotnet authored and kenyon committed Dec 8, 2022
1 parent ca58c1b commit 752a23b
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/puppet/provider/archive/ruby.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ def exists?
def create
transfer_download(archive_filepath) unless checksum?
extract
ensure
cleanup
end

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 752a23b

Please sign in to comment.