diff options
author | Nobuyoshi Nakada <[email protected]> | 2020-07-16 17:45:08 +0900 |
---|---|---|
committer | Hiroshi SHIBATA <[email protected]> | 2020-09-14 18:22:37 +0900 |
commit | edb5c67195129e1d10f329edb55e486e1874b20e (patch) | |
tree | 730b762e56096970b2093f851fd8eb99cd5d1a24 /lib/tmpdir.rb | |
parent | df1c035d0381e41a78ebc55b0450bab39b542cf2 (diff) |
[ruby/tmpdir] Warn when environment variables skipped (fixes #2)
https://github.com/ruby/tmpdir/commit/af7b020a89
Diffstat (limited to 'lib/tmpdir.rb')
-rw-r--r-- | lib/tmpdir.rb | 15 |
1 files changed, 11 insertions, 4 deletions
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 |