Skip to content
This repository

Tempfile fix for bug in Windows Tempfile#size breaks file size in JRuby #100

Closed
bchristenson opened this Issue October 01, 2009 · 3 comments

4 participants

Ben Christenson Prem Sichanugrist Tamer Salama Ben Browning
Ben Christenson

There is a monkeypatch for Tempfile at the bottom of lib/paperclip/iostream.rb that breaks Tempfile#size when it is run from JRuby.

It looks likes this is due to a different Tempfile implementation in JRuby. The @tmpfile instance variable is never set, so Tempfile#size always returns 0.

Tested on Windows XP and Fedora (JRuby only) with Ruby 1.8.6 and JRuby 1.3.1

Tamer Salama

Well spotted.

After removing the patch, the file size is reported properly ONLY after processing. If the files aren't processed - 0 is reported.

Tamer Salama

This might work for JRuby (iostream.rb):

if defined? Tempfile
  class Tempfile
    def size
      if self.path
        File.size(self.path)
      else
        0
      end
    end
  end
end
Ben Browning

Since paperclip's Tempfile monkeypatch is meant to fix a bug on Windows, it should just be patched on Windows:

if defined? Tempfile and /mswin|win32|mingw|bccwin|cygwin/ =~ RUBY_PLATFORM
  class Tempfile
    def size
      if @tmpfile
        @tmpfile.fsync
        @tmpfile.flush
        @tmpfile.stat.size
      else
        0
      end
    end
  end
end
Prem Sichanugrist sikachu closed this in 30c6dc5 June 29, 2011
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.