Class: Pathname Private
- Defined in:
- extend/pathname.rb,
extend/blank/pathname.rb
This class is part of a private API. This class may only be used in the Homebrew/brew repository. Third parties should avoid using this class if possible, as it may be removed or changed without warning.
Direct Known Subclasses
Constant Summary
Constants included from EagerInitializeExtension
EagerInitializeExtension::NilableInteger
Class Method Summary collapse
- .activate_extensions! ⇒ void private
Instance Method Summary collapse
-
#append_lines(content, **open_args) ⇒ void
Only appends to a file that is already created.
- #arch_compatible?(_wanted_arch) ⇒ Boolean private
-
#atomic_write(content) ⇒ void
Write to a file atomically.
- #binary_executable? ⇒ Boolean private
-
#blank? ⇒ Boolean
private
A Pathname is blank if its path is empty.
-
#cd(&_block) ⇒ T.type_parameter(:U)
Change to this directory, optionally executing the given block.
- #cp_path_sub(pattern, replacement, &block) ⇒ void private
- #dylib? ⇒ Boolean private
- #ensure_writable(&block) ⇒ void private
-
#env_script_all_files(dst, env) ⇒ void
Writes a wrapper env script and moves all files to the dst.
-
#extname ⇒ String
Extended to support common double extensions.
-
#install(*sources) ⇒ void
Moves a file from the original location to the Pathname's.
- #install_info ⇒ void private
- #install_metafiles(from = Pathname.pwd) ⇒ void private
-
#install_symlink(*sources) ⇒ void
Creates symlinks to sources in this folder.
- #mach_o_bundle? ⇒ Boolean private
- #make_relative_symlink(src) ⇒ void private
- #present? ⇒ Boolean private
- #resolved_path ⇒ Pathname private
- #resolved_path_exists? ⇒ Boolean private
- #rmdir_if_possible ⇒ Boolean private
- #rpaths ⇒ Array<String> private
- #sha256 ⇒ String private
-
#stem ⇒ String
For filetypes we support, returns basename without extension.
-
#subdirs ⇒ Array<Pathname>
Get all sub-directories of this directory.
- #text_executable? ⇒ Boolean private
- #uninstall_info ⇒ void private
- #verify_checksum(expected) ⇒ void private
- #version ⇒ Version private
-
#write_env_script(target, args_or_env, env = nil) ⇒ void
Writes an exec script that sets environment variables.
-
#write_exec_script(*targets) ⇒ void
Writes an exec script in this folder for each target pathname.
-
#write_jar_script(target_jar, script_name, java_opts = "", java_version: nil) ⇒ Integer
Writes an exec script that invokes a Java jar.
Methods included from Utils::Output::Mixin
#issue_reporting_message, #odebug, #odeprecated, #odie, #odisabled, #ofail, #oh1, #oh1_title, #ohai, #ohai_title, #onoe, #opoo, #opoo_outside_github_actions, #opoo_without_github_actions_annotation, #pretty_cannot_install, #pretty_deprecated, #pretty_disabled, #pretty_duration, #pretty_install_status, #pretty_installed, #pretty_uninstalled, #pretty_unmarked, #pretty_upgradable, #pretty_warning
Methods included from DiskUsageExtension
#abv, #disk_usage, #file_count
Methods included from SystemCommand::Mixin
#system_command, #system_command!
Methods included from EagerInitializeExtension
Class Method Details
.activate_extensions! ⇒ void
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.
This method returns an undefined value.
37 38 39 |
# File 'extend/pathname.rb', line 37 def self.activate_extensions! Pathname.prepend(WriteMkpathExtension) end |
Instance Method Details
#append_lines(content, **open_args) ⇒ void
This method returns an undefined value.
Only appends to a file that is already created.
100 101 102 103 104 |
# File 'extend/pathname.rb', line 100 def append_lines(content, **open_args) raise "Cannot append file that doesn't exist: #{self}" unless exist? File.open(self, "a", **open_args) { |f| f.puts(content) } end |
#arch_compatible?(_wanted_arch) ⇒ 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.
403 404 405 |
# File 'extend/pathname.rb', line 403 def arch_compatible?(_wanted_arch) true end |
#atomic_write(content) ⇒ void
This always overwrites.
This method returns an undefined value.
Write to a file atomically.
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 |
# File 'extend/pathname.rb', line 112 def atomic_write(content) require "extend/file/atomic" old_stat = stat if exist? File.atomic_write(self) do |file| file.write(content) end return unless old_stat # Try to restore original file's permissions separately # atomic_write does it itself, but it actually erases # them if chown fails begin # Set correct permissions on new file chown(old_stat.uid, nil) chown(nil, old_stat.gid) rescue Errno::EPERM, Errno::EACCES # Changing file ownership failed, moving on. nil end begin # This operation will affect filesystem ACL's chmod(old_stat.mode) rescue Errno::EPERM, Errno::EACCES # Changing file permissions failed, moving on. nil end end |
#binary_executable? ⇒ 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.
388 389 390 |
# File 'extend/pathname.rb', line 388 def binary_executable? false end |
#blank? ⇒ 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.
A Pathname is blank if its path is empty. Unlike Pathname#empty?,
this never touches the filesystem, so an existing-but-empty file or
directory is still present.
Pathname.new("").blank? # => true
Pathname.new(" ").blank? # => false
Pathname.new("test").blank? # => false
18 19 20 |
# File 'extend/blank/pathname.rb', line 18 def blank? to_s.empty? end |
#cd(&_block) ⇒ T.type_parameter(:U)
Change to this directory, optionally executing the given block.
224 225 226 |
# File 'extend/pathname.rb', line 224 def cd(&_block) Dir.chdir(self) { yield self } end |
#cp_path_sub(pattern, replacement, &block) ⇒ void
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.
This method returns an undefined value.
147 148 149 150 |
# File 'extend/pathname.rb', line 147 def cp_path_sub(pattern, replacement, &block) Utils::Output.odeprecated "Pathname#cp_path_sub", "Utils::Path.cp_path_sub" Utils::Path.cp_path_sub(self, pattern, replacement, &block) end |
#dylib? ⇒ 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.
398 399 400 |
# File 'extend/pathname.rb', line 398 def dylib? false end |
#ensure_writable(&block) ⇒ void
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.
This method returns an undefined value.
255 256 257 258 |
# File 'extend/pathname.rb', line 255 def ensure_writable(&block) Utils::Output.odeprecated "Pathname#ensure_writable", "Utils::Path.ensure_writable" Utils::Path.ensure_writable(self, &block) end |
#env_script_all_files(dst, env) ⇒ void
This method returns an undefined value.
Writes a wrapper env script and moves all files to the dst.
334 335 336 337 338 339 340 341 342 343 344 345 |
# File 'extend/pathname.rb', line 334 def env_script_all_files(dst, env) dst.mkpath Pathname.glob("#{self}/*") do |file| next if file.directory? new_file = dst.join(file.basename) raise Errno::EEXIST, new_file.to_s if new_file.exist? dst.install(file) file.write_env_script(new_file, env) end end |
#extname ⇒ String
Extended to support common double extensions.
156 157 158 159 160 161 162 163 164 165 166 167 168 169 |
# File 'extend/pathname.rb', line 156 def extname basename = File.basename(self) bottle_ext, = HOMEBREW_BOTTLES_EXTNAME_REGEX.match(basename).to_a return bottle_ext if bottle_ext archive_ext = basename[/(\.(?:tar|cpio|pax)\.(?:gz|bz2|lz|xz|zst|Z))\Z/, 1] return archive_ext if archive_ext # Don't treat version numbers as extname. return "" if basename.match?(/\b\d+\.\d+[^.]*\Z/) && !basename.end_with?(".7z") File.extname(basename) end |
#install(*sources) ⇒ void
This method returns an undefined value.
Moves a file from the original location to the Pathname's.
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'extend/pathname.rb', line 50 def install(*sources) sources.each do |src| case src when Resource src.stage(self) when Resource::Partial src.resource.stage { install(*src.files) } when Array if src.empty? opoo "Tried to install empty array to #{self}" break end src.each { |s| install_p(s, File.basename(s)) } when Hash if src.empty? opoo "Tried to install empty hash to #{self}" break end src.each { |s, new_basename| install_p(s, new_basename) } else install_p(src, File.basename(src)) end end end |
#install_info ⇒ void
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.
This method returns an undefined value.
261 262 263 264 |
# File 'extend/pathname.rb', line 261 def install_info Utils::Output.odeprecated "Pathname#install_info", "Utils::Path.install_info" Utils::Path.install_info(self) end |
#install_metafiles(from = Pathname.pwd) ⇒ void
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.
This method returns an undefined value.
368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 |
# File 'extend/pathname.rb', line 368 def (from = Pathname.pwd) require "metafiles" Pathname(from).children.each do |p| next if p.directory? next if File.empty?(p) next unless Metafiles.copy?(p.basename.to_s) # Some software symlinks these files (see help2man.rb) filename = Utils::Path.resolved_path(p) # Some software links metafiles together, so by the time we iterate to one of them # we may have already moved it. libxml2's COPYING and Copyright are affected by this. next unless filename.exist? filename.chmod 0644 install(filename) end end |
#install_symlink(*sources) ⇒ void
This method returns an undefined value.
Creates symlinks to sources in this folder.
83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'extend/pathname.rb', line 83 def install_symlink(*sources) sources.each do |src| case src when Array src.each { |s| install_symlink_p(s, File.basename(s)) } when Hash src.each { |s, new_basename| install_symlink_p(s, new_basename) } else install_symlink_p(src, File.basename(src)) end end end |
#mach_o_bundle? ⇒ 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.
393 394 395 |
# File 'extend/pathname.rb', line 393 def mach_o_bundle? false end |
#make_relative_symlink(src) ⇒ void
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.
This method returns an undefined value.
249 250 251 252 |
# File 'extend/pathname.rb', line 249 def make_relative_symlink(src) dirname.mkpath File.symlink(src.relative_path_from(dirname), self) end |
#present? ⇒ 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.
23 |
# File 'extend/blank/pathname.rb', line 23 def present? = !blank? # :nodoc: |
#resolved_path ⇒ Pathname
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.
237 238 239 240 |
# File 'extend/pathname.rb', line 237 def resolved_path Utils::Output.odeprecated "Pathname#resolved_path", "Utils::Path.resolved_path" Utils::Path.resolved_path(self) end |
#resolved_path_exists? ⇒ 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.
243 244 245 246 |
# File 'extend/pathname.rb', line 243 def resolved_path_exists? Utils::Output.odeprecated "Pathname#resolved_path_exists?", "Utils::Path.resolved_path_exists?" Utils::Path.resolved_path_exists?(self) end |
#rmdir_if_possible ⇒ 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.
180 181 182 183 |
# File 'extend/pathname.rb', line 180 def rmdir_if_possible Utils::Output.odeprecated "Pathname#rmdir_if_possible", "Utils::Path.rmdir_if_possible" Utils::Path.rmdir_if_possible(self) end |
#rpaths ⇒ Array<String>
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.
408 409 410 |
# File 'extend/pathname.rb', line 408 def rpaths [] end |
#sha256 ⇒ String
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.
198 199 200 201 202 203 204 |
# File 'extend/pathname.rb', line 198 def sha256 require "digest/sha2" # In integration tests only, raise when an unchanged file is rehashed # without the digest cache being involved. ::Downloadable::VerificationCache.check_repeated_hashing(self) if defined?(::Downloadable::VerificationCache) Digest::SHA256.file(self).hexdigest end |
#stem ⇒ String
For filetypes we support, returns basename without extension.
175 176 177 |
# File 'extend/pathname.rb', line 175 def stem File.basename(self, extname) end |
#subdirs ⇒ Array<Pathname>
Get all sub-directories of this directory.
232 233 234 |
# File 'extend/pathname.rb', line 232 def subdirs children.select(&:directory?) end |
#text_executable? ⇒ 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.
192 193 194 195 |
# File 'extend/pathname.rb', line 192 def text_executable? Utils::Output.odeprecated "Pathname#text_executable?", "Utils::Path.text_executable?" Utils::Path.text_executable?(self) end |
#uninstall_info ⇒ void
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.
This method returns an undefined value.
267 268 269 270 |
# File 'extend/pathname.rb', line 267 def uninstall_info Utils::Output.odeprecated "Pathname#uninstall_info", "Utils::Path.uninstall_info" Utils::Path.uninstall_info(self) end |
#verify_checksum(expected) ⇒ void
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.
This method returns an undefined value.
207 208 209 210 211 212 |
# File 'extend/pathname.rb', line 207 def verify_checksum(expected) raise ChecksumMissingError if expected.blank? actual = Checksum.new(sha256.downcase) raise ChecksumMismatchError.new(self, expected, actual) if expected != actual end |
#version ⇒ Version
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.
186 187 188 189 |
# File 'extend/pathname.rb', line 186 def version require "version" Version.parse(basename) end |
#write_env_script(target, args_or_env, env = nil) ⇒ void
This method returns an undefined value.
Writes an exec script that sets environment variables.
306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 |
# File 'extend/pathname.rb', line 306 def write_env_script(target, args_or_env, env = nil) args = if env.nil? raise ArgumentError, "#{args_or_env.inspect} is not a Hash" unless args_or_env.is_a?(Hash) env = args_or_env nil elsif args_or_env.is_a?(Array) args_or_env.join(" ") else args_or_env end env_export = +"" env.each { |key, value| env_export << "#{key}=\"#{value}\" " } dirname.mkpath write <<~SH #!/bin/bash #{env_export}exec "#{target}" #{args} "$@" SH chmod 0555 end |
#write_exec_script(*targets) ⇒ void
This method returns an undefined value.
Writes an exec script in this folder for each target pathname.
276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 |
# File 'extend/pathname.rb', line 276 def write_exec_script(*targets) targets.flatten! if targets.empty? opoo "Tried to write exec scripts to #{self} for an empty list of targets" return end mkpath targets.each do |target| target = Pathname.new(target) # allow pathnames or strings join(target.basename).write <<~SH #!/bin/bash exec "#{target}" "$@" SH end end |
#write_jar_script(target_jar, script_name, java_opts = "", java_version: nil) ⇒ Integer
Writes an exec script that invokes a Java jar.
358 359 360 361 362 363 364 365 |
# File 'extend/pathname.rb', line 358 def write_jar_script(target_jar, script_name, java_opts = "", java_version: nil) mkpath (self/script_name).write <<~EOS #!/bin/bash export JAVA_HOME="#{Language::Java.overridable_java_home_env(java_version)[:JAVA_HOME]}" exec "${JAVA_HOME}/bin/java" #{java_opts} -jar "#{target_jar}" "$@" EOS end |