aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog6
-rw-r--r--lib/webrick/httpauth/htdigest.rb9
-rw-r--r--lib/webrick/httpauth/htpasswd.rb9
3 files changed, 18 insertions, 6 deletions
diff --git a/ChangeLog b/ChangeLog
index eb8317f919..95a5a236c9 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+Sat Apr 20 23:38:14 2013 Tanaka Akira <akr@fsij.org>
+
+ * lib/webrick/httpauth/htpasswd.rb: Use Tempfile.create to avoid
+ unintentional unlink() by the finalizer.
+ lib/webrick/httpauth/htdigest.rb: Ditto.
+
Sat Apr 20 22:47:48 2013 Tanaka Akira <akr@fsij.org>
* lib/tempfile.rb (Tempfile.create): New method.
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