From edb5c67195129e1d10f329edb55e486e1874b20e Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada Date: Thu, 16 Jul 2020 17:45:08 +0900 Subject: [ruby/tmpdir] Warn when environment variables skipped (fixes #2) https://github.com/ruby/tmpdir/commit/af7b020a89 --- lib/tmpdir.rb | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'lib/tmpdir.rb') diff --git a/lib/tmpdir.rb b/lib/tmpdir.rb index e6cb327fc7..0b1f00aecf 100644 --- a/lib/tmpdir.rb +++ b/lib/tmpdir.rb @@ -20,14 +20,21 @@ class Dir def self.tmpdir tmp = nil - [ENV['TMPDIR'], ENV['TMP'], ENV['TEMP'], @@systmpdir, '/tmp', '.'].each do |dir| + ['TMPDIR', 'TMP', 'TEMP', ['system temporary path', @@systmpdir], ['/tmp']*2, ['.']*2].each do |name, dir = ENV[name]| next if !dir dir = File.expand_path(dir) - if stat = File.stat(dir) and stat.directory? and stat.writable? and - (!stat.world_writable? or stat.sticky?) + stat = File.stat(dir) rescue next + case + when !stat.directory? + warn "#{name} is not a directory: #{dir}" + when !stat.writable? + warn "#{name} is not writable: #{dir}" + when stat.world_writable? && !stat.sticky? + warn "#{name} is world-writable: #{dir}" + else tmp = dir break - end rescue nil + end end raise ArgumentError, "could not find a temporary directory" unless tmp tmp -- cgit v1.2.3