diff options
-rw-r--r-- | ChangeLog | 5 | ||||
-rw-r--r-- | lib/tmpdir.rb | 11 |
2 files changed, 12 insertions, 4 deletions
@@ -1,3 +1,8 @@ +Mon Mar 12 20:19:25 2012 Tanaka Akira <akr@fsij.org> + + * lib/tmpdir.rb (Dir::tmpdir): test the current directory suitable for + temporary directory. + Mon Mar 12 20:08:16 2012 Tanaka Akira <akr@fsij.org> * lib/fileutils.rb (fu_have_symlink?): specify TypeError for rescue diff --git a/lib/tmpdir.rb b/lib/tmpdir.rb index 37af025065..03c02fd788 100644 --- a/lib/tmpdir.rb +++ b/lib/tmpdir.rb @@ -18,18 +18,21 @@ class Dir # Returns the operating system's temporary file path. def Dir::tmpdir - tmp = '.' if $SAFE > 0 tmp = @@systmpdir else - for dir in [ENV['TMPDIR'], ENV['TMP'], ENV['TEMP'], @@systmpdir, '/tmp'] - if dir and stat = File.stat(dir) and stat.directory? and stat.writable? and + tmp = nil + for dir in [ENV['TMPDIR'], ENV['TMP'], ENV['TEMP'], @@systmpdir, '/tmp', '.'] + 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?) tmp = dir break end rescue nil end - File.expand_path(tmp) + raise ArgumentError, "could not find a temporary directory" if !tmp + tmp end end |