mirror of
https://github.com/ruby/ruby.git
synced 2025-09-20 02:53:57 +02:00
merge revision(s) 34413:
* 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/branches/ruby_1_9_3@34572 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
c9fac6977b
commit
66f39c771a
3 changed files with 27 additions and 17 deletions
|
@ -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)
|
||||
tmpfile.close if tmpfile
|
||||
|
||||
if path
|
||||
begin
|
||||
File.unlink(path)
|
||||
rescue Errno::ENOENT
|
||||
end
|
||||
|
||||
STDERR.print "done\n" if $DEBUG
|
||||
end
|
||||
|
||||
STDERR.print "done\n" if $DEBUG
|
||||
end
|
||||
end
|
||||
# :startdoc:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue