diff options
author | glass <glass@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2014-09-20 17:35:06 +0000 |
---|---|---|
committer | glass <glass@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2014-09-20 17:35:06 +0000 |
commit | 09e91be9abbaa7e363d15ba6654afc9e667af4aa (patch) | |
tree | b41ed6d9208a402c0c5d14912ba94fca99bc8f9b /lib/tmpdir.rb | |
parent | 997d5acdc70b6a1b5a9336e41d72818675d99448 (diff) |
* lib/tempfile.rb: define parameters appropriately and some
refactoring.
* lib/tmpdir.rb: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47655 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/tmpdir.rb')
-rw-r--r-- | lib/tmpdir.rb | 22 |
1 files changed, 7 insertions, 15 deletions
diff --git a/lib/tmpdir.rb b/lib/tmpdir.rb index 409d779b8a..0b21f00d8e 100644 --- a/lib/tmpdir.rb +++ b/lib/tmpdir.rb @@ -17,12 +17,12 @@ class Dir ## # Returns the operating system's temporary file path. - def Dir::tmpdir + def self.tmpdir if $SAFE > 0 @@systmpdir else tmp = nil - for dir in [ENV['TMPDIR'], ENV['TMP'], ENV['TEMP'], @@systmpdir, '/tmp', '.'] + [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 @@ -31,7 +31,7 @@ class Dir break end rescue nil end - raise ArgumentError, "could not find a temporary directory" if !tmp + raise ArgumentError, "could not find a temporary directory" unless tmp tmp end end @@ -81,8 +81,8 @@ class Dir # FileUtils.remove_entry dir # end # - def Dir.mktmpdir(prefix_suffix=nil, *rest) - path = Tmpname.create(prefix_suffix || "d", *rest) {|n| mkdir(n, 0700)} + def Dir.mktmpdir(prefix_suffix="d", *rest) + path = Tmpname.create(prefix_suffix, *rest) {|n| mkdir(n, 0700)} if block_given? begin yield path @@ -122,15 +122,7 @@ class Dir path << suffix end - def create(basename, *rest) - if opts = Hash.try_convert(rest[-1]) - opts = opts.dup if rest.pop.equal?(opts) - max_try = opts.delete(:max_try) - opts = [opts] - else - opts = [] - end - tmpdir, = *rest + def create(basename, tmpdir=nil, max_try: nil, **opts) if $SAFE > 0 and tmpdir.tainted? tmpdir = '/tmp' else @@ -139,7 +131,7 @@ class Dir n = nil begin path = File.join(tmpdir, make_tmpname(basename, n)) - yield(path, n, *opts) + yield(path, n, opts) rescue Errno::EEXIST n ||= 0 n += 1 |