Skip to content

Commit

Permalink
Merge pull request #13215 from timvisher/fix/keep-info_name_dir-files…
Browse files Browse the repository at this point in the history
…-on-clean

Keep `info/#{f.name}/dir` files in cleaner
  • Loading branch information
MikeMcQuaid authored Apr 29, 2022
2 parents 607c7b6 + 0d81864 commit 2c0bd31
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 5 deletions.
24 changes: 23 additions & 1 deletion Library/Homebrew/cleaner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,31 @@ def clean
[@f.bin, @f.sbin, @f.lib].each { |d| clean_dir(d) if d.exist? }

# Get rid of any info 'dir' files, so they don't conflict at the link stage
#
# The 'dir' files come in at least 3 locations:
#
# 1. 'info/dir'
# 2. 'info/#{name}/dir'
# 3. 'info/#{arch}/dir'
#
# Of these 3 only 'info/#{name}/dir' is safe to keep since the rest will
# conflict with other formulae because they use a shared location.
#
# See [cleaner: recursively delete info `dir`s by gromgit · Pull Request
# #11597][1], [emacs 28.1 bottle does not contain `dir` file · Issue
# #100190][2], and [Keep `info/#{f.name}/dir` files in cleaner by
# timvisher][3] for more info.
#
# [1]: https://github.com/Homebrew/brew/pull/11597
# [2]: https://github.com/Homebrew/homebrew-core/issues/100190
# [3]: https://github.com/Homebrew/brew/pull/13215
Dir.glob(@f.info/"**/dir").each do |f|
info_dir_file = Pathname(f)
observe_file_removal info_dir_file if info_dir_file.file? && !@f.skip_clean?(info_dir_file)
next unless info_dir_file.file?
next if info_dir_file == @f.info/@f.name/"dir"
next if @f.skip_clean?(info_dir_file)

observe_file_removal info_dir_file
end

rewrite_shebangs
Expand Down
28 changes: 24 additions & 4 deletions Library/Homebrew/test/cleaner_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@
it "removes '.la' files" do
file = f.lib/"foo.la"

f.lib.mkpath
file.dirname.mkpath
touch file

cleaner.clean
Expand All @@ -107,7 +107,7 @@
it "removes 'perllocal' files" do
file = f.lib/"perl5/darwin-thread-multi-2level/perllocal.pod"

(f.lib/"perl5/darwin-thread-multi-2level").mkpath
file.dirname.mkpath
touch file

cleaner.clean
Expand All @@ -118,7 +118,7 @@
it "removes '.packlist' files" do
file = f.lib/"perl5/darwin-thread-multi-2level/auto/test/.packlist"

(f.lib/"perl5/darwin-thread-multi-2level/auto/test").mkpath
file.dirname.mkpath
touch file

cleaner.clean
Expand All @@ -129,12 +129,32 @@
it "removes 'charset.alias' files" do
file = f.lib/"charset.alias"

f.lib.mkpath
file.dirname.mkpath
touch file

cleaner.clean

expect(file).not_to exist
end

it "removes 'info/**/dir' files except for 'info/<name>/dir'" do
file = f.info/"dir"
arch_file = f.info/"i686-elf/dir"
name_file = f.info/f.name/"dir"

file.dirname.mkpath
arch_file.dirname.mkpath
name_file.dirname.mkpath

touch file
touch arch_file
touch name_file

cleaner.clean

expect(file).not_to exist
expect(arch_file).not_to exist
expect(name_file).to exist
end
end

Expand Down

0 comments on commit 2c0bd31

Please sign in to comment.