23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
# File 'lib/tmpdir_block.rb', line 23
def tmpdir(*args, &block)
options = Hash === args.last ? args.pop : {}
dirname = Super.call(*args)
return dirname unless block
turd = options['turd'] || options[:turd]
basename = [
Hostname,
Ppid,
Pid,
Thread.current.object_id.abs,
rand
].join('-')
42.times do |n|
pathname = File.join(dirname, "#{ basename }-n=#{ n }")
begin
FileUtils.mkdir_p(pathname)
rescue Object => e
sleep(rand)
next
end
begin
return Dir.chdir(pathname, &block)
ensure
FileUtils.rm_rf(pathname) unless turd
end
end
raise Error, "failed to make tmpdir in #{ dirname.inspect }"
end
|