summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog5
-rwxr-xr-xlib/tempfile.rb12
-rw-r--r--test/test_tempfile.rb20
3 files changed, 31 insertions, 6 deletions
diff --git a/ChangeLog b/ChangeLog
index 52c80b0c39..bb4dc8dc1d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+Thu Nov 12 06:42:38 2009 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * lib/tempfile.rb (Tempfile#initialize): option hash may not be
+ given. [ruby-core:26681]
+
Thu Nov 12 01:29:15 2009 Yusuke Endoh <mame@tsg.ne.jp>
* enumerator.c (yielder_yield_push): Yielder#<< should return self.
diff --git a/lib/tempfile.rb b/lib/tempfile.rb
index 7024bd9bdb..b327acb62b 100755
--- a/lib/tempfile.rb
+++ b/lib/tempfile.rb
@@ -133,11 +133,17 @@ class Tempfile < DelegateClass(File)
create(basename, *rest) do |tmpname, n, opts|
lock = tmpname + '.lock'
- mode = opts.delete(:mode) || 0
- mode = File::RDWR|File::CREAT|File::EXCL|mode
+ mode = File::RDWR|File::CREAT|File::EXCL
+ perm = 0600
+ if opts
+ mode |= opts.delete(:mode) || 0
+ opts[:perm] = perm
+ else
+ opts = perm
+ end
self.class.mkdir(lock)
begin
- @data[1] = @tmpfile = File.open(tmpname, mode, 0600, *opts)
+ @data[1] = @tmpfile = File.open(tmpname, mode, opts)
@data[0] = @tmpname = tmpname
ensure
self.class.rmdir(lock)
diff --git a/test/test_tempfile.rb b/test/test_tempfile.rb
index 9a90d605ee..073a11e15a 100644
--- a/test/test_tempfile.rb
+++ b/test/test_tempfile.rb
@@ -3,6 +3,11 @@ require 'tempfile'
require_relative 'ruby/envutil'
class TestTempfile < Test::Unit::TestCase
+ def initialize(*)
+ super
+ @tempfile = nil
+ end
+
def tempfile(*args, &block)
t = Tempfile.new(*args, &block)
@tempfile = (t unless block)
@@ -45,13 +50,13 @@ class TestTempfile < Test::Unit::TestCase
def test_basename
t = tempfile("foo")
- assert_match /^foo/, File.basename(t.path)
+ assert_match(/^foo/, File.basename(t.path))
end
def test_basename_with_suffix
t = tempfile(["foo", ".txt"])
- assert_match /^foo/, File.basename(t.path)
- assert_match /\.txt$/, File.basename(t.path)
+ assert_match(/^foo/, File.basename(t.path))
+ assert_match(/\.txt$/, File.basename(t.path))
end
def test_unlink
@@ -284,5 +289,14 @@ puts Tempfile.new('foo').path
t.rewind
assert_equal(Encoding::ASCII_8BIT,t.read.encoding)
end
+
+ def test_binmode
+ t = tempfile("TEST", mode: IO::BINARY)
+ if IO::BINARY.nonzero?
+ assert(t.binmode?)
+ else
+ assert_equal(0600, t.stat.mode & 0777)
+ end
+ end
end