diff options
author | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 1998-07-29 09:50:58 +0000 |
---|---|---|
committer | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 1998-07-29 09:50:58 +0000 |
commit | 2562004338bc2694a7d8da75f4effcb9aa889641 (patch) | |
tree | 0af9582deace7d436b411552640555f90d7cd9fa /lib/tempfile.rb | |
parent | 3b0fec9a5f966fd7ae26bc7b84877fa7209d8605 (diff) |
sync ev
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/v1_1r@280 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/tempfile.rb')
-rw-r--r-- | lib/tempfile.rb | 24 |
1 files changed, 14 insertions, 10 deletions
diff --git a/lib/tempfile.rb b/lib/tempfile.rb index 9f23075147..2de1ebddf3 100644 --- a/lib/tempfile.rb +++ b/lib/tempfile.rb @@ -17,41 +17,44 @@ class Tempfile < SimpleDelegator def Tempfile.callback(path) lambda{ - print "removing ", path, "..." + print "removing ", path, "..." if $DEBUG if File.exist?(path) File.unlink(path) end if File.exist?(path + '.lock') - File.unlink(path + '.lock') + File.rmdir(path + '.lock') end - print "done\n" + print "done\n" if $DEBUG } end def initialize(basename, tmpdir = '/tmp') umask = File.umask(0177) + tmpname = lock = nil begin n = 0 while true begin - @tmpname = sprintf('%s/%s.%d.%d', tmpdir, basename, $$, n) - unless File.exist?(@tmpname) - File.symlink(tmpdir, @tmpname + '.lock') + tmpname = sprintf('%s/%s.%d.%d', tmpdir, basename, $$, n) + lock = tmpname + '.lock' + unless File.exist?(lock) + Dir.mkdir(lock) break end rescue - raise "cannot generate tmpfile `%s'" % @tmpname if n >= Max_try + raise "cannot generate tmpfile `%s'" % tmpname if n >= Max_try #sleep(1) end n += 1 end - @clean_files = Tempfile.callback(@tmpname) + @clean_files = Tempfile.callback(tmpname) ObjectSpace.define_finalizer(self, @clean_files) - @tmpfile = File.open(@tmpname, 'w+') + @tmpname = tmpname + @tmpfile = File.open(tmpname, 'w+') super(@tmpfile) - File.unlink(@tmpname + '.lock') + Dir.rmdir(lock) ensure File.umask(umask) end @@ -78,6 +81,7 @@ class Tempfile < SimpleDelegator end if __FILE__ == $0 +# $DEBUG = true f = Tempfile.new("foo") f.print("foo\n") f.close |