Class: Cleaner

Inherits:
Object show all
Includes:
Context
Defined in:
extend/os/mac/cleaner.rb,
extend/os/linux/cleaner.rb,
cleaner.rb

Overview

Cleans a newly installed keg. By default:

  • removes .la files
  • removes perllocal.pod files
  • removes .packlist files
  • removes empty directories
  • sets permissions on executables
  • removes unresolved symlinks

Instance Method Summary collapse

Methods included from Context

current, current=, #debug?, #quiet?, #verbose?, #with_context

Constructor Details

#initialize(formula) ⇒ Cleaner

Create a cleaner for the given formula.



17
18
19
# File 'cleaner.rb', line 17

def initialize(formula)
  @formula = formula
end

Instance Method Details

#cleanObject

Clean the keg of the formula.



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'cleaner.rb', line 22

def clean
  ObserverPathnameExtension.reset_counts!

  # Many formulae include 'lib/charset.alias', but it is not strictly needed
  # and will conflict if more than one formula provides it
  observe_file_removal @formula.lib/"charset.alias"

  [@formula.bin, @formula.sbin, @formula.lib].each { |dir| clean_dir(dir) if dir.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(@formula.info/"**/dir").each do |file|
    info_dir_file = Pathname(file)
    next unless info_dir_file.file?
    next if info_dir_file == @formula.info/@formula.name/"dir"
    next if @formula.skip_clean?(info_dir_file)

    observe_file_removal info_dir_file
  end

  rewrite_shebangs

  prune
end