[ruby/tempfile] Don't unlink in finalizer when already unlinked
https://github.com/ruby/tempfile/commit/f677941ea2
This commit is contained in:
parent
bd7eda6038
commit
1d68a735a2
@ -330,6 +330,8 @@ class Tempfile < DelegateClass(File)
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@finalizer_manager.unlinked = true
|
||||||
|
|
||||||
@unlinked = true
|
@unlinked = true
|
||||||
end
|
end
|
||||||
alias delete unlink
|
alias delete unlink
|
||||||
@ -366,10 +368,13 @@ class Tempfile < DelegateClass(File)
|
|||||||
attr_reader :unlinked, :mode, :opts, :finalizer_manager
|
attr_reader :unlinked, :mode, :opts, :finalizer_manager
|
||||||
|
|
||||||
class FinalizerManager # :nodoc:
|
class FinalizerManager # :nodoc:
|
||||||
|
attr_accessor :unlinked
|
||||||
|
|
||||||
def initialize(path)
|
def initialize(path)
|
||||||
@open_files = {}
|
@open_files = {}
|
||||||
@path = path
|
@path = path
|
||||||
@pid = Process.pid
|
@pid = Process.pid
|
||||||
|
@unlinked = false
|
||||||
end
|
end
|
||||||
|
|
||||||
def register(obj, file)
|
def register(obj, file)
|
||||||
@ -381,7 +386,7 @@ class Tempfile < DelegateClass(File)
|
|||||||
def call(object_id)
|
def call(object_id)
|
||||||
@open_files.delete(object_id).close
|
@open_files.delete(object_id).close
|
||||||
|
|
||||||
if @open_files.empty? && Process.pid == @pid
|
if @open_files.empty? && !@unlinked && Process.pid == @pid
|
||||||
$stderr.puts "removing #{@path}..." if $DEBUG
|
$stderr.puts "removing #{@path}..." if $DEBUG
|
||||||
begin
|
begin
|
||||||
File.unlink(@path)
|
File.unlink(@path)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user