[前][次][番号順一覧][スレッド一覧]

ruby-changes:28343

From: akr <ko1@a...>
Date: Sun, 21 Apr 2013 00:10:39 +0900 (JST)
Subject: [ruby-changes:28343] akr:r40395 (trunk): * lib/webrick/httpauth/htpasswd.rb: Use Tempfile.create to avoid

akr	2013-04-21 00:10:29 +0900 (Sun, 21 Apr 2013)

  New Revision: 40395

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=40395

  Log:
    * lib/webrick/httpauth/htpasswd.rb: Use Tempfile.create to avoid
      unintentional unlink() by the finalizer.
      lib/webrick/httpauth/htdigest.rb: Ditto.

  Modified files:
    trunk/ChangeLog
    trunk/lib/webrick/httpauth/htdigest.rb
    trunk/lib/webrick/httpauth/htpasswd.rb

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 40394)
+++ ChangeLog	(revision 40395)
@@ -1,3 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Sat Apr 20 23:38:14 2013  Tanaka Akira  <akr@f...>
+
+	* 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@f...>
 
 	* lib/tempfile.rb (Tempfile.create): New method.
Index: lib/webrick/httpauth/htpasswd.rb
===================================================================
--- lib/webrick/httpauth/htpasswd.rb	(revision 40394)
+++ lib/webrick/httpauth/htpasswd.rb	(revision 40395)
@@ -75,13 +75,16 @@ module WEBrick https://github.com/ruby/ruby/blob/trunk/lib/webrick/httpauth/htpasswd.rb#L75
 
       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
 
Index: lib/webrick/httpauth/htdigest.rb
===================================================================
--- lib/webrick/httpauth/htdigest.rb	(revision 40394)
+++ lib/webrick/httpauth/htdigest.rb	(revision 40395)
@@ -70,13 +70,16 @@ module WEBrick https://github.com/ruby/ruby/blob/trunk/lib/webrick/httpauth/htdigest.rb#L70
 
       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
 

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]