aboutsummaryrefslogtreecommitdiffstats
path: root/lib/tmpdir.rb
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-03-12 11:19:42 +0000
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-03-12 11:19:42 +0000
commitb681457f018c9d8ef2233a2f97ab998d629182c9 (patch)
treeae4cca0ffaf43e27c9f4a3bed57d12a1ee6771db /lib/tmpdir.rb
parent5e3009aa4557bdb7e5e70e4e38fea7b21d1867f0 (diff)
downloadruby-b681457f018c9d8ef2233a2f97ab998d629182c9.tar.gz
* lib/tmpdir.rb (Dir::tmpdir): test the current directory suitable for
temporary directory. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@34988 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/tmpdir.rb')
-rw-r--r--lib/tmpdir.rb11
1 files changed, 7 insertions, 4 deletions
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