Sha256: 6f1414c680e376635217cec4d79d68f263dcd31c914cf04460bdda652b91ce04
Contents?: true
Size: 999 Bytes
Versions: 4
Compression:
Stored size: 999 Bytes
Contents
require 'tmpdir' unless Dir.respond_to?(:mktmpdir) # backward compat for 1.8.6 class Dir def Dir.mktmpdir(prefix_suffix=nil, tmpdir=nil) 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}-#{$$}-#{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
4 entries across 4 versions & 1 rubygems