Project

General

Profile

Actions

Bug #1494

closed

tempfile#unlink may silently fail on windows

Added by modethree3 (Nicholas Manning) almost 15 years ago. Updated over 11 years ago.

Status:
Third Party's Issue
Assignee:
-
Target version:
ruby -v:
ruby 1.8.6 (2007-09-24 patchlevel 111) [i386-mswin32]
Backport:
[ruby-core:23505]

Description

=begin
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
    =end
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0