diff options
author | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2000-02-29 08:05:32 +0000 |
---|---|---|
committer | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2000-02-29 08:05:32 +0000 |
commit | 5928d4c1e01a076c3c992b3a003c167a5d4b7600 (patch) | |
tree | 3e43148d3114380fff1418aa3ff6d01b157a97e4 /lib/tempfile.rb | |
parent | ac9d16f8b62f24b7bb7190888b6bc28cf2e75af9 (diff) | |
download | ruby-5928d4c1e01a076c3c992b3a003c167a5d4b7600.tar.gz ruby-5928d4c1e01a076c3c992b3a003c167a5d4b7600.tar.xz ruby-5928d4c1e01a076c3c992b3a003c167a5d4b7600.zip |
2000-02-29
git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@629 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/tempfile.rb')
-rw-r--r-- | lib/tempfile.rb | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/lib/tempfile.rb b/lib/tempfile.rb index 11a8fba97..c43228530 100644 --- a/lib/tempfile.rb +++ b/lib/tempfile.rb @@ -15,9 +15,10 @@ require 'final' class Tempfile < SimpleDelegator Max_try = 10 - def Tempfile.callback(path) + def Tempfile.callback(path, data) lambda{ print "removing ", path, "..." if $DEBUG + data[0].close if data[0] if File.exist?(path) File.unlink(path) end @@ -47,10 +48,12 @@ class Tempfile < SimpleDelegator n += 1 end - @clean_files = Tempfile.callback(tmpname) + @protect = [] + @clean_files = Tempfile.callback(tmpname, @protect) ObjectSpace.define_finalizer(self, @clean_files) @tmpfile = File.open(tmpname, 'w+') + @protect[0] = @tmpfile @tmpname = tmpname super(@tmpfile) Dir.rmdir(lock) @@ -66,12 +69,13 @@ class Tempfile < SimpleDelegator def open @tmpfile.close if @tmpfile @tmpfile = File.open(@tmpname, 'r+') + @protect[0] = @tmpfile __setobj__(@tmpfile) end def close(real=false) @tmpfile.close if @tmpfile - @tmpfile = nil + @protect[0] = @tmpfile = nil if real @clean_files.call ObjectSpace.undefine_finalizer(self) |