diff options
author | normal <normal@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2018-08-14 23:00:02 +0000 |
---|---|---|
committer | normal <normal@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2018-08-14 23:00:02 +0000 |
commit | ab7e34e4db6a1fd7cc83367b2646405a109fa7d8 (patch) | |
tree | 2848d169b68bc4f42fe38bae322b45c5ba471043 /lib | |
parent | 7d664ecc49c47b1880e0966ee032f07e89467ea1 (diff) |
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@fsij.org>
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64363 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib')
-rw-r--r-- | lib/webrick/httpauth/htgroup.rb | 11 |
1 files changed, 7 insertions, 4 deletions
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 |