Class Dir
In: lib/mcollective/monkey_patches.rb
Parent: Object

Methods

mktmpdir   tmpdir  

Public Class methods

[Source]

    # File lib/mcollective/monkey_patches.rb, line 55
55:   def self.mktmpdir(prefix_suffix=nil, tmpdir=nil)
56:     case prefix_suffix
57:     when nil
58:       prefix = "d"
59:       suffix = ""
60:     when String
61:       prefix = prefix_suffix
62:       suffix = ""
63:     when Array
64:       prefix = prefix_suffix[0]
65:       suffix = prefix_suffix[1]
66:     else
67:       raise ArgumentError, "unexpected prefix_suffix: #{prefix_suffix.inspect}"
68:     end
69:     tmpdir ||= Dir.tmpdir
70:     t = Time.now.strftime("%Y%m%d")
71:     n = nil
72:     begin
73:       path = "#{tmpdir}/#{prefix}#{t}-#{$$}-#{rand(0x100000000).to_s(36)}"
74:       path << "-#{n}" if n
75:       path << suffix
76:       Dir.mkdir(path, 0700)
77:     rescue Errno::EEXIST
78:       n ||= 0
79:       n += 1
80:       retry
81:     end
82: 
83:     if block_given?
84:       begin
85:         yield path
86:       ensure
87:         FileUtils.remove_entry_secure path
88:       end
89:     else
90:       path
91:     end
92:   end

[Source]

     # File lib/mcollective/monkey_patches.rb, line 94
 94:   def self.tmpdir
 95:     tmp = '.'
 96:     for dir in [ENV['TMPDIR'], ENV['TMP'], ENV['TEMP'], '/tmp']
 97:       if dir and stat = File.stat(dir) and stat.directory? and stat.writable?
 98:         tmp = dir
 99:         break
100:       end rescue nil
101:     end
102:     File.expand_path(tmp)
103:   end

[Validate]