This is the initial release of the Windows Tempfile Fix plugin. This plugin sets out to make Tempfile binary safe on Windows.

Installation


1 $ piston import svn://svn.teksol.info/svn/rails/plugins/windows_tempfile_fix vendor\plugins\windows_tempfile_fix

Alternatively:


1 $ ruby script/plugin install svn://svn.teksol.info/svn/rails/plugins/windows_tempfile_fix

README

As I reported on my blog at
http://blog.teksol.info/articles/2006/12/08/rmagick-and-jpeg-datastream-contains-no-image,
the Windows version of Ruby will fail to load certain files when they are used
through a Tempfile. This is because the Tempfile class does not open it’s files
in binary mode.

This plugin is very conservative. It will not install itself if it does
not detect the exact version it is supposed to be used against.

This plugin will only do it’s work if it the following expression evaluates
to true:
RUBY_PLATFORM == “i386-mswin32” && RUBY_VERSION == “1.8.4”

Today, I hit a major roadblock: “JPEG datastream contains no image”. I turned to Google and found a solution.

Line 55 of tempfile.rb is:

lib/ruby/1.8/tempfile.rb

1 @tmpfile = File.open(tmpname, File::RDWR|File::CREAT|File::EXCL, 0600)

Unfortunately, on Windows, this causes problems. If the file contains binary data (such as a JPEG datastream…), the fact that we open the file without the BINARY flag sometimes truncates the file content.

I patched my local Ruby 1.8.4 version to this:

lib/ruby/1.8/tempfile.rb

1 @tmpfile = File.open(tmpname, File::RDWR|File::CREAT|File::EXCL|File::BINARY, 0600)

The only change is I OR the File::BINARY flag to the mode parameter.

Now, I guess I should submit a Ruby enhancement request, no ? With failing test and all ? Sometimes I hate my Windows box…

Search

Your Host

A picture of me

I am François Beausoleil, a Ruby on Rails and Scala developer. During the day, I work on Seevibes, a platform to measure social interactions related to TV shows. At night, I am interested many things. Read my biography.

Top Tags

Books I read and recommend

Links

Projects I work on

Projects I worked on