Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions lib/tmpdir.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,18 @@ class Dir
##
# Returns the operating system's temporary file path.

def self.get_systmpdir
if defined?(Ractor) && (Ractor.current != Ractor.main)
defined?(Etc.systmpdir) ? Etc.systmpdir : '/tmp'
else
@@systmpdir
end
end
private_class_method :get_systmpdir

def self.tmpdir
tmp = nil
['TMPDIR', 'TMP', 'TEMP', ['system temporary path', @@systmpdir], ['/tmp']*2, ['.']*2].each do |name, dir = ENV[name]|
['TMPDIR', 'TMP', 'TEMP', ['system temporary path', get_systmpdir], ['/tmp']*2, ['.']*2].each do |name, dir = ENV[name]|
next if !dir
dir = File.expand_path(dir)
stat = File.stat(dir) rescue next
Expand Down Expand Up @@ -117,13 +126,14 @@ def tmpdir

UNUSABLE_CHARS = "^,-.0-9A-Z_a-z~"

class << (RANDOM = Random.new)
class << (RANDOM = Object.new)
MAX = 36**6 # < 0x100000000
def next
rand(MAX).to_s(36)
end
end
private_constant :RANDOM
Ractor.make_shareable(RANDOM) if defined?(Ractor)

def create(basename, tmpdir=nil, max_try: nil, **opts)
origdir = tmpdir
Expand Down