aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authornormal <normal@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-11-21 23:05:41 +0000
committernormal <normal@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-11-21 23:05:41 +0000
commit24a7251eb04fc7b90e325c082a521f5b86020c3f (patch)
tree015ae2e6909fd287ac1b3b18e0675196e181fb0d /lib
parentd2abd1f5031e4322795672bd6374b0aeb167e576 (diff)
downloadruby-24a7251eb04fc7b90e325c082a521f5b86020c3f.tar.gz
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 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56865 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib')
-rw-r--r--lib/cgi/session.rb2
-rw-r--r--lib/net/http.rb8
-rw-r--r--lib/net/imap.rb4
-rw-r--r--lib/net/pop.rb4
-rw-r--r--lib/net/smtp.rb4
-rw-r--r--lib/open3.rb4
-rw-r--r--lib/pstore.rb2
-rw-r--r--lib/shell/process-controller.rb2
-rw-r--r--lib/tempfile.rb6
-rw-r--r--lib/webrick/httpauth/htdigest.rb2
-rw-r--r--lib/webrick/httpauth/htpasswd.rb2
-rw-r--r--lib/webrick/server.rb10
12 files changed, 23 insertions, 27 deletions
diff --git a/lib/cgi/session.rb b/lib/cgi/session.rb
index d44a5f84b0..b504f25f15 100644
--- a/lib/cgi/session.rb
+++ b/lib/cgi/session.rb
@@ -426,7 +426,7 @@ class CGI
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
diff --git a/lib/net/http.rb b/lib/net/http.rb
index 71d3d0aced..5a22fc0015 100644
--- a/lib/net/http.rb
+++ b/lib/net/http.rb
@@ -978,7 +978,7 @@ module Net #:nodoc:
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:
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:
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
diff --git a/lib/net/imap.rb b/lib/net/imap.rb
index 9895ed68ce..7a4d4da301 100644
--- a/lib/net/imap.rb
+++ b/lib/net/imap.rb
@@ -329,9 +329,7 @@ module Net
end
@receiver_thread.join
synchronize do
- unless @sock.closed?
- @sock.close
- end
+ @sock.close
end
raise e if e
end
diff --git a/lib/net/pop.rb b/lib/net/pop.rb
index 4a2dca2311..95d07652b6 100644
--- a/lib/net/pop.rb
+++ b/lib/net/pop.rb
@@ -570,7 +570,7 @@ module Net
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
ensure
@started = false
@command = nil
- @socket.close if @socket and not @socket.closed?
+ @socket.close if @socket
@socket = nil
end
private :do_finish
diff --git a/lib/net/smtp.rb b/lib/net/smtp.rb
index 359a0f9710..1302f3aa1d 100644
--- a/lib/net/smtp.rb
+++ b/lib/net/smtp.rb
@@ -567,7 +567,7 @@ module Net
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
ensure
@started = false
@error_occurred = false
- @socket.close if @socket and not @socket.closed?
+ @socket.close if @socket
@socket = nil
end
diff --git a/lib/open3.rb b/lib/open3.rb
index 3c9d450737..ddfad66436 100644
--- a/lib/open3.rb
+++ b/lib/open3.rb
@@ -204,7 +204,7 @@ module Open3
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
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
diff --git a/lib/pstore.rb b/lib/pstore.rb
index 3e2f594b6f..f787bb0ae0 100644
--- a/lib/pstore.rb
+++ b/lib/pstore.rb
@@ -335,7 +335,7 @@ class PStore
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.
diff --git a/lib/shell/process-controller.rb b/lib/shell/process-controller.rb
index a536ebd6ee..7e5bb505c9 100644
--- a/lib/shell/process-controller.rb
+++ b/lib/shell/process-controller.rb
@@ -260,7 +260,7 @@ class Shell
ObjectSpace.each_object(IO) do |io|
if ![STDIN, STDOUT, STDERR].include?(io)
- io.close unless io.closed?
+ io.close
end
end
diff --git a/lib/tempfile.rb b/lib/tempfile.rb
index b0ebd0be0e..36b0e1a481 100644
--- a/lib/tempfile.rb
+++ b/lib/tempfile.rb
@@ -147,7 +147,7 @@ class Tempfile < DelegateClass(File)
end
def _close # :nodoc:
- @tmpfile.close unless @tmpfile.closed?
+ @tmpfile.close
end
protected :_close
@@ -252,7 +252,7 @@ class Tempfile < DelegateClass(File)
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=nil, mode: 0, **options)
begin
yield tmpfile
ensure
- tmpfile.close if !tmpfile.closed?
+ tmpfile.close
File.unlink tmpfile
end
else
diff --git a/lib/webrick/httpauth/htdigest.rb b/lib/webrick/httpauth/htdigest.rb
index 1ef4fdb4aa..1b42c02dfa 100644
--- a/lib/webrick/httpauth/htdigest.rb
+++ b/lib/webrick/httpauth/htdigest.rb
@@ -79,7 +79,7 @@ module WEBrick
File::rename(tmp.path, output)
renamed = true
ensure
- tmp.close if !tmp.closed?
+ tmp.close
File.unlink(tmp.path) if !renamed
end
end
diff --git a/lib/webrick/httpauth/htpasswd.rb b/lib/webrick/httpauth/htpasswd.rb
index f43fc2c548..8c7b09463b 100644
--- a/lib/webrick/httpauth/htpasswd.rb
+++ b/lib/webrick/httpauth/htpasswd.rb
@@ -84,7 +84,7 @@ module WEBrick
File::rename(tmp.path, output)
renamed = true
ensure
- tmp.close if !tmp.closed?
+ tmp.close
File.unlink(tmp.path) if !renamed
end
end
diff --git a/lib/webrick/server.rb b/lib/webrick/server.rb
index 45bd9706d3..0a8e722b44 100644
--- a/lib/webrick/server.rb
+++ b/lib/webrick/server.rb
@@ -309,7 +309,7 @@ module WEBrick
else
@logger.debug "close: <address unknown>"
end
- sock.close unless sock.closed?
+ sock.close
end
}
end
@@ -334,11 +334,9 @@ module WEBrick
@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