1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* 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
This commit is contained in:
knu 2012-02-01 16:12:44 +00:00
parent dc82e7e749
commit 1f1196fae3
2 changed files with 26 additions and 16 deletions

View file

@ -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> Wed Feb 1 09:50:10 2012 Nobuyoshi Nakada <nobu@ruby-lang.org>
* doc/re.rdoc (Repetition): fix typo. reported by Ori Avtalion * doc/re.rdoc (Repetition): fix typo. reported by Ori Avtalion

View file

@ -227,18 +227,17 @@ class Tempfile < DelegateClass(File)
# # to do so again. # # to do so again.
# end # end
def unlink def unlink
# keep this order for thread safeness
return unless @tmpname return unless @tmpname
begin begin
if File.exist?(@tmpname)
File.unlink(@tmpname) File.unlink(@tmpname)
rescue Errno::ENOENT
rescue Errno::EACCES
# may not be able to unlink on Windows; just ignore
return
end end
# remove tmpname from remover # remove tmpname from remover
@data[0] = @data[1] = nil @data[0] = @data[1] = nil
@tmpname = nil @tmpname = nil
rescue Errno::EACCES
# may not be able to unlink on Windows; just ignore
end
end end
alias delete unlink alias delete unlink
@ -270,22 +269,24 @@ class Tempfile < DelegateClass(File)
end end
def call(*args) def call(*args)
if @pid == $$ return if @pid != $$
path, tmpfile = *@data path, tmpfile = *@data
STDERR.print "removing ", path, "..." if $DEBUG STDERR.print "removing ", path, "..." if $DEBUG
tmpfile.close if tmpfile tmpfile.close if tmpfile
# keep this order for thread safeness
if path if path
File.unlink(path) if File.exist?(path) begin
File.unlink(path)
rescue Errno::ENOENT
end
end end
STDERR.print "done\n" if $DEBUG STDERR.print "done\n" if $DEBUG
end end
end end
end
# :startdoc: # :startdoc:
class << self class << self