Sha256: 47aa5a3f2c7a285e37a25956f466f2525d121d0999633e2d4bebe684afb31be1

Contents?: true

Size: 806 Bytes

Versions: 8

Compression:

Stored size: 806 Bytes

Contents

require 'tmpdir'

module PhusionPassenger
module Utils

# 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 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(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

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

end # module Utils
end # module PhusionPassenger

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
passenger-4.0.4 lib/phusion_passenger/utils/tmpio.rb
passenger-4.0.3 lib/phusion_passenger/utils/tmpio.rb
passenger-4.0.2 lib/phusion_passenger/utils/tmpio.rb
passenger-4.0.1 lib/phusion_passenger/utils/tmpio.rb
passenger-4.0.0.rc6 lib/phusion_passenger/utils/tmpio.rb
passenger-4.0.0.rc4 lib/phusion_passenger/utils/tmpio.rb
passenger-3.9.2.beta lib/phusion_passenger/utils/tmpio.rb
passenger-3.9.1.beta lib/phusion_passenger/utils/tmpio.rb