aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog6
-rw-r--r--lib/tempfile.rb2
-rw-r--r--test/test_tempfile.rb14
3 files changed, 21 insertions, 1 deletions
diff --git a/ChangeLog b/ChangeLog
index 562c1f09c1..4bd1be90d2 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+Tue Oct 1 22:03:48 2013 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * lib/tempfile.rb (Tempfile#unlink): finalizer is no longer needed
+ after unlinking. patched by by normalperson (Eric Wong) at
+ [ruby-core:56521] [Bug #8768]
+
Tue Oct 1 20:54:33 2013 Nobuyoshi Nakada <nobu@ruby-lang.org>
* file.c (stat_new_0): constify.
diff --git a/lib/tempfile.rb b/lib/tempfile.rb
index e7df7d670e..92a73f82ea 100644
--- a/lib/tempfile.rb
+++ b/lib/tempfile.rb
@@ -190,7 +190,6 @@ class Tempfile < DelegateClass(File)
def close!
_close
unlink
- ObjectSpace.undefine_finalizer(self)
end
# Unlinks (deletes) the file from the filesystem. One should always unlink
@@ -238,6 +237,7 @@ class Tempfile < DelegateClass(File)
# remove tmpname from remover
@data[0] = @data[1] = nil
@tmpname = nil
+ ObjectSpace.undefine_finalizer(self)
end
alias delete unlink
diff --git a/test/test_tempfile.rb b/test/test_tempfile.rb
index 4f7e26f606..b3282538e4 100644
--- a/test/test_tempfile.rb
+++ b/test/test_tempfile.rb
@@ -206,6 +206,20 @@ puts Tempfile.new('foo').path
end
end
+ def test_tempfile_finalizer_does_not_run_if_unlinked
+ bug8768 = '[ruby-core:56521] [Bug #8768]'
+ args = %w(--disable-gems -rtempfile)
+ assert_in_out_err(args, <<-'EOS') do |(filename), (error)|
+ tmp = Tempfile.new('foo')
+ puts tmp.path
+ tmp.unlink
+ $DEBUG = true
+ EOS
+ assert_file.not_exist?(filename)
+ assert_nil(error, "#{bug8768} we used to get a confusing 'removing ...done' here")
+ end
+ end
+
def test_size_flushes_buffer_before_determining_file_size
t = tempfile("foo")
t.write("hello")