mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* lib/tempfile.rb (Tempfile#open): re-open with same mode and
options as initialize. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@27086 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
d894e1d930
commit
d0cb5c71ce
3 changed files with 12 additions and 1 deletions
|
@ -1,3 +1,8 @@
|
|||
Mon Mar 29 15:10:39 2010 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||
|
||||
* lib/tempfile.rb (Tempfile#open): re-open with same mode and
|
||||
options as initialize.
|
||||
|
||||
Mon Mar 29 09:16:45 2010 NARUSE, Yui <naruse@ruby-lang.org>
|
||||
|
||||
* random.c: change include order; ruby.h should be at first.
|
||||
|
|
|
@ -138,6 +138,7 @@ class Tempfile < DelegateClass(File)
|
|||
if opts
|
||||
mode |= opts.delete(:mode) || 0
|
||||
opts[:perm] = perm
|
||||
perm = nil
|
||||
else
|
||||
opts = perm
|
||||
end
|
||||
|
@ -148,6 +149,9 @@ class Tempfile < DelegateClass(File)
|
|||
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 @@ class Tempfile < DelegateClass(File)
|
|||
# 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
|
||||
|
|
|
@ -294,6 +294,8 @@ puts Tempfile.new('foo').path
|
|||
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
|
||||
|
|
Loading…
Reference in a new issue