Module: Bundler::Dir::Tmpname
Do not use. This module is for internal use only.
Relationships & Source Files | |
Defined in: | lib/bundler/vendor/tmpdir/lib/tmpdir.rb |
Constant Summary
-
UNUSABLE_CHARS =
# File 'lib/bundler/vendor/tmpdir/lib/tmpdir.rb', line 118"^,-.0-9A-Z_a-z~"
Class Method Summary
- .create(basename, tmpdir = nil, max_try: nil, **opts) mod_func
- .tmpdir mod_func
Class Method Details
.create(basename, tmpdir = nil, max_try: nil, **opts) (mod_func)
[ GitHub ]# File 'lib/bundler/vendor/tmpdir/lib/tmpdir.rb', line 128
def create(basename, tmpdir=nil, max_try: nil, **opts) origdir = tmpdir tmpdir ||= tmpdir() n = nil prefix, suffix = basename prefix = (String.try_convert(prefix) or raise ArgumentError, "unexpected prefix: #{prefix.inspect}") prefix = prefix.delete(UNUSABLE_CHARS) suffix &&= (String.try_convert(suffix) or raise ArgumentError, "unexpected suffix: #{suffix.inspect}") suffix &&= suffix.delete(UNUSABLE_CHARS) begin t = Time.now.strftime("%Y%m%d") path = "#{prefix}#{t}-#{$$}-#{RANDOM.next}"\ "#{n ? %[-#{n}] : ''}#{suffix||''}" path = File.join(tmpdir, path) yield(path, n, opts, origdir) rescue Errno::EEXIST n ||= 0 n += 1 retry if !max_try or n < max_try raise "cannot generate temporary name using `#{basename}' under `#{tmpdir}'" end path end