From ab7e34e4db6a1fd7cc83367b2646405a109fa7d8 Mon Sep 17 00:00:00 2001 From: normal Date: Tue, 14 Aug 2018 23:00:02 +0000 Subject: webrick/httpauth/htgroup.rb (flush): avoid unnecessary unlink Based on patch by akr [ruby-core:88477], use Tempfile.create to avoid unnecessary unlink call. Unlike akr's original patch, this does not change the return value of flush. Thanks-to: Tanaka Akira git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64363 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- lib/webrick/httpauth/htgroup.rb | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'lib') diff --git a/lib/webrick/httpauth/htgroup.rb b/lib/webrick/httpauth/htgroup.rb index 399a62c37f..e06c441b18 100644 --- a/lib/webrick/httpauth/htgroup.rb +++ b/lib/webrick/httpauth/htgroup.rb @@ -63,15 +63,18 @@ module WEBrick def flush(output=nil) output ||= @path - tmp = Tempfile.new("htgroup", File::dirname(output)) + tmp = Tempfile.create("htgroup", File::dirname(output)) begin @group.keys.sort.each{|group| tmp.puts(format("%s: %s", group, self.members(group).join(" "))) } + ensure tmp.close - File::rename(tmp.path, output) - rescue - tmp.close(true) + if $! + File.unlink(tmp.path) + else + return File.rename(tmp.path, output) + end end end -- cgit v1.2.3