Sha256: ddc2d4e197944e82e819c9dd3fd6a09e38c513dcb4815dcad843a72cbef44ca9

Contents?: true

Size: 1.23 KB

Versions: 36

Compression:

Stored size: 1.23 KB

Contents

class Dir
  Backports.make_block_optional self, :each, :test_on => Dir.new(".")
  class << self
    Backports.make_block_optional self, :foreach, :test_on => Dir, :arg => "."
    
    def mktmpdir(prefix_suffix=nil, tmpdir=nil)
      raise NoMethodError, "undefined method `mktmpdir' for Dir:Class; you must require 'tmpdir'" unless respond_to? :tmpdir
      
      case prefix_suffix
      when nil
        prefix = "d"
        suffix = ""
      when String
        prefix = prefix_suffix
        suffix = ""
      when Array
        prefix = prefix_suffix[0]
        suffix = prefix_suffix[1]
      else
        raise ArgumentError, "unexpected prefix_suffix: #{prefix_suffix.inspect}"
      end
      tmpdir ||= Dir.tmpdir
      t = Time.now.strftime("%Y%m%d")
      n = nil
      begin
        path = "#{tmpdir}/#{prefix}#{t}-#{$$}-#{Kernel.rand(0x100000000).to_s(36)}"
        path << "-#{n}" if n
        path << suffix
        Dir.mkdir(path, 0700)
      rescue Errno::EEXIST
        n ||= 0
        n += 1
        retry
      end

      if block_given?
        begin
          yield path
        ensure
          FileUtils.remove_entry_secure path
        end
      else
        path
      end
    end unless method_defined? :mktmpdir
    
  end
end
  

Version data entries

36 entries across 36 versions & 1 rubygems

Version Path
backports-2.6.0 lib/backports/1.8.7/dir.rb
backports-2.5.3 lib/backports/1.8.7/dir.rb
backports-2.5.2 lib/backports/1.8.7/dir.rb
backports-2.5.1 lib/backports/1.8.7/dir.rb
backports-2.5.0 lib/backports/1.8.7/dir.rb
backports-2.4.0 lib/backports/1.8.7/dir.rb
backports-2.3.0 lib/backports/1.8.7/dir.rb
backports-2.2.1 lib/backports/1.8.7/dir.rb
backports-2.2.0 lib/backports/1.8.7/dir.rb
backports-2.1.0 lib/backports/1.8.7/dir.rb
backports-2.0.3 lib/backports/1.8.7/dir.rb
backports-2.0.2 lib/backports/1.8.7/dir.rb
backports-2.0.1 lib/backports/1.8.7/dir.rb
backports-2.0.0 lib/backports/1.8.7/dir.rb
backports-1.18.2 lib/backports/1.8.7/dir.rb
backports-1.18.1 lib/backports/1.8.7/dir.rb
backports-1.18.0 lib/backports/1.8.7/dir.rb
backports-1.17.1 lib/backports/1.8.7/dir.rb
backports-1.17.0 lib/backports/1.8.7/dir.rb
backports-1.16.7 lib/backports/1.8.7/dir.rb