about summary refs log tree commit homepage
diff options
context:
space:
mode:
-rw-r--r--lib/unicorn/util.rb2
-rw-r--r--test/unit/test_util.rb40
2 files changed, 23 insertions, 19 deletions
diff --git a/lib/unicorn/util.rb b/lib/unicorn/util.rb
index 5ceda5c..458b6d7 100644
--- a/lib/unicorn/util.rb
+++ b/lib/unicorn/util.rb
@@ -57,7 +57,7 @@ module Unicorn
             open_arg << ":#{enc.to_s}"
             enc = fp.internal_encoding and open_arg << ":#{enc.to_s}"
           end
-          fp.reopen(fp.path, open_arg)
+          File.open(fp.path, 'ab') { |tmpfp| fp.reopen(tmpfp) }
           fp.sync = true
           new_st = fp.stat
           if orig_st.uid != new_st.uid || orig_st.gid != new_st.gid
diff --git a/test/unit/test_util.rb b/test/unit/test_util.rb
index b267179..377f6b8 100644
--- a/test/unit/test_util.rb
+++ b/test/unit/test_util.rb
@@ -8,26 +8,29 @@ class TestUtil < Test::Unit::TestCase
   EXPECT_FLAGS = File::WRONLY | File::APPEND
   def test_reopen_logs_noop
     tmp = Tempfile.new('')
-    tmp.reopen(tmp.path, 'a')
-    tmp.sync = true
-    ext = tmp.external_encoding rescue nil
-    int = tmp.internal_encoding rescue nil
-    before = tmp.stat.inspect
+    fp = File.open(tmp.path, 'ab')
+    fp.sync = true
+    ext = fp.external_encoding rescue nil
+    int = fp.internal_encoding rescue nil
+    before = fp.stat.inspect
     Unicorn::Util.reopen_logs
-    assert_equal before, File.stat(tmp.path).inspect
-    assert_equal ext, (tmp.external_encoding rescue nil)
-    assert_equal int, (tmp.internal_encoding rescue nil)
+    assert_equal before, File.stat(fp.path).inspect
+    assert_equal ext, (fp.external_encoding rescue nil)
+    assert_equal int, (fp.internal_encoding rescue nil)
+    assert_equal(EXPECT_FLAGS, EXPECT_FLAGS & fp.fcntl(Fcntl::F_GETFL))
     assert_nothing_raised { tmp.close! }
+    assert_nothing_raised { fp.close }
   end
 
   def test_reopen_logs_renamed
     tmp = Tempfile.new('')
     tmp_path = tmp.path.freeze
-    tmp.reopen(tmp_path, 'a')
-    tmp.sync = true
-    ext = tmp.external_encoding rescue nil
-    int = tmp.internal_encoding rescue nil
-    before = tmp.stat.inspect
+    fp = File.open(tmp_path, 'ab')
+    fp.sync = true
+
+    ext = fp.external_encoding rescue nil
+    int = fp.internal_encoding rescue nil
+    before = fp.stat.inspect
     to = Tempfile.new('')
     File.rename(tmp_path, to.path)
     assert ! File.exist?(tmp_path)
@@ -35,13 +38,14 @@ class TestUtil < Test::Unit::TestCase
     assert_equal tmp_path, tmp.path
     assert File.exist?(tmp_path)
     assert before != File.stat(tmp_path).inspect
-    assert_equal tmp.stat.inspect, File.stat(tmp_path).inspect
-    assert_equal ext, (tmp.external_encoding rescue nil)
-    assert_equal int, (tmp.internal_encoding rescue nil)
-    assert_equal(EXPECT_FLAGS, EXPECT_FLAGS & tmp.fcntl(Fcntl::F_GETFL))
-    assert tmp.sync
+    assert_equal fp.stat.inspect, File.stat(tmp_path).inspect
+    assert_equal ext, (fp.external_encoding rescue nil)
+    assert_equal int, (fp.internal_encoding rescue nil)
+    assert_equal(EXPECT_FLAGS, EXPECT_FLAGS & fp.fcntl(Fcntl::F_GETFL))
+    assert fp.sync
     assert_nothing_raised { tmp.close! }
     assert_nothing_raised { to.close! }
+    assert_nothing_raised { fp.close }
   end
 
   def test_reopen_logs_renamed_with_encoding