unicorn.git  about / heads / tags
Rack HTTP server for Unix and fast clients
blob dcdf9da51747f53259866a48a7640c0eb3570d23 816 bytes (raw)
$ git show 4.x-stable:lib/unicorn/tmpio.rb	# shows this blob on the CLI

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
 
# -*- 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
    fp = begin
      super("#{Dir::tmpdir}/#{rand}", RDWR|CREAT|EXCL, 0600)
    rescue Errno::EEXIST
      retry
    end
    unlink(fp.path)
    fp.binmode
    fp.sync = true
    fp
  end

  # for easier env["rack.input"] compatibility with Rack <= 1.1
  def size
    stat.size
  end unless File.method_defined?(:size)

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

git clone https://yhbt.net/unicorn.git