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#close!, Tempfile#path): added side

notes from Hongli Lai's fork.

* lib/tempfile.rb (Tempfile#unlink, Tempfile.callback): do nothing
  any more once unlinked.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@24663 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2009-08-26 05:34:47 +00:00
parent d4e85c416d
commit ba7a870a89
2 changed files with 20 additions and 7 deletions

View file

@ -1,3 +1,11 @@
Wed Aug 26 14:34:39 2009 Nobuyoshi Nakada <nobu@ruby-lang.org>
* lib/tempfile.rb (Tempfile#close!, Tempfile#path): added side
notes from Hongli Lai's fork.
* lib/tempfile.rb (Tempfile#unlink, Tempfile.callback): do nothing
any more once unlinked.
Wed Aug 26 13:48:33 2009 Nobuyoshi Nakada <nobu@ruby-lang.org>
* lib/tempfile.rb (Tempfile#unlink): reverted r23494, since the

View file

@ -11,7 +11,7 @@ require 'thread'
# A class for managing temporary files. This library is written to be
# thread safe.
class Tempfile < DelegateClass(File)
MAX_TRY = 10
MAX_TRY = 10 # :nodoc:
@@cleanlist = []
@@lock = Mutex.new
@ -53,7 +53,7 @@ class Tempfile < DelegateClass(File)
rescue
failure += 1
retry if failure < MAX_TRY
raise "cannot generate tempfile `%s'" % tmpname
raise "cannot generate tempfile `#{tmpname}'"
end
}
@ -122,11 +122,10 @@ class Tempfile < DelegateClass(File)
end
# Closes and unlinks the file.
# Has the same effect as called <tt>close(true)</tt>.
def close!
_close
@clean_proc.call
ObjectSpace.undefine_finalizer(self)
@data = @tmpname = nil
unlink
end
# Unlinks the file. On UNIX-like systems, it is often a good idea
@ -135,11 +134,14 @@ class Tempfile < DelegateClass(File)
# file.
def unlink
# keep this order for thread safeness
return unless @tmpname
begin
if File.exist?(@tmpname)
File.unlink(@tmpname)
end
@@cleanlist.delete(@tmpname)
# remove tmpname and cleanlist from callback
@data[0] = @data[2] = nil
@data = @tmpname = nil
ObjectSpace.undefine_finalizer(self)
rescue Errno::EACCES
@ -149,6 +151,7 @@ class Tempfile < DelegateClass(File)
alias delete unlink
# Returns the full path name of the temporary file.
# This will be nil if #unlink has been called.
def path
@tmpname
end
@ -177,8 +180,10 @@ class Tempfile < DelegateClass(File)
tmpfile.close if tmpfile
# keep this order for thread safeness
File.unlink(path) if File.exist?(path)
cleanlist.delete(path) if cleanlist
if path
File.unlink(path) if File.exist?(path)
cleanlist.delete(path) if cleanlist
end
print "done\n" if $DEBUG
end