Flowdock
method

create

Importance_0
Ruby latest stable (v2_5_5) - 0 notes - Class: Tmpname
create(basename, tmpdir=nil, max_try: nil, **opts) public

No documentation

This method has no description. You can help the Ruby community by adding new notes.

Hide source
# File lib/tmpdir.rb, line 115
    def create(basename, tmpdir=nil, max_try: nil, **opts)
      if $SAFE > 0 and tmpdir.tainted?
        tmpdir = '/tmp'
      else
        origdir = tmpdir
        tmpdir ||= tmpdir()
      end
      n = nil
      prefix, suffix = basename
      prefix = (String.try_convert(prefix) or
                raise ArgumentError, "unexpected prefix: #{prefix.inspect}")
      prefix = prefix.delete("#{File::SEPARATOR}#{File::ALT_SEPARATOR}")
      suffix &&= (String.try_convert(suffix) or
                  raise ArgumentError, "unexpected suffix: #{suffix.inspect}")
      suffix &&= suffix.delete("#{File::SEPARATOR}#{File::ALT_SEPARATOR}")
      begin
        t = Time.now.strftime("%Y%m%d")
        path = "#{prefix}#{t}-#{$$}-#{rand(0x100000000).to_s(36)}"                "#{n ? %[-#{n}] : ''}#{suffix||''}"
        path = File.join(tmpdir, path)
        yield(path, n, opts, origdir)
      rescue Errno::EEXIST
        n ||= 0
        n += 1
        retry if !max_try or n < max_try
        raise "cannot generate temporary name using `#{basename}' under `#{tmpdir}'"
      end
      path
    end
Register or log in to add new notes.