From e2220ecc42428b62826359e73eb75c5573e86941 Mon Sep 17 00:00:00 2001 From: Sam Ford <1584702+samford@users.noreply.github.com> Date: Mon, 27 May 2024 13:09:46 -0400 Subject: [PATCH] cask/audit: Rework tmpdir removal I previously introduced a finalizer method in `Cask::Audit` to remove the created `@tmpdir` once it's no longer needed but the existing approach produces a `finalizer references object to be finalized` warning when `brew audit` is run. I didn't see this warning when I was originally testing it but now it reliably appears. This reworks the finalizer to define it within the `#extract_artifacts` method and use `@tmpdir` as the target object. --- Library/Homebrew/cask/audit.rb | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Library/Homebrew/cask/audit.rb b/Library/Homebrew/cask/audit.rb index 38c0271e1a4a4..54156fc69cfbf 100644 --- a/Library/Homebrew/cask/audit.rb +++ b/Library/Homebrew/cask/audit.rb @@ -47,12 +47,6 @@ def initialize( @token_conflicts = token_conflicts @only = only || [] @except = except || [] - - # Clean up `#extract_artifacts` tmp dir when Audit object is destroyed - ObjectSpace.define_finalizer( - self, - proc { FileUtils.remove_entry(@tmpdir) if @tmpdir }, - ) end def run! @@ -540,6 +534,12 @@ def extract_artifacts @tmpdir ||= Pathname(Dir.mktmpdir("cask-audit", HOMEBREW_TEMP)) + # Clean up tmp dir when @tmpdir object is destroyed + ObjectSpace.define_finalizer( + @tmpdir, + proc { FileUtils.remove_entry(@tmpdir) }, + ) + ohai "Downloading and extracting artifacts" downloaded_path = download.fetch