зеркало из https://github.com/github/ruby.git
tempfile.rb: undefine finalizer on unlink
* lib/tempfile.rb (Tempfile#unlink): finalizer is no longer needed after unlinking. patched by by normalperson (Eric Wong) at [ruby-core:56521] [Bug #8768] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43110 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
Родитель
57c7de44fc
Коммит
ec2db8decf
|
@ -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.
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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")
|
||||
|
|
Загрузка…
Ссылка в новой задаче