From 65ab6ea40e4285f54d1c5f10260c020337dac0df Mon Sep 17 00:00:00 2001 From: Melissa Stone Date: Wed, 27 May 2020 11:07:34 -0700 Subject: [PATCH] (PUP-10537) Ruby 2.7 warning: $SAFE `warning: $SAFE will become a normal global variable in Ruby 3.0` `$SAFE` and `taint` are deprecated concepts. See: https://rubyreferences.github.io/rubychanges/2.7.html#safe-and-taint-concepts-are-deprecated-in-general This is largely based on changes in https://github.com/ruby/ruby/commit/c5c05460ac20abcbc0ed686eb4acf06da7a39a79 This code was originally introduced by https://github.com/puppetlabs/puppet/commit/19cf4beef924916a5a18d07f3b21ef13f3dd2e56, which was based on the ruby code. It makes sense to follow their logic on how we extract `$SAFE` from our code. --- lib/puppet/file_system/uniquefile.rb | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/lib/puppet/file_system/uniquefile.rb b/lib/puppet/file_system/uniquefile.rb index 50bf0b8a711..594711a63f7 100644 --- a/lib/puppet/file_system/uniquefile.rb +++ b/lib/puppet/file_system/uniquefile.rb @@ -124,11 +124,7 @@ def create_tmpname(basename, *rest) opts = [] end tmpdir, = *rest - if $SAFE > 0 and tmpdir.tainted? - tmpdir = '/tmp' - else - tmpdir ||= tmpdir() - end + tmpdir ||= tmpdir() n = nil begin path = File.expand_path(make_tmpname(basename, n), tmpdir) @@ -154,18 +150,14 @@ def try_convert_to_hash(h) def tmpdir tmp = '.' - if $SAFE > 0 - @@systmpdir - else - for dir in [ Puppet::Util.get_env('TMPDIR'), Puppet::Util.get_env('TMP'), Puppet::Util.get_env('TEMP'), @@systmpdir, '/tmp'] - stat = File.stat(dir) if dir - if stat && stat.directory? && stat.writable? - tmp = dir - break - end rescue nil - end - File.expand_path(tmp) + for dir in [ Puppet::Util.get_env('TMPDIR'), Puppet::Util.get_env('TMP'), Puppet::Util.get_env('TEMP'), @@systmpdir, '/tmp'] + stat = File.stat(dir) if dir + if stat && stat.directory? && stat.writable? + tmp = dir + break + end rescue nil end + File.expand_path(tmp) end