diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/tmpdir.rb | 22 |
1 files changed, 9 insertions, 13 deletions
diff --git a/lib/tmpdir.rb b/lib/tmpdir.rb index d12afa1ae6..e30004c0bb 100644 --- a/lib/tmpdir.rb +++ b/lib/tmpdir.rb @@ -106,18 +106,6 @@ class Dir Dir.tmpdir end - def make_tmpname((prefix, suffix), n) - prefix = (String.try_convert(prefix) or - raise ArgumentError, "unexpected prefix: #{prefix.inspect}") - suffix &&= (String.try_convert(suffix) or - raise ArgumentError, "unexpected suffix: #{suffix.inspect}") - t = Time.now.strftime("%Y%m%d") - path = "#{prefix}#{t}-#{$$}-#{rand(0x100000000).to_s(36)}".dup - path << "-#{n}" if n - path << suffix if suffix - path - end - def create(basename, tmpdir=nil, max_try: nil, **opts) if $SAFE > 0 and tmpdir.tainted? tmpdir = '/tmp' @@ -125,8 +113,16 @@ class Dir tmpdir ||= tmpdir() end n = nil + prefix, suffix = basename + prefix = (String.try_convert(prefix) or + raise ArgumentError, "unexpected prefix: #{prefix.inspect}") + suffix &&= (String.try_convert(suffix) or + raise ArgumentError, "unexpected suffix: #{suffix.inspect}") begin - path = File.join(tmpdir, make_tmpname(basename, n)) + t = Time.now.strftime("%Y%m%d") + path = "#{prefix}#{t}-#{$$}-#{rand(0x100000000).to_s(36)}"\ + "#{n ? %[-#{n}] : ''}#{suffix||''}" + path = File.join(tmpdir, path) yield(path, n, opts) rescue Errno::EEXIST n ||= 0 |