Class: PhusionPassenger::Utils::TmpIO

Inherits:
File
  • Object
show all
Defined in:
lib/phusion_passenger/utils/tmpio.rb

Overview

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 Method Summary collapse

Instance Method Summary collapse

Class Method Details

.new(namespace) ⇒ Object

creates and returns a new File object. The File is unlinked immediately, switched to binary mode, and userspace output buffering is disabled



15
16
17
18
19
20
21
22
23
24
25
# File 'lib/phusion_passenger/utils/tmpio.rb', line 15

def self.new(namespace)
  fp = begin
    super("#{Dir::tmpdir}/#{namespace}-#{rand}", RDWR|CREAT|EXCL, 0600)
  rescue Errno::EEXIST
    retry
  end
  unlink(fp.path)
  fp.binmode
  fp.sync = true
  fp
end

Instance Method Details

#sizeObject

for easier env compatibility with Rack <= 1.1



28
29
30
# File 'lib/phusion_passenger/utils/tmpio.rb', line 28

def size
  stat.size
end