summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-04-20 15:10:29 +0000
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-04-20 15:10:29 +0000
commit5fb8bb16e6ee98b1e5c7c657c0d0fe8b16e6dada (patch)
treee5e988c4e13d926827855676cc8f4b1b226ed3f8 /lib
parent5388fb64d991db9c094d1972176c4f5794e3555f (diff)
* lib/webrick/httpauth/htpasswd.rb: Use Tempfile.create to avoid
unintentional unlink() by the finalizer. lib/webrick/httpauth/htdigest.rb: Ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40395 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib')
-rw-r--r--lib/webrick/httpauth/htdigest.rb9
-rw-r--r--lib/webrick/httpauth/htpasswd.rb9
2 files changed, 12 insertions, 6 deletions
diff --git a/lib/webrick/httpauth/htdigest.rb b/lib/webrick/httpauth/htdigest.rb
index 4b74588c77..5fb0635e2a 100644
--- a/lib/webrick/httpauth/htdigest.rb
+++ b/lib/webrick/httpauth/htdigest.rb
@@ -70,13 +70,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
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