style: resolve symblic links in HOMEBREW_CACHE

On Linux HOMEBREW_CACHE may be set to `$HOME/.cache/Homebrew`. Some
systems, like Fedora Silverblue, have `/home` set up to be a symbolic
link to `/var/home`. While Homebrew generally seems to work fine on
Fedora Silverblue, rubocop causes the `brew style` command to emit
a lot of warnings because of the symbolic link[1]. This can be resolved
by looking up the real path of HOMEBREW_CACHE before passing it to rubocop.

[1] https://github.com/rubocop/rubocop/issues/6228

Co-authored-by: Bo Anderson <mail@boanderson.me>
This commit is contained in:
notfirefox 2024-09-14 18:57:45 +02:00
parent 1f306b4d15
commit bb4208ebf1

View File

@ -164,7 +164,9 @@ module Homebrew
args += files
cache_env = { "XDG_CACHE_HOME" => "#{HOMEBREW_CACHE}/style" }
HOMEBREW_CACHE.mkpath
cache_dir = HOMEBREW_CACHE.realpath
cache_env = { "XDG_CACHE_HOME" => "#{cache_dir}/style" }
FileUtils.rm_rf cache_env["XDG_CACHE_HOME"] if reset_cache