Class: Mktemp
Overview
Performs Formula#mktemp’s functionality, and tracks the results. Each instance is only intended to be used once.
Instance Attribute Summary collapse
-
#tmpdir ⇒ Object
readonly
Path to the tmpdir used in this run, as a Pathname.
Instance Method Summary collapse
-
#initialize(prefix, opts = {}) ⇒ Mktemp
constructor
A new instance of Mktemp.
-
#quiet! ⇒ void
Instructs this Mktemp to not emit messages when retention is triggered.
-
#retain! ⇒ void
Instructs this Mktemp to retain the staged files.
-
#retain? ⇒ Boolean
True if the staged temporary files should be retained.
-
#retain_in_cache? ⇒ Boolean
True if the source files should be retained.
-
#run ⇒ Object
-
#to_s ⇒ String
Constructor Details
#initialize(prefix, opts = {}) ⇒ Mktemp
Returns a new instance of Mktemp.
14 15 16 17 18 19 |
# File 'mktemp.rb', line 14 def initialize(prefix, opts = {}) @prefix = prefix @retain_in_cache = opts[:retain_in_cache] @retain = opts[:retain] || @retain_in_cache @quiet = false end |
Instance Attribute Details
#tmpdir ⇒ Object (readonly)
Path to the tmpdir used in this run, as a Pathname.
12 13 14 |
# File 'mktemp.rb', line 12 def tmpdir @tmpdir end |
Instance Method Details
#quiet! ⇒ void
This method returns an undefined value.
Instructs this Mktemp to not emit messages when retention is triggered.
39 40 41 |
# File 'mktemp.rb', line 39 def quiet! @quiet = true end |
#retain! ⇒ void
This method returns an undefined value.
Instructs this Mktemp to retain the staged files.
23 24 25 |
# File 'mktemp.rb', line 23 def retain! @retain = true end |
#retain? ⇒ Boolean
True if the staged temporary files should be retained.
28 29 30 |
# File 'mktemp.rb', line 28 def retain? @retain end |
#retain_in_cache? ⇒ Boolean
True if the source files should be retained.
33 34 35 |
# File 'mktemp.rb', line 33 def retain_in_cache? @retain_in_cache end |
#run ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'mktemp.rb', line 48 def run prefix_name = @prefix.tr "@", "AT" @tmpdir = if retain_in_cache? tmp_dir = HOMEBREW_CACHE/"Sources/#{prefix_name}" chmod_rm_rf(tmp_dir) # clear out previous staging directory tmp_dir.mkpath tmp_dir else Pathname.new(Dir.mktmpdir("#{prefix_name}-", HOMEBREW_TEMP)) end # Make sure files inside the temporary directory have the same group as the # brew instance. # # Reference from `man 2 open` # > When a new file is created, it is given the group of the directory which # contains it. group_id = if HOMEBREW_BREW_FILE.grpowned? HOMEBREW_BREW_FILE.stat.gid else Process.gid end begin chown(nil, group_id, @tmpdir) rescue Errno::EPERM opoo "Failed setting group \"#{T.must(Etc.getgrgid(group_id)).name}\" on #{@tmpdir}" end begin Dir.chdir(tmpdir) { yield self } ensure ignore_interrupts { chmod_rm_rf(@tmpdir) } unless retain? end ensure if retain? && @tmpdir.present? && !@quiet = retain_in_cache? ? "Source files for debugging available at:" : "Temporary files retained at:" ohai , @tmpdir.to_s end end |
#to_s ⇒ String
44 45 46 |
# File 'mktemp.rb', line 44 def to_s "[Mktemp: #{tmpdir} retain=#{@retain} quiet=#{@quiet}]" end |