ruby-changes:52155
From: normal <ko1@a...>
Date: Wed, 15 Aug 2018 08:00:07 +0900 (JST)
Subject: [ruby-changes:52155] normal:r64363 (trunk): webrick/httpauth/htgroup.rb (flush): avoid unnecessary unlink
normal 2018-08-15 08:00:02 +0900 (Wed, 15 Aug 2018) New Revision: 64363 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=64363 Log: 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 <akr@f...> Modified files: trunk/lib/webrick/httpauth/htgroup.rb Index: lib/webrick/httpauth/htgroup.rb =================================================================== --- lib/webrick/httpauth/htgroup.rb (revision 64362) +++ lib/webrick/httpauth/htgroup.rb (revision 64363) @@ -63,15 +63,18 @@ module WEBrick https://github.com/ruby/ruby/blob/trunk/lib/webrick/httpauth/htgroup.rb#L63 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 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/