From 97e469fc3afb751618b8b9a7b364cb447aaf90dd Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Sun, 19 Jul 2009 16:38:16 -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. --- lib/unicorn/app/exec_cgi.rb | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) (limited to 'lib/unicorn/app') diff --git a/lib/unicorn/app/exec_cgi.rb b/lib/unicorn/app/exec_cgi.rb index 147b279..67817c8 100644 --- a/lib/unicorn/app/exec_cgi.rb +++ b/lib/unicorn/app/exec_cgi.rb @@ -42,11 +42,8 @@ module Unicorn::App # Calls the app def call(env) - out, err = Tempfile.new(nil), Tempfile.new(nil) - out.unlink - err.unlink + out, err = Unicorn::Util.tmpio, Unicorn::Util.tmpio inp = force_file_input(env) - out.sync = err.sync = true pid = fork { run_child(inp, out, err, env) } inp.close pid, status = Process.waitpid2(pid) @@ -125,10 +122,7 @@ module Unicorn::App if inp.size == 0 # inp could be a StringIO or StringIO-like object ::File.open('/dev/null', 'rb') else - tmp = Tempfile.new(nil) - tmp.unlink - tmp.binmode - tmp.sync = true + tmp = Unicorn::Util.tmpio buf = Z.dup while inp.read(CHUNK_SIZE, buf) -- cgit v1.2.3-24-ge0c7