ruby-changes:22364
From: knu <ko1@a...>
Date: Thu, 2 Feb 2012 01:12:54 +0900 (JST)
Subject: [ruby-changes:22364] knu:r34413 (trunk): * lib/tempfile.rb (Tempfile#unlink, Tempfile::Remover#call): Just
knu 2012-02-02 01:12:44 +0900 (Thu, 02 Feb 2012) New Revision: 34413 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=34413 Log: * lib/tempfile.rb (Tempfile#unlink, Tempfile::Remover#call): Just call File.unlink and ignore ENOENT because existence check before unlinking does not help in terms of race condition. * lib/tempfile.rb (Tempfile#unlink, Tempfile::Remover#call): My comment about thread safeness is obsolete. Modified files: trunk/ChangeLog trunk/lib/tempfile.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 34412) +++ ChangeLog (revision 34413) @@ -1,3 +1,12 @@ +Wed Feb 1 14:38:31 2012 Akinori MUSHA <knu@i...> + + * lib/tempfile.rb (Tempfile#unlink, Tempfile::Remover#call): Just + call File.unlink and ignore ENOENT because existence check + before unlinking does not help in terms of race condition. + + * lib/tempfile.rb (Tempfile#unlink, Tempfile::Remover#call): My + comment about thread safeness is obsolete. + Wed Feb 1 09:50:10 2012 Nobuyoshi Nakada <nobu@r...> * doc/re.rdoc (Repetition): fix typo. reported by Ori Avtalion Index: lib/tempfile.rb =================================================================== --- lib/tempfile.rb (revision 34412) +++ lib/tempfile.rb (revision 34413) @@ -227,18 +227,17 @@ # # to do so again. # end def unlink - # keep this order for thread safeness return unless @tmpname begin - if File.exist?(@tmpname) - File.unlink(@tmpname) - end - # remove tmpname from remover - @data[0] = @data[1] = nil - @tmpname = nil + File.unlink(@tmpname) + rescue Errno::ENOENT rescue Errno::EACCES # may not be able to unlink on Windows; just ignore + return end + # remove tmpname from remover + @data[0] = @data[1] = nil + @tmpname = nil end alias delete unlink @@ -270,20 +269,22 @@ end def call(*args) - if @pid == $$ - path, tmpfile = *@data + return if @pid != $$ - STDERR.print "removing ", path, "..." if $DEBUG + path, tmpfile = *@data - tmpfile.close if tmpfile + STDERR.print "removing ", path, "..." if $DEBUG - # keep this order for thread safeness - if path - File.unlink(path) if File.exist?(path) + tmpfile.close if tmpfile + + if path + begin + File.unlink(path) + rescue Errno::ENOENT end + end - STDERR.print "done\n" if $DEBUG - end + STDERR.print "done\n" if $DEBUG end end # :startdoc: -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/