Sha256: 7c7e48228b613206da3bf2517e1e14eba3d720c4d71877ef803db789c8d74098

Contents?: true

Size: 1.06 KB

Versions: 71

Compression:

Stored size: 1.06 KB

Contents

unless Dir.respond_to? :mktmpdir
  class << Dir
    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
  end
end

Version data entries

71 entries across 71 versions & 5 rubygems

Version Path
backports-3.6.7 lib/backports/1.8.7/stdlib/tmpdir.rb
backports-3.6.6 lib/backports/1.8.7/stdlib/tmpdir.rb
backports-3.6.5 lib/backports/1.8.7/stdlib/tmpdir.rb
backports-3.6.4 lib/backports/1.8.7/stdlib/tmpdir.rb
backports-3.6.3 lib/backports/1.8.7/stdlib/tmpdir.rb
backports-3.6.2 lib/backports/1.8.7/stdlib/tmpdir.rb
backports-3.6.1 lib/backports/1.8.7/stdlib/tmpdir.rb
scout_realtime-1.0.5 lib/vendor/backports-3.3.5/lib/backports/1.8.7/stdlib/tmpdir.rb
scout_realtime-1.0.4 lib/vendor/backports-3.3.5/lib/backports/1.8.7/stdlib/tmpdir.rb
scout_realtime-1.0.3 lib/vendor/backports-3.3.5/lib/backports/1.8.7/stdlib/tmpdir.rb
scout_realtime-1.0.3.pre lib/vendor/backports-3.3.5/lib/backports/1.8.7/stdlib/tmpdir.rb
scout_realtime-1.0.2 lib/vendor/backports-3.3.5/lib/backports/1.8.7/stdlib/tmpdir.rb
scout_realtime-1.0.1 lib/vendor/backports-3.3.5/lib/backports/1.8.7/stdlib/tmpdir.rb
scout_realtime-1.0.0 lib/vendor/backports-3.3.5/lib/backports/1.8.7/stdlib/tmpdir.rb
scout_realtime-0.5.5 lib/vendor/backports-3.3.5/lib/backports/1.8.7/stdlib/tmpdir.rb
scout_realtime-0.5.5.pre lib/vendor/backports-3.3.5/lib/backports/1.8.7/stdlib/tmpdir.rb
scout_realtime-0.5.4 lib/vendor/backports-3.3.5/lib/backports/1.8.7/stdlib/tmpdir.rb
backports-3.6.0 lib/backports/1.8.7/stdlib/tmpdir.rb
backports-3.5.0 lib/backports/1.8.7/stdlib/tmpdir.rb
backports-3.4.1 lib/backports/1.8.7/stdlib/tmpdir.rb