From 001884f62336ab57361bf49fc463778b78d2c76c Mon Sep 17 00:00:00 2001 From: akr Date: Sun, 13 Sep 2009 13:16:55 +0000 Subject: [PATCH] * lib/tempfile.rb (Tempfile::Remover): new class to replace Tempfile.callback. [ruby-core:17824] [ruby-dev:39271] See [ruby-dev:39317] for the reason. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@24902 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 6 ++++++ lib/tempfile.rb | 42 +++++++++++++++++++++++------------------- 2 files changed, 29 insertions(+), 19 deletions(-) diff --git a/ChangeLog b/ChangeLog index 6fb2bf3c55..636de74ffd 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +Sun Sep 13 22:13:35 2009 Tanaka Akira + + * lib/tempfile.rb (Tempfile::Remover): new class to replace + Tempfile.callback. [ruby-core:17824] [ruby-dev:39271] + See [ruby-dev:39317] for the reason. + Sun Sep 13 11:06:12 2009 Tanaka Akira * lib/open-uri.rb (OpenURI::Meta#content_type_parse): strip quotes. diff --git a/lib/tempfile.rb b/lib/tempfile.rb index c984cd3393..97edd53db0 100644 --- a/lib/tempfile.rb +++ b/lib/tempfile.rb @@ -55,7 +55,7 @@ class Tempfile < DelegateClass(File) end @data = [tmpname] - @clean_proc = Tempfile.callback(@data) + @clean_proc = Tempfile::Remover.new(@data) ObjectSpace.define_finalizer(self, @clean_proc) @tmpfile = File.open(tmpname, File::RDWR|File::CREAT|File::EXCL, 0600) @@ -155,26 +155,30 @@ class Tempfile < DelegateClass(File) end alias length size - class << self - def callback(data) # :nodoc: - pid = $$ - lambda{ - if pid == $$ - path, tmpfile, cleanlist = *data - - print "removing ", path, "..." if $DEBUG - - tmpfile.close if tmpfile - - # keep this order for thread safeness - File.unlink(path) if File.exist?(path) - cleanlist.delete(path) if cleanlist - - print "done\n" if $DEBUG - end - } + class Remover # :nodoc: + def initialize(data) + @pid = $$ + @data = data end + def call(arg=nil) + if @pid == $$ + path, tmpfile, cleanlist = *@data + + print "removing ", path, "..." if $DEBUG + + tmpfile.close if tmpfile + + # keep this order for thread safeness + File.unlink(path) if File.exist?(path) + cleanlist.delete(path) if cleanlist + + print "done\n" if $DEBUG + end + end + end + + class << self # If no block is given, this is a synonym for new(). # # If a block is given, it will be passed tempfile as an argument,