summaryrefslogtreecommitdiff
path: root/lib/tmpdir.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/tmpdir.rb')
-rw-r--r--lib/tmpdir.rb34
1 files changed, 13 insertions, 21 deletions
diff --git a/lib/tmpdir.rb b/lib/tmpdir.rb
index d7a8f799fe..ea1d380ef1 100644
--- a/lib/tmpdir.rb
+++ b/lib/tmpdir.rb
@@ -19,22 +19,18 @@ class Dir
# Returns the operating system's temporary file path.
def self.tmpdir
- if $SAFE > 0
- @@systmpdir.dup
- else
- tmp = nil
- [ENV['TMPDIR'], ENV['TMP'], ENV['TEMP'], @@systmpdir, '/tmp', '.'].each do |dir|
- 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
- raise ArgumentError, "could not find a temporary directory" unless tmp
- tmp
+ tmp = nil
+ [ENV['TMPDIR'], ENV['TMP'], ENV['TEMP'], @@systmpdir, '/tmp', '.'].each do |dir|
+ 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
+ raise ArgumentError, "could not find a temporary directory" unless tmp
+ tmp
end
# Dir.mktmpdir creates a temporary directory.
@@ -115,12 +111,8 @@ class Dir
UNUSABLE_CHARS = [File::SEPARATOR, File::ALT_SEPARATOR, File::PATH_SEPARATOR, ":"].uniq.join("").freeze
def create(basename, tmpdir=nil, max_try: nil, **opts)
- if $SAFE > 0 and tmpdir.tainted?
- tmpdir = '/tmp'
- else
- origdir = tmpdir
- tmpdir ||= tmpdir()
- end
+ origdir = tmpdir
+ tmpdir ||= tmpdir()
n = nil
prefix, suffix = basename
prefix = (String.try_convert(prefix) or