Skip to content
Merged
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
18 changes: 13 additions & 5 deletions lib/tmpdir.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,14 @@ class Dir
# Class variables are inaccessible from non-main Ractor.
# And instance variables too, in Ruby 3.0.

# System-wide temporary directory path
SYSTMPDIR = (defined?(Etc.systmpdir) ? Etc.systmpdir.freeze : '/tmp')
private_constant :SYSTMPDIR

##
# Returns the operating system's temporary file path.
#
# require 'tmpdir'
# Dir.tmpdir # => "/tmp"

def self.tmpdir
['TMPDIR', 'TMP', 'TEMP', ['system temporary path', SYSTMPDIR], ['/tmp']*2, ['.']*2].find do |name, dir|
Tmpname::TMPDIR_CANDIDATES.find do |name, dir|
unless dir
next if !(dir = ENV[name] rescue next) or dir.empty?
end
Expand Down Expand Up @@ -126,6 +122,18 @@ def self.mktmpdir(prefix_suffix=nil, *rest, **options, &block)
module Tmpname # :nodoc:
module_function

# System-wide temporary directory path
systmpdir = (defined?(Etc.systmpdir) ? Etc.systmpdir.freeze : '/tmp')

# Temporary directory candidates consisting of environment variable
# names or description and path pairs.
TMPDIR_CANDIDATES = [
'TMPDIR', 'TMP', 'TEMP',
['system temporary path', systmpdir],
%w[/tmp /tmp],
%w[. .],
].each(&:freeze).freeze

def tmpdir
Dir.tmpdir
end
Expand Down
Loading