Class: Mktemp Private

Inherits:
Object show all
Includes:
Utils::Output::Mixin
Defined in:
mktemp.rb

Overview

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.

Performs Formula#mktemp's functionality and tracks the results. Each instance is only intended to be used once. Can also be used to create a temporary directory with the brew instance's group.

Instance Attribute Summary collapse

Instance Method Summary collapse

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

Constructor Details

#initialize(prefix, retain: false, retain_in_cache: false, path: nil, parent: HOMEBREW_TEMP) ⇒ 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.

With path, reuse that existing directory (e.g. one shared between the fetch and build phases) rather than creating a temporary one. Otherwise create the directory under parent, unless retaining it in cache.

Parameters:

  • prefix (String)
  • retain (Boolean) (defaults to: false)
  • retain_in_cache (Boolean) (defaults to: false)
  • path (Pathname, nil) (defaults to: nil)
  • parent (Pathname) (defaults to: HOMEBREW_TEMP)


25
26
27
28
29
30
31
32
33
# File 'mktemp.rb', line 25

def initialize(prefix, retain: false, retain_in_cache: false, path: nil, parent: HOMEBREW_TEMP)
  @prefix = prefix
  @path = path
  @parent = parent
  @retain_in_cache = retain_in_cache
  @retain = T.let(retain || @retain_in_cache, T::Boolean)
  @quiet = T.let(false, T::Boolean)
  @tmpdir = T.let(nil, T.nilable(Pathname))
end

Instance Attribute Details

#tmpdirPathname? (readonly)

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.

Path to the tmpdir used in this run

Returns:



16
17
18
# File 'mktemp.rb', line 16

def tmpdir
  @tmpdir
end

Instance Method Details

#quiet!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.

Instructs this Mktemp to not emit messages when retention is triggered.



55
56
57
# File 'mktemp.rb', line 55

def quiet!
  @quiet = true
end

#retain!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.

Instructs this Mktemp to retain the staged files.



37
38
39
# File 'mktemp.rb', line 37

def retain!
  @retain = true
end

#retain?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.

True if the staged temporary files should be retained.

Returns:

  • (Boolean)


43
44
45
# File 'mktemp.rb', line 43

def retain?
  @retain
end

#retain_in_cache?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.

True if the source files should be retained.

Returns:

  • (Boolean)


49
50
51
# File 'mktemp.rb', line 49

def retain_in_cache?
  @retain_in_cache
end

#run(chdir: true, &_block) ⇒ T.type_parameter(:U)

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.

Parameters:

  • chdir (Boolean) (defaults to: true)
  • _block (T.proc.params(arg0: Mktemp).returns(T.type_parameter(:U)))

Returns:

  • (T.type_parameter(:U))


70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'mktemp.rb', line 70

def run(chdir: true, &_block)
  @tmpdir = @path || create_tmpdir

  begin
    if chdir
      Dir.chdir(@tmpdir) { yield self }
    else
      yield self
    end
  ensure
    Utils::Interrupts.ignore { chmod_rm_rf(@tmpdir) } unless retain?
  end
ensure
  if retain? && @tmpdir.present? && !@quiet
    message = retain_in_cache? ? "Source files for debugging available at:" : "Temporary files retained at:"
    ohai message, @tmpdir.to_s
  end
end