Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ruby provider: ensure cleanup happens #474

Merged
merged 2 commits into from
Apr 13, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
pillarsdotnet marked this conversation as resolved.
Show resolved Hide resolved
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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Technically you can rm_f a file that does not exist (because force is only about ignoring errors). Checking for existence does not hurt though, so I am fine with this.

end

def move_file_in_place(from, to)
Expand Down