Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/tempfile.rb
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ def call(object_id)
$stderr.puts "removing #{@path}..." if $DEBUG
begin
File.unlink(@path)
rescue Errno::ENOENT
rescue Errno::ENOENT, Errno::EACCES
end
$stderr.puts "done" if $DEBUG
end
Expand Down
16 changes: 16 additions & 0 deletions test/test_tempfile.rb
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,22 @@ def test_finalizer_does_not_unlink_if_already_unlinked
end
end unless /mswin|mingw/ =~ RUBY_PLATFORM

def test_finalizer_ignores_eacces_on_unlink
assert_in_out_err("-r#{LIB_TEMPFILE_RB_PATH}", <<~'RUBY') do |(filename,*), (error,*)|
File.singleton_class.prepend(Module.new do
def unlink(*)
raise Errno::EACCES
end
end)
file = Tempfile.new("foo")
puts file.path
RUBY
assert_file.exist?(filename)
File.unlink(filename)
assert_nil error
end
end

def test_close_does_not_make_path_nil
t = tempfile("foo")
t.close
Expand Down
Loading