diff options
author | knu <knu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2012-02-01 16:12:44 +0000 |
---|---|---|
committer | knu <knu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2012-02-01 16:12:44 +0000 |
commit | 1f1196fae381d6c03545d95806929b297b2d48df (patch) | |
tree | 50012aebdb9f7166029847737c69885d1d38c768 | |
parent | dc82e7e7496f1c22750a58c456cdea849751b70b (diff) | |
download | ruby-1f1196fae381d6c03545d95806929b297b2d48df.tar.gz |
* 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.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@34413 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | ChangeLog | 9 | ||||
-rw-r--r-- | lib/tempfile.rb | 33 |
2 files changed, 26 insertions, 16 deletions
@@ -1,3 +1,12 @@ +Wed Feb 1 14:38:31 2012 Akinori MUSHA <knu@iDaemons.org> + + * 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@ruby-lang.org> * doc/re.rdoc (Repetition): fix typo. reported by Ori Avtalion diff --git a/lib/tempfile.rb b/lib/tempfile.rb index 5e860db095..9f4ed8f3fd 100644 --- a/lib/tempfile.rb +++ b/lib/tempfile.rb @@ -227,18 +227,17 @@ class Tempfile < DelegateClass(File) # # 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 @@ class Tempfile < DelegateClass(File) 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) - end + tmpfile.close if tmpfile - STDERR.print "done\n" if $DEBUG + if path + begin + File.unlink(path) + rescue Errno::ENOENT + end end + + STDERR.print "done\n" if $DEBUG end end # :startdoc: |