Created
November 2, 2012 15:37
-
-
Save doxavore/4002071 to your computer and use it in GitHub Desktop.
JRuby Dir.tmpdir
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def Dir::tmpdir | |
tmp = '.' | |
if $SAFE > 0 | |
tmp = @@systmpdir | |
else | |
# Search a directory which isn't world-writable first. In JRuby, | |
# FileUtils.remove_entry_secure(dir) crashes when a dir is under | |
# a world-writable directory because it tries to open directory. | |
# Opening directory is not allowed in Java. | |
dirs = [ENV['TMPDIR'], ENV['TMP'], ENV['TEMP'], @@systmpdir, '/tmp', tmp] | |
for dir in dirs | |
if dir and stat = File.stat(dir) and stat.directory? and stat.writable? and !stat.world_writable? | |
return File.expand_path(dir) | |
end rescue nil | |
end | |
for dir in dirs | |
if dir and stat = File.stat(dir) and stat.directory? and stat.writable? | |
tmp = dir | |
break | |
end rescue nil | |
end | |
File.expand_path(tmp) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment