class Dir - mcollective version 2.12.5

# class Dir

### Public Class Methods

mktmpdir(prefix_suffix=nil, tmpdir=nil) { |path| ... } click to toggle source

        # File lib/mcollective/monkey_patches.rb
     72 def self.mktmpdir(prefix_suffix=nil, tmpdir=nil)
     73   case prefix_suffix
     74   when nil
     75     prefix = "d"
     76     suffix = ""
     77   when String
     78     prefix = prefix_suffix
     79     suffix = ""
     80   when Array
     81     prefix = prefix_suffix[0]
     82     suffix = prefix_suffix[1]
     83   else
     84     raise ArgumentError, "unexpected prefix_suffix: #{prefix_suffix.inspect}"
     85   end
     86   tmpdir ||= Dir.tmpdir
     87   t = Time.now.strftime("%Y%m%d")
     88   n = nil
     89   begin
     90     path = "#{tmpdir}/#{prefix}#{t}-#{$$}-#{rand(0x100000000).to_s(36)}"
     91     path << "-#{n}" if n
     92     path << suffix
     93     Dir.mkdir(path, 0700)
     94   rescue Errno::EEXIST
     95     n ||= 0
     96     n += 1
     97     retry
     98   end
     99
    100   if block_given?
    101     begin
    102       yield path
    103     ensure
    104       FileUtils.remove_entry_secure path
    105     end
    106   else
    107     path
    108   end
    109 end

tmpdir() click to toggle source

        # File lib/mcollective/monkey_patches.rb
    111 def self.tmpdir
    112   tmp = '.'
    113   for dir in [ENV['TMPDIR'], ENV['TMP'], ENV['TEMP'], '/tmp']
    114     if dir and stat = File.stat(dir) and stat.directory? and stat.writable?
    115       tmp = dir
    116       break
    117     end rescue nil
    118   end
    119   File.expand_path(tmp)
    120 end