Skip to content
This repository has been archived by the owner on Jul 13, 2023. It is now read-only.

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

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

Comments

@bchristenson
Copy link

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

@tamersalama
Copy link

Well spotted.

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

@tamersalama
Copy link

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

@bbrowning
Copy link

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants