From 5701f92321e04a0e994f581ccbac749c64de5e73 Mon Sep 17 00:00:00 2001 From: Sam Ford <1584702+samford@users.noreply.github.com> Date: Fri, 24 May 2024 09:22:12 -0400 Subject: [PATCH] Clean up cask audit tmpdir after use `Cask::Audit#extract_artifacts` is used in the `#audit_signing` and `#cask_plist_min_os` methods to create a directory in `/tmp` and extract cask artifacts without duplicating the work if it's already done. However, due to how this is set up, `tmpdir` isn't removed afterward and the extracted artifacts will take up disk space until the `tmp` directory is cleaned up. As a result, running `brew audit --strict --online` locally can chew through disk space and it may not be clear to the user where their free space has gone. This adds a finalizer method to `Cask::Audit` to remove the created `@tmpdir` (if any) once it's no longer needed. There may be a better way of addressing the issue but this works for now without having to restructure how these audits work. --- Library/Homebrew/cask/audit.rb | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Library/Homebrew/cask/audit.rb b/Library/Homebrew/cask/audit.rb index d27f7c576174c..ffa47e73948ba 100644 --- a/Library/Homebrew/cask/audit.rb +++ b/Library/Homebrew/cask/audit.rb @@ -47,6 +47,12 @@ 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!