From 86fd8957c7799368619aa8ce054b440716494a11 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Sun, 19 Jul 2009 17:11:01 -0700 Subject: Remove core Tempfile dependency (1.9.2-preview1 compat) With the 1.9.2preview1 release (and presumably 1.9.1 p243), the Ruby core team has decided that bending over backwards to support crippled operating/file systems was necessary and that files must be closed before unlinking. Regardless, this is more efficient than using Tempfile because: 1) no delegation is necessary, this is a real File object 2) no mkdir is necessary for locking, we can trust O_EXCL to work properly without unnecessary FS activity 3) no finalizer is needed to unlink the file, we unlink it as soon as possible after creation. (cherry picked from commit 344b85ff28e160daa6563ab7c80b733abdeb874a) Conflicts: lib/unicorn.rb lib/unicorn/app/exec_cgi.rb lib/unicorn/tee_input.rb --- lib/unicorn/util.rb | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'lib/unicorn/util.rb') diff --git a/lib/unicorn/util.rb b/lib/unicorn/util.rb index 2d3f827..d2214b7 100644 --- a/lib/unicorn/util.rb +++ b/lib/unicorn/util.rb @@ -1,4 +1,5 @@ require 'fcntl' +require 'tmpdir' module Unicorn class Util @@ -39,6 +40,22 @@ module Unicorn nr end + # creates and returns a new File object. The File is unlinked + # immediately, switched to binary mode, and userspace output + # buffering is disabled + def tmpio + fp = begin + File.open("#{Dir::tmpdir}/#{rand}", + File::RDWR|File::CREAT|File::EXCL, 0600) + rescue Errno::EEXIST + retry + end + File.unlink(fp.path) + fp.binmode + fp.sync = true + fp + end + end end -- cgit v1.2.3-24-ge0c7