Bug in WindowsFileStat in jna-posix

I think I’ve found a problem in the jna-posix library. (Latest from
trunk, and also the version in jruby-1.1.4)

Running on Windows/Vista (32 bit) this comes up with complete nonsense
for file sizes. I note from the change history that a change was made to
this library to use _stat64 instead of _stat to get file status
information, in order to allow it to work correctly on large files.
Perhaps this is only producing the correct results on 64 bit O/S? In any
case, I’m not sure why it isn’t working properly for me. If I disable
native extensions when I start jruby, I’m getting the correct results
via the Java implementation.

Has anyone else seen this?

I’ve investigated this further and narrowed it down to cases concerning
the use of ‘temporary files’ in rails, e.g. when a file is uploaded as
part of a form response. It is only for these temporary files that
things are going wrong. My initial guess was that something is wrong
with the ‘flush’ that happens internally before the .size method goes
off to ask for the file size.

def file=(incoming_file)
unless incoming_file.nil?
@temp_file = incoming_file
if @temp_file.size > 0
self.filename = sanitize_filename(@temp_file.original_filename)
self.disk_filename = Attachment.disk_filename(filename)
self.content_type = @temp_file.content_type.to_s.chomp
self.filesize = @temp_file.size
end
end
end

If I disable native extensions, things seem to work fine.
jruby.native.enabled=false.

I’m beginning to suspect this is actually a long-standing jruby problem
and not something new to either jruby 1.1.4, jna-posix or indeed rails
2.1.x.