ruby-changes:2140
From: ko1@a...
Date: 5 Oct 2007 15:44:23 +0900
Subject: [ruby-changes:2140] knu - Ruby:r13631 (ruby_1_8): * lib/tempfile.rb (Tempfile::make_tmpname): Allow to specify a
knu 2007-10-05 15:44:14 +0900 (Fri, 05 Oct 2007) New Revision: 13631 Modified files: branches/ruby_1_8/ChangeLog branches/ruby_1_8/lib/tempfile.rb Log: * lib/tempfile.rb (Tempfile::make_tmpname): Allow to specify a suffix for a temporary file name. * lib/tempfile.rb (Tempfile::make_tmpname): Make temporary file names less predictable by including a random string. [inspired by: akr] http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/branches/ruby_1_8/ChangeLog?r1=13631&r2=13630 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/branches/ruby_1_8/lib/tempfile.rb?r1=13631&r2=13630 Index: ruby_1_8/ChangeLog =================================================================== --- ruby_1_8/ChangeLog (revision 13630) +++ ruby_1_8/ChangeLog (revision 13631) @@ -1,3 +1,12 @@ +Fri Oct 5 15:40:04 2007 Akinori MUSHA <knu@i...> + + * lib/tempfile.rb (Tempfile::make_tmpname): Allow to specify a + suffix for a temporary file name. + + * lib/tempfile.rb (Tempfile::make_tmpname): Make temporary file + names less predictable by including a random string. + [inspired by: akr] + Tue Oct 2 21:20:14 2007 NAKAMURA Usaku <usa@r...> * win32/win32.c (make_cmdvector): adjust escaped successive Index: ruby_1_8/lib/tempfile.rb =================================================================== --- ruby_1_8/lib/tempfile.rb (revision 13630) +++ ruby_1_8/lib/tempfile.rb (revision 13631) @@ -13,10 +13,16 @@ MAX_TRY = 10 @@cleanlist = [] - # Creates a temporary file of mode 0600 in the temporary directory - # whose name is basename.pid.n and opens with mode "w+". A Tempfile - # object works just like a File object. + # Creates a temporary file of mode 0600 in the temporary directory, + # opens it with mode "w+", and returns a Tempfile object which + # represents the created temporary file. A Tempfile object can be + # treated just like a normal File object. # + # The basename parameter is used to determine the name of a + # temporary file. If an Array is given, the first element is used + # as prefix string and the second as suffix string, respectively. + # Otherwise it is treated as prefix string. + # # If tmpdir is omitted, the temporary directory is determined by # Dir::tmpdir provided by 'tmpdir.rb'. # When $SAFE > 0 and the given tmpdir is tainted, it uses @@ -67,7 +73,15 @@ end def make_tmpname(basename, n) - sprintf('%s.%d.%d', basename, $$, n) + case basename + when Array + prefix, suffix = *basename + else + prefix, suffix = basename, '' + end + + t = Time.now.strftime("%Y%m%d") + path = "#{prefix}#{t}-#{$$}-#{rand(0x100000000).to_s(36)}-#{n}#{suffix}" end private :make_tmpname -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml