lib/rio/tempdir.rb in rio-0.4.2 vs lib/rio/tempdir.rb in rio-0.5.1
- old
+ new
@@ -25,13 +25,14 @@
proposal of nobu.nokada@softhome.net. He added the class to
tempfile.rb, but since it does not seem to appear in cvs, I'll keep
it apart in tempdir.rb.
=end
-
require 'tmpdir'
+
+
module AutoRemoval #:nodoc: all
MAX_TRY = 10
@@cleanlist = []
private
@@ -48,23 +49,13 @@
lock = nil
n = failure = 0
begin
- Thread.critical = true
- begin
- tmpname = File.join(tmpdir, make_tmpname(basename, n))
- n += 1
- end until !@@cleanlist.include?(tmpname) and yield(tmpname)
- rescue
- p $!
- failure += 1
- retry if failure < MAX_TRY
- raise "cannot generate tempfile `%s'" % tmpname
- ensure
- Thread.critical = false
- end
+ tmpname = File.join(tmpdir, make_tmpname(basename, n))
+ n += 1
+ end until !@@cleanlist.include?(tmpname) and yield(tmpname)
tmpname
end
def self.callback(path, clear) # :nodoc:
@@ -100,12 +91,12 @@
include AutoRemoval
def initialize(*args)
require 'fileutils'
- tmpname = createtmp(*args) do |tmpname|
- unless File.exist?(tmpname)
- Dir.mkdir(tmpname, 0700)
+ tmpname = createtmp(*args) do |tname|
+ unless File.exist?(tname)
+ FileUtils.mkpath(tname, :mode => 0700)
end
end
super(tmpname)
@clean_proc, = AutoRemoval.callback(tmpname, FileUtils.method(:rm_rf))