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

ruby-changes:44792

From: normal <ko1@a...>
Date: Tue, 22 Nov 2016 08:05:59 +0900 (JST)
Subject: [ruby-changes:44792] normal:r56865 (trunk): lib/*: remove closed checks

normal	2016-11-22 08:05:41 +0900 (Tue, 22 Nov 2016)

  New Revision: 56865

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=56865

  Log:
    lib/*: remove closed checks
    
    Follow r56795.  Since Ruby 2.2, calling #close on a closed
    socket no longer raises exceptions.
    
    * lib/cgi/session.rb (update): remove closed? check
    * lib/net/http.rb (finish, transport_request): ditto
    * lib/net/imap.rb (disconnect): ditto
    * lib/net/pop.rb (do_start, do_finish): ditto
    * lib/net/smtp.rb (do_start, do_finish): ditto
    * lib/open3.rb (popen_run, pipeline_run): ditto
    * lib/pstore.rb (transaction): ditto
    * lib/shell/process-controller.rb (sfork):
    * lib/tempfile (_close, call, Tempfile.create): ditto
    * lib/webrick/httpauth/htdigest.rb (flush): ditto
    * lib/webrick/httpauth/htpasswd.rb (flush): ditto
    * lib/webrick/server.rb (start_thread, cleanup_shutdown_pipe): ditto

  Modified files:
    trunk/lib/cgi/session.rb
    trunk/lib/net/http.rb
    trunk/lib/net/imap.rb
    trunk/lib/net/pop.rb
    trunk/lib/net/smtp.rb
    trunk/lib/open3.rb
    trunk/lib/pstore.rb
    trunk/lib/shell/process-controller.rb
    trunk/lib/tempfile.rb
    trunk/lib/webrick/httpauth/htdigest.rb
    trunk/lib/webrick/httpauth/htpasswd.rb
    trunk/lib/webrick/server.rb
Index: lib/webrick/server.rb
===================================================================
--- lib/webrick/server.rb	(revision 56864)
+++ lib/webrick/server.rb	(revision 56865)
@@ -309,7 +309,7 @@ module WEBrick https://github.com/ruby/ruby/blob/trunk/lib/webrick/server.rb#L309
           else
             @logger.debug "close: <address unknown>"
           end
-          sock.close unless sock.closed?
+          sock.close
         end
       }
     end
@@ -334,11 +334,9 @@ module WEBrick https://github.com/ruby/ruby/blob/trunk/lib/webrick/server.rb#L334
       @shutdown_pipe = nil
       return if !shutdown_pipe
       shutdown_pipe.each {|io|
-        if !io.closed?
-          begin
-            io.close
-          rescue IOError # another thread closed io.
-          end
+        begin
+          io.close
+        rescue IOError # another thread closed io.
         end
       }
     end
Index: lib/webrick/httpauth/htdigest.rb
===================================================================
--- lib/webrick/httpauth/htdigest.rb	(revision 56864)
+++ lib/webrick/httpauth/htdigest.rb	(revision 56865)
@@ -79,7 +79,7 @@ module WEBrick https://github.com/ruby/ruby/blob/trunk/lib/webrick/httpauth/htdigest.rb#L79
           File::rename(tmp.path, output)
           renamed = true
         ensure
-          tmp.close if !tmp.closed?
+          tmp.close
           File.unlink(tmp.path) if !renamed
         end
       end
Index: lib/webrick/httpauth/htpasswd.rb
===================================================================
--- lib/webrick/httpauth/htpasswd.rb	(revision 56864)
+++ lib/webrick/httpauth/htpasswd.rb	(revision 56865)
@@ -84,7 +84,7 @@ module WEBrick https://github.com/ruby/ruby/blob/trunk/lib/webrick/httpauth/htpasswd.rb#L84
           File::rename(tmp.path, output)
           renamed = true
         ensure
-          tmp.close if !tmp.closed?
+          tmp.close
           File.unlink(tmp.path) if !renamed
         end
       end
Index: lib/tempfile.rb
===================================================================
--- lib/tempfile.rb	(revision 56864)
+++ lib/tempfile.rb	(revision 56865)
@@ -147,7 +147,7 @@ class Tempfile < DelegateClass(File) https://github.com/ruby/ruby/blob/trunk/lib/tempfile.rb#L147
   end
 
   def _close    # :nodoc:
-    @tmpfile.close unless @tmpfile.closed?
+    @tmpfile.close
   end
   protected :_close
 
@@ -252,7 +252,7 @@ class Tempfile < DelegateClass(File) https://github.com/ruby/ruby/blob/trunk/lib/tempfile.rb#L252
 
       warn "removing #{@tmpfile.path}..." if $DEBUG
 
-      @tmpfile.close unless @tmpfile.closed?
+      @tmpfile.close
       begin
         File.unlink(@tmpfile.path)
       rescue Errno::ENOENT
@@ -334,7 +334,7 @@ def Tempfile.create(basename="", tmpdir= https://github.com/ruby/ruby/blob/trunk/lib/tempfile.rb#L334
     begin
       yield tmpfile
     ensure
-      tmpfile.close if !tmpfile.closed?
+      tmpfile.close
       File.unlink tmpfile
     end
   else
Index: lib/pstore.rb
===================================================================
--- lib/pstore.rb	(revision 56864)
+++ lib/pstore.rb	(revision 56865)
@@ -335,7 +335,7 @@ class PStore https://github.com/ruby/ruby/blob/trunk/lib/pstore.rb#L335
             save_data(checksum, original_data_size, file)
           end
         ensure
-          file.close if !file.closed?
+          file.close
         end
       else
         # This can only occur if read_only == true.
Index: lib/open3.rb
===================================================================
--- lib/open3.rb	(revision 56864)
+++ lib/open3.rb	(revision 56865)
@@ -204,7 +204,7 @@ module Open3 https://github.com/ruby/ruby/blob/trunk/lib/open3.rb#L204
       begin
         return yield(*result)
       ensure
-        parent_io.each{|io| io.close unless io.closed?}
+        parent_io.each{|io| io.close }
         wait_thr.join
       end
     end
@@ -655,7 +655,7 @@ module Open3 https://github.com/ruby/ruby/blob/trunk/lib/open3.rb#L655
       begin
         return yield(*result)
       ensure
-        parent_io.each{|io| io.close unless io.closed?}
+        parent_io.each{|io| io.close }
         wait_thrs.each {|t| t.join }
       end
     end
Index: lib/cgi/session.rb
===================================================================
--- lib/cgi/session.rb	(revision 56864)
+++ lib/cgi/session.rb	(revision 56865)
@@ -426,7 +426,7 @@ class CGI https://github.com/ruby/ruby/blob/trunk/lib/cgi/session.rb#L426
           f.close
           File.rename @path+".new", @path
         ensure
-          f.close if f and !f.closed?
+          f.close if f
           lockf.close if lockf
         end
       end
Index: lib/shell/process-controller.rb
===================================================================
--- lib/shell/process-controller.rb	(revision 56864)
+++ lib/shell/process-controller.rb	(revision 56865)
@@ -260,7 +260,7 @@ class Shell https://github.com/ruby/ruby/blob/trunk/lib/shell/process-controller.rb#L260
 
             ObjectSpace.each_object(IO) do |io|
               if ![STDIN, STDOUT, STDERR].include?(io)
-                io.close unless io.closed?
+                io.close
               end
             end
 
Index: lib/net/smtp.rb
===================================================================
--- lib/net/smtp.rb	(revision 56864)
+++ lib/net/smtp.rb	(revision 56865)
@@ -567,7 +567,7 @@ module Net https://github.com/ruby/ruby/blob/trunk/lib/net/smtp.rb#L567
     ensure
       unless @started
         # authentication failed, cancel connection.
-        s.close if s and not s.closed?
+        s.close if s
         @socket = nil
       end
     end
@@ -613,7 +613,7 @@ module Net https://github.com/ruby/ruby/blob/trunk/lib/net/smtp.rb#L613
     ensure
       @started = false
       @error_occurred = false
-      @socket.close if @socket and not @socket.closed?
+      @socket.close if @socket
       @socket = nil
     end
 
Index: lib/net/imap.rb
===================================================================
--- lib/net/imap.rb	(revision 56864)
+++ lib/net/imap.rb	(revision 56865)
@@ -329,9 +329,7 @@ module Net https://github.com/ruby/ruby/blob/trunk/lib/net/imap.rb#L329
       end
       @receiver_thread.join
       synchronize do
-        unless @sock.closed?
-          @sock.close
-        end
+        @sock.close
       end
       raise e if e
     end
Index: lib/net/pop.rb
===================================================================
--- lib/net/pop.rb	(revision 56864)
+++ lib/net/pop.rb	(revision 56865)
@@ -570,7 +570,7 @@ module Net https://github.com/ruby/ruby/blob/trunk/lib/net/pop.rb#L570
     ensure
       # Authentication failed, clean up connection.
       unless @started
-        s.close if s and not s.closed?
+        s.close if s
         @socket = nil
         @command = nil
       end
@@ -601,7 +601,7 @@ module Net https://github.com/ruby/ruby/blob/trunk/lib/net/pop.rb#L601
     ensure
       @started = false
       @command = nil
-      @socket.close if @socket and not @socket.closed?
+      @socket.close if @socket
       @socket = nil
     end
     private :do_finish
Index: lib/net/http.rb
===================================================================
--- lib/net/http.rb	(revision 56864)
+++ lib/net/http.rb	(revision 56865)
@@ -978,7 +978,7 @@ module Net   #:nodoc: https://github.com/ruby/ruby/blob/trunk/lib/net/http.rb#L978
 
     def do_finish
       @started = false
-      @socket.close if @socket and not @socket.closed?
+      @socket.close if @socket
       @socket = nil
     end
     private :do_finish
@@ -1463,12 +1463,12 @@ module Net   #:nodoc: https://github.com/ruby/ruby/blob/trunk/lib/net/http.rb#L1463
              Timeout::Error => exception
         if count == 0 && IDEMPOTENT_METHODS_.include?(req.method)
           count += 1
-          @socket.close if @socket and not @socket.closed?
+          @socket.close if @socket
           D "Conn close because of error #{exception}, and retry"
           retry
         end
         D "Conn close because of error #{exception}"
-        @socket.close if @socket and not @socket.closed?
+        @socket.close if @socket
         raise
       end
 
@@ -1476,7 +1476,7 @@ module Net   #:nodoc: https://github.com/ruby/ruby/blob/trunk/lib/net/http.rb#L1476
       res
     rescue => exception
       D "Conn close because of error #{exception}"
-      @socket.close if @socket and not @socket.closed?
+      @socket.close if @socket
       raise exception
     end
 

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

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