From be554930577e0c7417a8c60244a5295557b8b4eb Mon Sep 17 00:00:00 2001 From: Jeremy Evans Date: Thu, 22 Jun 2023 15:54:11 -0700 Subject: [PATCH] Allow Dir.tmpdir to work inside a Ractor Switch class variable usage to private constant, and make sure the constant is frozen. Fixes [Bug #18933] --- lib/tmpdir.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/tmpdir.rb b/lib/tmpdir.rb index 55920a4..a44bd19 100644 --- a/lib/tmpdir.rb +++ b/lib/tmpdir.rb @@ -12,14 +12,14 @@ end class Dir - - @@systmpdir ||= defined?(Etc.systmpdir) ? Etc.systmpdir : '/tmp' + SYSTMPDIR = defined?(Etc.systmpdir) ? Etc.systmpdir.dup.freeze : '/tmp' + private_constant :SYSTMPDIR ## # Returns the operating system's temporary file path. def self.tmpdir - ['TMPDIR', 'TMP', 'TEMP', ['system temporary path', @@systmpdir], ['/tmp']*2, ['.']*2].find do |name, dir| + ['TMPDIR', 'TMP', 'TEMP', ['system temporary path', SYSTMPDIR], ['/tmp']*2, ['.']*2].find do |name, dir| unless dir next if !(dir = ENV[name]) or dir.empty? end