diff options
Diffstat (limited to 'lib/webrick/httpauth/htpasswd.rb')
-rw-r--r-- | lib/webrick/httpauth/htpasswd.rb | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/lib/webrick/httpauth/htpasswd.rb b/lib/webrick/httpauth/htpasswd.rb index 205a6db2f0..69b739fbfe 100644 --- a/lib/webrick/httpauth/htpasswd.rb +++ b/lib/webrick/httpauth/htpasswd.rb @@ -75,13 +75,16 @@ module WEBrick def flush(output=nil) output ||= @path - tmp = Tempfile.new("htpasswd", File::dirname(output)) + tmp = Tempfile.create("htpasswd", File::dirname(output)) + renamed = false begin each{|item| tmp.puts(item.join(":")) } tmp.close File::rename(tmp.path, output) - rescue - tmp.close(true) + renamed = true + ensure + tmp.close if !tmp.closed? + File.unlink(tmp.path) if !renamed end end |