Sha256: 43ac884c10e75941f521c2d52b534cefb0d0cffe883c352401448af8d7ba4894

Contents?: true

Size: 805 Bytes

Versions: 10

Compression:

Stored size: 805 Bytes

Contents

# -*- encoding: binary -*-
# :stopdoc:
require 'tmpdir'

# some versions of Ruby had a broken Tempfile which didn't work
# well with unlinked files.  This one is much shorter, easier
# to understand, and slightly faster.
class Unicorn::TmpIO < File

  # creates and returns a new File object.  The File is unlinked
  # immediately, switched to binary mode, and userspace output
  # buffering is disabled
  def self.new
    path = nil

    # workaround File#path being tainted:
    # https://bugs.ruby-lang.org/issues/14485
    fp = begin
      path = "#{Dir::tmpdir}/#{rand}"
      super(path, RDWR|CREAT|EXCL, 0600)
    rescue Errno::EEXIST
      retry
    end

    unlink(path)
    fp.binmode
    fp.sync = true
    fp
  end

  # pretend we're Tempfile for Rack::TempfileReaper
  alias close! close
end

Version data entries

10 entries across 10 versions & 2 rubygems

Version Path
unicorn-maintained-6.2.0 lib/unicorn/tmpio.rb
unicorn-6.1.0 lib/unicorn/tmpio.rb
unicorn-6.0.0 lib/unicorn/tmpio.rb
unicorn-5.8.0 lib/unicorn/tmpio.rb
unicorn-5.7.0 lib/unicorn/tmpio.rb
unicorn-5.6.0 lib/unicorn/tmpio.rb
unicorn-5.5.5 lib/unicorn/tmpio.rb
unicorn-5.5.4 lib/unicorn/tmpio.rb
unicorn-5.5.3 lib/unicorn/tmpio.rb
unicorn-5.5.2 lib/unicorn/tmpio.rb