ruby-changes:12925
From: nobu <ko1@a...>
Date: Wed, 26 Aug 2009 14:35:04 +0900 (JST)
Subject: [ruby-changes:12925] Ruby:r24663 (trunk): * lib/tempfile.rb (Tempfile#close!, Tempfile#path): added side
nobu 2009-08-26 14:34:47 +0900 (Wed, 26 Aug 2009) New Revision: 24663 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=24663 Log: * 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. Modified files: trunk/ChangeLog trunk/lib/tempfile.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 24662) +++ ChangeLog (revision 24663) @@ -1,3 +1,11 @@ +Wed Aug 26 14:34:39 2009 Nobuyoshi Nakada <nobu@r...> + + * 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@r...> * lib/tempfile.rb (Tempfile#unlink): reverted r23494, since the Index: lib/tempfile.rb =================================================================== --- lib/tempfile.rb (revision 24662) +++ lib/tempfile.rb (revision 24663) @@ -11,7 +11,7 @@ # 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 @@ rescue failure += 1 retry if failure < MAX_TRY - raise "cannot generate tempfile `%s'" % tmpname + raise "cannot generate tempfile `#{tmpname}'" end } @@ -122,11 +122,10 @@ 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 @@ # 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 @@ 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 @@ 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 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/