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::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
This commit is contained in:
akr 2009-09-13 13:16:55 +00:00
parent 3d93c5198f
commit 001884f623
2 changed files with 29 additions and 19 deletions

View file

@ -1,3 +1,9 @@
Sun Sep 13 22:13:35 2009 Tanaka Akira <akr@fsij.org>
* 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 <akr@fsij.org>
* lib/open-uri.rb (OpenURI::Meta#content_type_parse): strip quotes.

View file

@ -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,