ruby-changes:15205
From: nobu <ko1@a...>
Date: Mon, 29 Mar 2010 15:12:06 +0900 (JST)
Subject: [ruby-changes:15205] Ruby:r27086 (trunk): * lib/tempfile.rb (Tempfile#open): re-open with same mode and
nobu 2010-03-29 15:11:48 +0900 (Mon, 29 Mar 2010) New Revision: 27086 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=27086 Log: * lib/tempfile.rb (Tempfile#open): re-open with same mode and options as initialize. Modified files: trunk/ChangeLog trunk/lib/tempfile.rb trunk/test/test_tempfile.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 27085) +++ ChangeLog (revision 27086) @@ -1,3 +1,8 @@ +Mon Mar 29 15:10:39 2010 Nobuyoshi Nakada <nobu@r...> + + * lib/tempfile.rb (Tempfile#open): re-open with same mode and + options as initialize. + Mon Mar 29 09:16:45 2010 NARUSE, Yui <naruse@r...> * random.c: change include order; ruby.h should be at first. Index: lib/tempfile.rb =================================================================== --- lib/tempfile.rb (revision 27085) +++ lib/tempfile.rb (revision 27086) @@ -138,6 +138,7 @@ if opts mode |= opts.delete(:mode) || 0 opts[:perm] = perm + perm = nil else opts = perm end @@ -148,6 +149,9 @@ ensure self.class.rmdir(lock) end + @mode = mode & ~(File::CREAT|File::EXCL) + perm or opts.freeze + @opts = opts end super(@tmpfile) @@ -156,7 +160,7 @@ # Opens or reopens the file with mode "r+". def open @tmpfile.close if @tmpfile - @tmpfile = File.open(@tmpname, 'r+') + @tmpfile = File.open(@tmpname, @mode, @opts) @data[1] = @tmpfile __setobj__(@tmpfile) end Index: test/test_tempfile.rb =================================================================== --- test/test_tempfile.rb (revision 27085) +++ test/test_tempfile.rb (revision 27086) @@ -294,6 +294,8 @@ t = tempfile("TEST", mode: IO::BINARY) if IO::BINARY.nonzero? assert(t.binmode?) + t.open + assert(t.binmode?, 'binmode after reopen') else assert_equal(0600, t.stat.mode & 0777) end -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/