Skip to content

Commit

Permalink
Clean up cask audit tmpdir after use
Browse files Browse the repository at this point in the history
`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.
  • Loading branch information
samford committed May 24, 2024
1 parent ea5023a commit 5701f92
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions Library/Homebrew/cask/audit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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(

Check warning on line 52 in Library/Homebrew/cask/audit.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/cask/audit.rb#L52

Added line #L52 was not covered by tests
self,
proc { FileUtils.remove_entry(@tmpdir) if @tmpdir },
)
end

def run!
Expand Down

0 comments on commit 5701f92

Please sign in to comment.