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

Closed
bchristenson opened this Issue Oct 1, 2009 · 3 comments

Comments

Projects
None yet
4 participants

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

Well spotted.

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

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

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

@sikachu sikachu closed this in 30c6dc5 Jun 29, 2011

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment