Sha256: b4a79b5248b1bbd9df9603e83b352ab81b1a4549f0846d509fdae5f47e07c393

Contents?: true

Size: 867 Bytes

Versions: 16

Compression:

Stored size: 867 Bytes

Contents

# -*- encoding: binary -*-
# :stopdoc:
require 'tmpdir'

module Pitchfork
  # 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
      path = nil

      # workaround File#path being tainted:
      # https://bugs.ruby-lang.org/issues/14485
      fp = begin
        path = "#{Dir::tmpdir}/#{rand}"
        super(path, RDWR|CREAT|EXCL, 0600)
      rescue Errno::EEXIST
        retry
      end

      unlink(path)
      fp.binmode
      fp.sync = true
      fp
    end

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

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
pitchfork-0.12.0 lib/pitchfork/tmpio.rb
pitchfork-0.11.1 lib/pitchfork/tmpio.rb
pitchfork-0.11.0 lib/pitchfork/tmpio.rb
pitchfork-0.10.0 lib/pitchfork/tmpio.rb
pitchfork-0.9.0 lib/pitchfork/tmpio.rb
pitchfork-0.8.0 lib/pitchfork/tmpio.rb
pitchfork-0.7.0 lib/pitchfork/tmpio.rb
pitchfork-0.6.0 lib/pitchfork/tmpio.rb
pitchfork-0.5.0 lib/pitchfork/tmpio.rb
pitchfork-0.4.1 lib/pitchfork/tmpio.rb
pitchfork-0.4.0 lib/pitchfork/tmpio.rb
pitchfork-0.3.0 lib/pitchfork/tmpio.rb
pitchfork-0.2.0 lib/pitchfork/tmpio.rb
pitchfork-0.1.2 lib/pitchfork/tmpio.rb
pitchfork-0.1.1 lib/pitchfork/tmpio.rb
pitchfork-0.1.0 lib/pitchfork/tmpio.rb