Bug #1494: tempfile#unlink may silently fail on windows
http://redmine.ruby-lang.org/issues/show/1494

Author: Nicholas Manning
Status: Open, Priority: Low
Category: core, Target version: Ruby 1.8.6
ruby -v: ruby 1.8.6 (2007-09-24 patchlevel 111) [i386-mswin32]

There is an unlink method that was causing an exception when running it on my windows machine.  The method will call the 'rescue' block but then will do nothing.  This is problematic when things like RubyInline uses this method to create temp files and then delete them on windows.

Suggested patch (from http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-core/2848)  (thanks to Florian Frank who wrote it).

--- lib/tempfile.rb     23 Jul 2003 16:37:35 -0000      1.19
+++ lib/tempfile.rb     5 May 2004 23:33:57 -0000
@@ -106,7 +106,10 @@ class Tempfile < SimpleDelegator
   # file.
   def unlink
     # keep this order for thread safeness
-    File.unlink(@tmpname) if File.exist?(@tmpname)
+    if File.exist?(@tmpname)
+      closed? or close
+      File.unlink(@tmpname)
+    end
     @@cleanlist.delete(@tmpname) if @@cleanlist
   end
   alias delete unlink


----------------------------------------
http://redmine.ruby-lang.org