diff --git a/CHANGELOG.md b/CHANGELOG.md index 454e74d..fec923b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,11 @@ particular, this may be useful for debugging problems with the upstream dependen bisect` in a local clone) or for continuous integration with upstream HEAD. +### 2.5.3 / 2021-05-31 + +Make `net-ftp` an optional dependency, since requiring it as a hard dependency in v2.5.2 caused warnings to be emitted by Ruby 2.7 and earlier. A warning message is emitted if FTP functionality is called and `net-ftp` isn't available; this should only happen in Ruby 3.1 and later. + + ### 2.5.2 / 2021-05-28 #### Dependencies diff --git a/Gemfile b/Gemfile index 27e5e85..99d6ed5 100644 --- a/Gemfile +++ b/Gemfile @@ -1,4 +1,6 @@ source 'https://rubygems.org' +gem "net-ftp" if Gem::Requirement.new("> 3.1.0.dev").satisfied_by?(Gem::Version.new(RUBY_VERSION)) + # Specify your gem's dependencies in mini_portile2.gemspec gemspec diff --git a/lib/mini_portile2/mini_portile.rb b/lib/mini_portile2/mini_portile.rb index c5a18cf..209af33 100644 --- a/lib/mini_portile2/mini_portile.rb +++ b/lib/mini_portile2/mini_portile.rb @@ -1,7 +1,6 @@ require 'rbconfig' require 'net/http' require 'net/https' -require 'net/ftp' require 'fileutils' require 'tempfile' require 'digest' @@ -545,6 +544,7 @@ def download_file_file(uri, full_path) end def download_file_ftp(uri, full_path) + require "net/ftp" filename = File.basename(uri.path) with_tempfile(filename, full_path) do |temp_file| total = 0 @@ -568,6 +568,8 @@ def download_file_ftp(uri, full_path) end output end + rescue LoadError + raise LoadError, "Ruby #{RUBY_VERSION} does not provide the net-ftp gem, please add it as a dependency if you need to use FTP" rescue Net::FTPError return false end diff --git a/mini_portile2.gemspec b/mini_portile2.gemspec index 7dcfa1b..610164b 100644 --- a/mini_portile2.gemspec +++ b/mini_portile2.gemspec @@ -33,8 +33,6 @@ Gem::Specification.new do |spec| spec.required_ruby_version = ">= 2.3.0" - spec.add_dependency "net-ftp", "~> 0.1" - spec.add_development_dependency "bundler", "~> 2.1" spec.add_development_dependency "minitar", "~> 0.7" spec.add_development_dependency "minitest", "~> 5.11" diff --git a/test/test_download.rb b/test/test_download.rb index 173789b..2a11946 100644 --- a/test/test_download.rb +++ b/test/test_download.rb @@ -18,10 +18,12 @@ def server_must_receive_connection(connections = 3, &block) end end - block.call - - thread.kill - server.close + begin + block.call + ensure + thread.kill + server.close + end request_count.must_be :>, 0 end