Module: Utils::Path Private
- Included in:
- Cask::DSL, Cask::DSL::Base, Formula, Homebrew::Service
- Defined in:
- utils/path.rb
Overview
This module is part of a private API. This module may only be used in the Homebrew/brew repository. Third parties should avoid using this module if possible, as it may be removed or changed without warning.
Helpers for Homebrew path handling and package path validation.
Class Method Summary collapse
- .child_of?(parent, child) ⇒ Boolean private
- .formula_any_version_installed?(formula_names) ⇒ Boolean
Whether any installed keg for one or more formula names has an install receipt.
- .formula_installed_prefixes(formula_names) ⇒ Array<Pathname>
The installed prefix directories for one or more formula names.
- .formula_opt_bin(formula_name) ⇒ Pathname
The
bindirectory under the stable install path for a given formula name. - .formula_opt_bin_env(formula_name, *paths) ⇒ Hash{String => String}
An environment hash with
PATHprepended by a formula's stablebindirectory. - .formula_opt_bin_path(formula_name, *paths) ⇒ PATH
The current
PATHwith a formula's stablebindirectory prepended. - .formula_opt_include(formula_name) ⇒ Pathname
The
includedirectory under the stable install path for a given formula name. - .formula_opt_lib(formula_name) ⇒ Pathname
The
libdirectory under the stable install path for a given formula name. - .formula_opt_libexec(formula_name) ⇒ Pathname
The
libexecdirectory under the stable install path for a given formula name. - .formula_opt_prefix(formula_name) ⇒ Pathname
The stable install path for a given formula name.
- .loadable_package_path?(path, package_type) ⇒ Boolean private
Instance Method Summary collapse
- #formula_any_version_installed?(formula_names) ⇒ Boolean
Whether any installed keg for one or more formula names has an install receipt.
- #formula_opt_bin(formula_name) ⇒ Pathname
The
bindirectory under the stable install path for a given formula name. - #formula_opt_include(formula_name) ⇒ Pathname
The
includedirectory under the stable install path for a given formula name. - #formula_opt_lib(formula_name) ⇒ Pathname
The
libdirectory under the stable install path for a given formula name. - #formula_opt_libexec(formula_name) ⇒ Pathname
The
libexecdirectory under the stable install path for a given formula name. - #formula_opt_prefix(formula_name) ⇒ Pathname
The stable install path for a given formula name.
Class Method Details
.child_of?(parent, child) ⇒ Boolean
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
10 11 12 13 14 15 | # File 'utils/path.rb', line 10 def self.child_of?(parent, child) parent_pathname = Pathname(parent). child_pathname = Pathname(child). child_pathname.ascend { |p| return true if p == parent_pathname } false end |
.formula_any_version_installed?(formula_names) ⇒ Boolean
Whether any installed keg for one or more formula names has an install receipt.
112 113 114 | # File 'utils/path.rb', line 112 def self.formula_any_version_installed?(formula_names) formula_installed_prefixes(formula_names).any? { |keg| (keg/"INSTALL_RECEIPT.json").file? } end |
.formula_installed_prefixes(formula_names) ⇒ Array<Pathname>
The installed prefix directories for one or more formula names.
101 102 103 104 105 106 | # File 'utils/path.rb', line 101 def self.formula_installed_prefixes(formula_names) Array(formula_names).map { |formula_name| HOMEBREW_CELLAR/Utils.name_from_full_name(formula_name) } .select(&:directory?) .flat_map(&:subdirs) .sort_by(&:basename) end |
.formula_opt_bin(formula_name) ⇒ Pathname
The bin directory under the stable install path for a given formula name.
37 38 39 | # File 'utils/path.rb', line 37 def self.formula_opt_bin(formula_name) formula_opt_prefix(formula_name)/"bin" end |
.formula_opt_bin_env(formula_name, *paths) ⇒ Hash{String => String}
An environment hash with PATH prepended by a formula's stable bin directory.
136 137 138 | # File 'utils/path.rb', line 136 def self.formula_opt_bin_env(formula_name, *paths) { "PATH" => formula_opt_bin_path(formula_name, *paths).to_s } end |
.formula_opt_bin_path(formula_name, *paths) ⇒ PATH
The current PATH with a formula's stable bin directory prepended.
128 129 130 | # File 'utils/path.rb', line 128 def self.formula_opt_bin_path(formula_name, *paths) PATH.new(formula_opt_bin(formula_name), *paths, ENV.fetch("PATH")) end |
.formula_opt_include(formula_name) ⇒ Pathname
The include directory under the stable install path for a given formula name.
85 86 87 | # File 'utils/path.rb', line 85 def self.formula_opt_include(formula_name) formula_opt_prefix(formula_name)/"include" end |
.formula_opt_lib(formula_name) ⇒ Pathname
The lib directory under the stable install path for a given formula name.
53 54 55 | # File 'utils/path.rb', line 53 def self.formula_opt_lib(formula_name) formula_opt_prefix(formula_name)/"lib" end |
.formula_opt_libexec(formula_name) ⇒ Pathname
The libexec directory under the stable install path for a given formula name.
69 70 71 | # File 'utils/path.rb', line 69 def self.formula_opt_libexec(formula_name) formula_opt_prefix(formula_name)/"libexec" end |
.formula_opt_prefix(formula_name) ⇒ Pathname
The stable install path for a given formula name.
21 22 23 | # File 'utils/path.rb', line 21 def self.formula_opt_prefix(formula_name) HOMEBREW_PREFIX/"opt/#{Utils.name_from_full_name(formula_name)}" end |
.loadable_package_path?(path, package_type) ⇒ Boolean
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 | # File 'utils/path.rb', line 141 def self.loadable_package_path?(path, package_type) return true unless Homebrew::EnvConfig.forbid_packages_from_paths? path_realpath = path.realpath.to_s path_string = path.to_s allowed_paths = [trusted_package_root("#{HOMEBREW_LIBRARY}/Taps/")] allowed_paths << if package_type == :formula trusted_package_root(HOMEBREW_CELLAR) else trusted_package_root(Cask::Caskroom.path) end # Casks can also be loaded from local JSON files, not just Ruby. package_extnames = (package_type == :cask) ? %w[.rb.json] : %w[.rb] return true if package_extnames.none? { |ext| path_realpath.end_with?(ext) || path_string.end_with?(ext) } # Compare path ancestry, not string prefixes, so `..` can't escape a trusted root. return true if allowed_paths.any? { |root| child_of?(root, path_realpath) } return true if allowed_paths.any? { |root| child_of?(root, path) } # Looks like a local path, Ruby file and not a tap. if path_string.include?("./") || path_string.end_with?(".rb") || path_string.count("/") != 2 package_type_plural = Utils.pluralize(package_type.to_s, 2) path_realpath_if_different = " (#{path_realpath})" if path_realpath != path_string create_flag = " --cask" if package_type == :cask raise <<~WARNING Homebrew requires #{package_type_plural} to be in a tap, rejecting: #{path_string}#{path_realpath_if_different} To create a tap, run e.g. brew tap-new <user|org>/<repository> To create a #{package_type} in a tap run e.g. brew create#{create_flag} <url> --tap=<user|org>/<repository> WARNING else # Looks like a tap, let's quietly reject but not error. path_string.count("/") != 2 end end |
Instance Method Details
#formula_any_version_installed?(formula_names) ⇒ Boolean
Whether any installed keg for one or more formula names has an install receipt.
120 121 122 | # File 'utils/path.rb', line 120 def formula_any_version_installed?(formula_names) Utils::Path.formula_any_version_installed?(formula_names) end |
#formula_opt_bin(formula_name) ⇒ Pathname
The bin directory under the stable install path for a given formula name.
45 46 47 | # File 'utils/path.rb', line 45 def formula_opt_bin(formula_name) Utils::Path.formula_opt_bin(formula_name) end |
#formula_opt_include(formula_name) ⇒ Pathname
The include directory under the stable install path for a given formula name.
93 94 95 | # File 'utils/path.rb', line 93 def formula_opt_include(formula_name) Utils::Path.formula_opt_include(formula_name) end |
#formula_opt_lib(formula_name) ⇒ Pathname
The lib directory under the stable install path for a given formula name.
61 62 63 | # File 'utils/path.rb', line 61 def formula_opt_lib(formula_name) Utils::Path.formula_opt_lib(formula_name) end |
#formula_opt_libexec(formula_name) ⇒ Pathname
The libexec directory under the stable install path for a given formula name.
77 78 79 | # File 'utils/path.rb', line 77 def formula_opt_libexec(formula_name) Utils::Path.formula_opt_libexec(formula_name) end |
#formula_opt_prefix(formula_name) ⇒ Pathname
The stable install path for a given formula name.
29 30 31 | # File 'utils/path.rb', line 29 def formula_opt_prefix(formula_name) Utils::Path.formula_opt_prefix(formula_name) end |
© 2009–present Homebrew contributors
Licensed under the BSD 2-Clause License.
https://docs.brew.sh/rubydoc/Utils/Path.html